def handle(who, msg, where): res = re.match("^([0-9]+ |)(.*)$", msg) if not res: return num, term = res.groups() if num: num = int(num.strip()) else: num = 1 if num < 1: num = 1 val = cache.get(term, None) if val is None: val = define(term) cache[term]=val n = len(val) num -= 1 if num >= n: api.privmsg(where, "{} has {} definitions. [1-{}]".format(term, n,n)) return definition = val[num]["text"] api.privmsg(where, "<{{C3}}Definition{{}} {{B}}{}{{}} (of {}) for {{B}}{}{{}}> {}".format( num + 1, n, term, definition))
def math(sender, message, target): if not message.startswith("%"): return equ = message[1:].replace(" ","") try: value = evaluate(equ) if value is not None: api.privmsg(target, "{GREEN}" + str(round(value,15))) except Exception as e: api.privmsg(target, str(e)) raise
def search(who, what, where): reply_json = urllib.request.urlopen(_API_URL + urllib.parse.quote(what)).read() response = json.loads(reply_json.decode("utf-8")) data = response['responseData'] if "results" not in data or len(data['results']) == 0: api.privmsg(where, "No results :(") return result = data['results'][0] reply = "<{C3}Google Search{}: {B}%s{} | {LINK}%s{} >" % ( result['titleNoFormatting'], urllib.parse.unquote(result['url'])) api.privmsg(where, reply)
def handle(who, msg, where): parts = re.split(url_re, msg, 1) # Only grab the first url. lame i know. if len(parts) == 1: return url = parts[1] short = "" if len(url) >= 20: # Long enough for a shorten short = shorten(url) short = "{{LINK}}{}{{}} | ".format(shorten(url)) title = getTitle(url) out = "<{}{{blue}}Title{{}}: {{yellow}}{}{{}}>".format(short, title) api.privmsg(where, out)
def cron(): threading.Timer(1, cron).start() now = datetime.datetime.now() if len(cache) == 0: return changed = False while len(cache) > 0: if now >= cache[0][0]: changed= True when, where, what = cache.pop(0) api.privmsg(where, what) else: break if changed: store["next"] = cache
def handle(who, msg, where): parts = re.split(url_re, msg) if len(parts) == 1: return shortened = False for i in range(1,len(parts), 2): url = parts[i] if len(url) < 20: continue parts[i] = "{{LINK}}{}{{}}".format(shorten(url)) shortened = True if not shortened: return api.privmsg(where, "".join(parts))
def printDate(sender, args, replyTo): if '>' not in args: # print usage and leave. return api.privmsg(replyTo, "Bad usage") timeSpec, note = args.split(">",1) msg = "({}) {}: {}".format( datetime.datetime.now().strftime("%x %X"), sender, note) when = datetime.datetime(*parse(timeSpec)[0][:6]) schedule(when, replyTo, msg)
def onTell(who, args, where): print("Tell:") print(store["blocked"]) print(store["alarms"]) if args == "off": blocked.add(who) store["blocked"] = blocked api.privmsg(who, "!tell's are disabled for you. Use '!tell on' to turn them back on") return if args == "on": blocked.remove(who) store["blocked"] = blocked api.privmsg(who, "!tell's are enabled for you. Use '!tell off' to turn them off") return nick, msg = args.split(" ", 1) when = datetime.datetime.now().strftime("%H:%M:%S %m/%d/%y") if nick in store["blocked"]: api.privmsg(who, "{} has {{RED}}disabled {{}}!tells please use memoserv or a PM instead".format(nick)) return msg = when + " " + nick +": " + msg if nick not in messages: messages[nick] = [] messages[nick].append(msg) store["alarms"] = messages
def onTell(who, args, where): if args == "off": blocked.add(who) store["blocked"] = blocked api.privmsg(who, offMessage) return if args == "on": blocked.remove(who) store["blocked"] = blocked api.privmsg(who, onMessage) return nick, msg = args.split(" ", 1) if nick in store["blocked"]: api.privmsg(who, disabledMessage.format(nick)) return when = getTime() msg = when + " " + who +": " + msg if nick not in messages: messages[nick] = [] messages[nick].append(msg) store["alarms"] = messages
def handle(who, msg, where): parts = re.split(url_re, msg, 1) # Only grab the first url. lame i know. if len(parts) == 1: return url = parts[1] short = "" if len(url) >= 20: # Long enough for a shorten short = shorten(url) short = shortFmt.format(shorten(url)) title = getTitle(url) if title: title = titleFmt.format(title) if short or title: divider = "" if short and title: divider = delim out = outputFmt.format(short=short, delim=divider, title=title) api.privmsg(where, out)
def handle(who, msg, where): res = re.match("^([0-9]+ |)(.*)$", msg) if not res: return num, term = res.groups() if not term: return api.privmsg(where, usage) if num: num = int(num.strip()) else: num = 1 if num < 1: num = 1 val = cache.get(term, None) if val is None: val = define(term) cache[term]=val n = len(val) if n == 0: api.privmsg(where, noDefinitions.format(term=term)) return num -= 1 if num >= n: api.privmsg(where, invalidArg.format(term = term, tot = n)) return definition = val[num]["text"] api.privmsg(where, definitionFmt.format( num = num + 1, tot = n, term = term, definition = definition))
def heartify(src, msg, dst): if "<3" in msg: api.privmsg(dst, msg.replace("<3", u'{C5}♥{}'))
def say(where, what): api.privmsg(where, what)
def activity(who, what, where): if who in messages: for msg in messages[who]: api.privmsg(who, msg) del messages[who] store["alarms"] = messages
def onLine(sender, message, target): prevLine = lastLines.get(target, "") if prevLine == message: api.privmsg(target, message) message = "" lastLines[target] = message
def printDate(sender, args, replyTo): now = datetime.datetime.now() api.privmsg(replyTo, now.strftime("%H:%M:%S %A. %B(%m) %d %Y"))
def onLine(sender, message, target): if message == "\\o/": api.privmsg(target, "YAY") api.privmsg(target, "/ \\")
def printLoads(sender, args, chan): api.privmsg(chan, "I've been restarted %s times!" % loads)
def repeatLine(sender, msg, to): api.privmsg(to, msg)
def donateLine(sender, msg, to): api.privmsg(to, "[{C8}Bitcoin {C11}1DtTvCLiUMhs21QcETQzLyiqxoopUjqBSU{}][{C8}Wallet {C11}[email protected]{}][{C8}PayPal {C11}http://goo.gl/aSQWy0{}]")
def printLoads(sender, args, chan): api.privmsg(chan, "I've been restarted %s times!" % loads)
def heartify(src, msg, dst): if "<3" in msg: api.privmsg(dst, msg.replace("<3", u'{C5}♥{}'))
def handle(who, msg, where): parts = re.split(url_re, msg) for url in parts[1::2]: api.privmsg(where, "<{blue}Title{}: {yellow}" + getTitle(url) +"{} >")
def onName(sender, args, chan): api.privmsg(chan, str(getNames(chan)))
def doWeather(who, msg, where): res = getWeather(msg) api.privmsg(where, res)
def doWeather(who, msg, where): res = getWeather(msg) api.privmsg(where, res)
def onLine(sender, message, target): if message=="\\o/": api.privmsg(target, "YAY") api.privmsg(target, "/ \\")