From f50a79191ec5474da3896912cd2b174ec0372e6d Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 13:29:53 +0200 Subject: [PATCH 01/12] Remove color codes from messages --- core/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/main.py b/core/main.py index 0054b0ae..b7e4fff5 100644 --- a/core/main.py +++ b/core/main.py @@ -162,11 +162,12 @@ def main(conn, out): prefix = '^(?:[{}]?|'.format(command_prefix) else: prefix = '^(?:[{}]|'.format(command_prefix) - + + lastparam_nocolor = re.sub(ur'\x03\d\d|\x02|\x0F|\x16|\x1F', '', inp.lastparam) command_re = prefix + inp.conn.nick command_re += r'[,;:]+\s+)(\w+)(?:$|\s+)(.*)' - m = re.match(command_re, inp.lastparam) + m = re.match(command_re, lastparam_nocolor) if m: trigger = m.group(1).lower() @@ -187,7 +188,7 @@ def main(conn, out): # REGEXES for func, args in bot.plugs['regex']: - m = args['re'].search(inp.lastparam) + m = args['re'].search(lastparam_nocolor) if m: input = Input(conn, *out) input.inp = m From ea274da2d214cf0eb8465d28baa3a3138abff333 Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 13:44:45 +0200 Subject: [PATCH 02/12] Added img alias for googleimage --- plugins/google.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/google.py b/plugins/google.py index fe9e288a..a542a9ec 100644 --- a/plugins/google.py +++ b/plugins/google.py @@ -11,6 +11,7 @@ def api_get(kind, query): @hook.command('image') +@hook.command('img') @hook.command('gis') @hook.command def googleimage(inp): From 8dbe9c1b60c909dfbb661e52acfe8b4f3afb59c2 Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 13:46:34 +0200 Subject: [PATCH 03/12] Require botcontrol permission for resethistory command --- plugins/history.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/history.py b/plugins/history.py index c703bcf7..98b8f121 100644 --- a/plugins/history.py +++ b/plugins/history.py @@ -46,7 +46,7 @@ def chat_tracker(paraml, input=None, db=None, conn=None): track_history(input, message_time, conn) -@hook.command(autohelp=False) +@hook.command(autohelp=False, permissions=["botcontrol"]) def resethistory(inp, input=None, conn=None): """resethistory - Resets chat history for the current channel""" try: From ed019f66e4b11f25c3c6e45e19ca01f6ab597709 Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 13:48:28 +0200 Subject: [PATCH 04/12] Fixed seen command description --- plugins/history.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/history.py b/plugins/history.py index 98b8f121..9deda9cc 100644 --- a/plugins/history.py +++ b/plugins/history.py @@ -60,7 +60,7 @@ def resethistory(inp, input=None, conn=None): @hook.command def seen(inp, nick='', chan='', db=None, input=None, conn=None): - """seen -- Tell when a nickname was last in active in one of this bot's channels.""" + """seen [channel] -- Tell when a nickname was last in active in one of this bot's channels.""" if input.conn.nick.lower() == inp.lower(): return "You need to get your eyes checked." From 24f3eb67f2d01e372181fe9ba976c5c4892ed82f Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 14:35:35 +0200 Subject: [PATCH 05/12] Fixed seen channel argument --- plugins/history.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/plugins/history.py b/plugins/history.py index 9deda9cc..5e2c3667 100644 --- a/plugins/history.py +++ b/plugins/history.py @@ -2,6 +2,7 @@ from util import hook, timesince import time import re +import string db_ready = [] @@ -61,29 +62,36 @@ def resethistory(inp, input=None, conn=None): @hook.command def seen(inp, nick='', chan='', db=None, input=None, conn=None): """seen [channel] -- Tell when a nickname was last in active in one of this bot's channels.""" - - if input.conn.nick.lower() == inp.lower(): + + args = inp.split() + lookup_nick = args[0] + if len(args) > 1: + lookup_chan = args[1] + else: + lookup_chan = chan + + if input.conn.nick.lower() == lookup_nick.lower(): return "You need to get your eyes checked." - if inp.lower() == nick.lower(): + if lookup_nick.lower() == nick.lower(): return "Have you looked in a mirror lately?" - if not re.match("^[A-Za-z0-9_|.\-\]\[]*$", inp.lower()): + if any(c not in (string.ascii_letters + string.digits + "_-\[]{}^`|") for c in lookup_nick): return "I can't look up that name, its impossible to use!" db_init(db, conn.name) - last_seen = db.execute("select name, time, quote from seen_user where name" - " like ? and chan = ?", (inp, chan)).fetchone() + last_seen = db.execute("SELECT name, time, quote FROM seen_user WHERE name" + " like ? and chan = ?", (lookup_nick, lookup_chan)).fetchone() if last_seen: reltime = timesince.timesince(last_seen[1]) - if last_seen[0] != inp.lower(): # for glob matching - inp = last_seen[0] + if last_seen[0] != lookup_nick.lower(): # for glob matching + lookup_nick = last_seen[0] if last_seen[2][0:1] == "\x01": - return '{} was last seen {} ago: * {} {}'.format(inp, reltime, inp, + return '{} was last seen {} ago: * {} {}'.format(lookup_nick, reltime, lookup_nick, last_seen[2][8:-1]) else: - return '{} was last seen {} ago saying: {}'.format(inp, reltime, last_seen[2]) + return '{} was last seen {} ago saying: {}'.format(lookup_nick, reltime, last_seen[2]) else: - return "I've never seen {} talking in this channel.".format(inp) + return "I've never seen {} talking in this channel.".format(lookup_nick) From 097c249d933b3e9946375b52feb05955443b03c8 Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 17:24:58 +0200 Subject: [PATCH 06/12] Added socket.error handler for mcping --- plugins/minecraft_ping.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/minecraft_ping.py b/plugins/minecraft_ping.py index 978ca19d..5eaf9e18 100644 --- a/plugins/minecraft_ping.py +++ b/plugins/minecraft_ping.py @@ -130,6 +130,8 @@ def mcping_legacy(host, port): raise PingError("Invalid hostname") except socket.timeout: raise PingError("Request timed out") + except socket.error: + raise PingError("Connection refused") if response[0] != '\xff': raise PingError("Invalid response") From 44f535b8356e56f8c7dc7c3baf3f8421e7603286 Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 17:51:12 +0200 Subject: [PATCH 07/12] Removed username check for the potato command --- plugins/potato.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/potato.py b/plugins/potato.py index 9987e180..9e5a2df1 100644 --- a/plugins/potato.py +++ b/plugins/potato.py @@ -43,9 +43,6 @@ def potato(inp, action=None): """potato - Makes a tasty little potato.""" inp = inp.strip() - if not re.match("^[A-Za-z0-9_|.-\]\[]*$", inp.lower()): - return "I cant make a tasty potato for that user!" - potato_type = random.choice(potatoes) size = random.choice(['small', 'little', 'mid-sized', 'medium-sized', 'large', 'gigantic']) flavor = random.choice(['tasty', 'delectable', 'delicious', 'yummy', 'toothsome', 'scrumptious', 'luscious']) From ba2b2e902556cb5425fdc7edaf1465926181b0ac Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 17:56:19 +0200 Subject: [PATCH 08/12] Set adminonly for resethistory and removed permission --- plugins/history.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/history.py b/plugins/history.py index 5e2c3667..35fedece 100644 --- a/plugins/history.py +++ b/plugins/history.py @@ -47,7 +47,7 @@ def chat_tracker(paraml, input=None, db=None, conn=None): track_history(input, message_time, conn) -@hook.command(autohelp=False, permissions=["botcontrol"]) +@hook.command(autohelp=False, adminonly=True) def resethistory(inp, input=None, conn=None): """resethistory - Resets chat history for the current channel""" try: From 257b0a94a79c0fbb6c2bb68e29d1dc51e01e23a7 Mon Sep 17 00:00:00 2001 From: Gabriel Huber Date: Tue, 10 Jun 2014 18:02:21 +0200 Subject: [PATCH 09/12] Added reminder command --- plugins/reminder.py | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 plugins/reminder.py diff --git a/plugins/reminder.py b/plugins/reminder.py new file mode 100644 index 00000000..74792ad5 --- /dev/null +++ b/plugins/reminder.py @@ -0,0 +1,69 @@ +from util import hook +from time import sleep +import thread +import re + +def parsetime(timestring): + timere = re.compile("(\d+)\s?(d|h|m|s)") + timeelem = timere.findall(timestring) + seconds = 0 + + for elem in timeelem: + if elem[1] == "d": + seconds += int(elem[0]) * 86400 + elif elem[1] == "h": + seconds += int(elem[0]) * 3600 + elif elem[1] == "m": + seconds += int(elem[0]) * 60 + elif elem[1] == "s": + seconds += int(elem[0]) + else: + return None + + return seconds + +def formattime(seconds): + hours = seconds//3600 + minutes = seconds%3600//60 + seconds = seconds%60 + timelist = [] + if hours == 1: + timelist.append("{} hour".format(hours)) + elif hours > 1: + timelist.append("{} hours".format(hours)) + if minutes == 1: + timelist.append("{} minute".format(minutes)) + elif minutes > 1: + timelist.append("{} minutes".format(minutes)) + if seconds == 1: + timelist.append("{} second".format(seconds)) + elif seconds > 1: + timelist.append("{} seconds".format(seconds)) + + return " ".join(timelist) + +def delayreply(conn, channel, msg, sleept): + sleep(sleept) + say(conn, channel, "It's time for: " + msg) + +def say(conn, channel, msg): + out = u"PRIVMSG {} :{}".format(channel, msg) + conn.send(out) + +@hook.command("remind") +@hook.command +def reminder(inp, reply=None, conn=None, chan=None): + """reminder