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 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): diff --git a/plugins/history.py b/plugins/history.py index c703bcf7..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 = [] @@ -46,7 +47,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: @@ -60,30 +61,37 @@ 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.""" - - if input.conn.nick.lower() == inp.lower(): + """seen [channel] -- Tell when a nickname was last in active in one of this bot's channels.""" + + 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) 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") 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']) 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