Skip to content
Open
7 changes: 4 additions & 3 deletions core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions plugins/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def api_get(kind, query):


@hook.command('image')
@hook.command('img')
@hook.command('gis')
@hook.command
def googleimage(inp):
Expand Down
34 changes: 21 additions & 13 deletions plugins/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from util import hook, timesince
import time
import re
import string

db_ready = []

Expand Down Expand Up @@ -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:
Expand All @@ -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 <nick> <channel> -- Tell when a nickname was last in active in one of this bot's channels."""

if input.conn.nick.lower() == inp.lower():
"""seen <nick> [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)
2 changes: 2 additions & 0 deletions plugins/minecraft_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 0 additions & 3 deletions plugins/potato.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ def potato(inp, action=None):
"""potato <user> - Makes <user> 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'])
Expand Down
69 changes: 69 additions & 0 deletions plugins/reminder.py
Original file line number Diff line number Diff line change
@@ -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 <time> to <message> - Says <message> in <time>
(time has to be in format 1h2m3s or 1hour 2minutes 3seconds)"""
splitword = "to"
inp_split = inp.split(splitword, 1)

if inp != "" and len(inp_split) == 2:
waittime = parsetime(inp_split[0])
txt = inp_split[1].strip()
if not waittime:
return "Could not parse time, allowed values are: days, hours, minutes and seconds"
thread.start_new_thread(delayreply, (conn, chan, txt, waittime))
reply("I will remind you in {} to {}".format(formattime(waittime), txt))
else:
return "You need to specify 2 arguments"
15 changes: 15 additions & 0 deletions plugins/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
('maroon', '\x0305')
])

leetchars = {"a":"4", "b":"8", "e":"3", "g":"6", "i":"1",
"l":"1", "o":"0", "s":"5", "t":"7", "z":"2"}

# helper functions

strip_re = re.compile("(\x03|\x02|\x1f)(?:,?\d{1,2}(?:,\d{1,2})?)?", re.UNICODE)
Expand Down Expand Up @@ -156,6 +159,18 @@ def munge(inp):
return text.munge(inp)


# leet

@hook.command("1337")
@hook.command
def leet(inp):
"""leet <message> -- Writes message in leet"""
out = inp
for key, value in leetchars.items():
out = out.replace(key, value).replace(key.upper(), value)
return out


# colors - based on code by Reece Selwood - <https://github.com/hitzler/homero>


Expand Down
4 changes: 3 additions & 1 deletion plugins/valvesounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def get_sound_info(game, search):
items.append("{} - {} {}".format(item["who"],
text if len(text) < 325 else text[:325] + "...",
item["listen"]))
if len(items) == 1:
if len(items) < 1:
return "No results"
elif len(items) == 1:
return items[0]
else:
return "{} (and {} others: {})".format(items[0], len(items) - 1, web.haste("\n".join(items)))
Expand Down