Commit 15ded96e authored by Andrew Lombardi's avatar Andrew Lombardi Committed by Sébastien Helleu

kbtimeout.py 0.2: improve support of hostmasks, add compatibility with Python...

kbtimeout.py 0.2: improve support of hostmasks, add compatibility with Python 3, switch license to GPL3
parent 6dacfdae
#
# Copyright (c) 2009 by kinabalu (andrew AT mysticcoders DOT com)
# Copyright (c) 2009 - 2018 by kinabalu (https://mysticcoders.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
......@@ -12,8 +12,7 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
......@@ -21,7 +20,9 @@
#
# History:
#
# 2009-05-03, kinabalu <andrew AT mysticcoders DOT com>
# 2018-07-22, kinabalu (https://mysticcoders.com)
# version 0.2, script cleanup and ensure py3 compatibility
# 2009-05-03, kinabalu
# version 0.1, initial version
#
# /kbtimeout and /kbt can be used in combination with these actions
......@@ -39,7 +40,7 @@
# For up-to-date information about this script, and new
# version downloads, please go to:
#
# http://www.mysticcoders.com/apps/kickban-timeout/
# https://www.mysticcoders.com/
#
# If you have any questions, please contact me on-line at:
#
......@@ -48,31 +49,55 @@
# - kinabalu
#
import os
import string
import os
import string
import weechat
try:
import weechat
except ImportError:
print('This script has to run under WeeChat (https://weechat.org/).')
sys.exit(1)
SCRIPT_NAME = 'kbtimeout'
SCRIPT_AUTHOR = 'kinabalu (https://mysticcoders.com)'
SCRIPT_VERSION = '0.2'
SCRIPT_LICENSE = 'GPL3'
def handler(data, buffer, argList):
if len(argList.split(" ")) < 2:
split_args = argList.split(" ")
if len(split_args) < 2:
weechat.prnt("", "Wrong number of parameters for kbtimeout")
return weechat.WEECHAT_RC_ERROR;
nick = argList.split(" ")[0]
timeout = argList.split(" ")[1]
nick = split_args[0]
timeout = split_args[1]
message = ""
if len(argList.split(" ")) > 2:
if len(split_args) > 2:
message = argList.split(" ", 2)[2]
nick_ptr = weechat.nicklist_search_nick(buffer, "", nick)
infolist = weechat.infolist_get("irc_nick", "", "{},{}".format("freenode", "##kbtimeout"))
buffer_name = weechat.buffer_get_string(buffer, "name");
if nick_ptr:
weechat.command(buffer, "/kickban " + nick + " " + message)
weechat.hook_timer(int(timeout) * 1000, 0, 1, "kickban_callback", buffer_name + ":" + nick)
found_ban_host = None
while weechat.infolist_next(infolist):
ban_nick = weechat.infolist_string(infolist, "name")
ban_host = weechat.infolist_string(infolist, "host")
ban_account = weechat.infolist_string(infolist, "account")
if ban_nick == nick:
found_ban_host = ban_host
weechat.infolist_free(infolist)
found_ban_host = found_ban_host[1:]
if found_ban_host:
weechat.command(buffer, "/kickban " + found_ban_host + " " + message)
weechat.hook_timer(int(timeout) * 1000, 0, 1, "kickban_callback", buffer_name + ":" + found_ban_host)
return weechat.WEECHAT_RC_OK
# END handler
......@@ -83,10 +108,10 @@ def kickban_callback(data, times_left):
if buffer_ptr:
weechat.command(buffer_ptr, "/unban " + details[1])
return weechat.WEECHAT_RC_OK
# END kickban_callback
# *** Script starts here ***
# END kickban_callback
weechat.register("kbtimeout", "kinabalu <andrew@mysticcoders.com>", "0.1", "GPL2", "kickban with timeout", "", "")
if __name__ == '__main__':
weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, "kickban with timeout", "", "")
weechat.hook_command("kbtimeout", "Kickban with ban timeout", "[nick] [timeout] [comment]", "kickban nick with comment", "%(irc_channel_nicks_hosts) %-", "handler", "")
weechat.hook_command(SCRIPT_NAME, "Kickban with ban timeout", "[nick] [timeout] [comment]", "kickban nick with comment", "%(irc_channel_nicks_hosts) %-", "handler", "")
weechat.hook_command("kbt", "Kickban with ban timeout", "[nick] [timeout] [comment]", "kickban nick with comment", "%(irc_channel_nicks_hosts) %-", "handler", "")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment