def message(bot, trigger): tellee = trigger.nick channel = trigger.sender tells = [] nicks = list(reversed(sorted(bot.memory['tell_dict'].keys()))) for nick in nicks: if tellee.lower() == nick.lower() or (nick.endswith('*') and tellee.lower().startswith(nick.lower().rstrip('*:'))): bot.memory['tell_lock'].acquire() try: new_key = [] for (teller, verb, datetime, msg) in bot.memory['tell_dict'][nick]: if verb.lower()=='tell': tells.append("[Sent %s] <%s> %s" % (pretty_date(datetime), teller, msg)) if verb.lower()=='inform': tells.append("[I] [Sent %s] <%s> %s" % (pretty_date(datetime), teller, msg)) elif verb.lower()=='watch': if trigger.is_privmsg is False: if teller in bot.privileges[channel]: bot.msg(teller, "%s just spoke in %s." % (tellee, channel)) else: bot.msg(teller, "%s just spoke in a channel you aren't in." % (tellee)) else: if datetime-time.time()<86400: new_key.append((teller, verb, datetime, msg)) if new_key: bot.memory['tell_dict'][nick] = new_key else: try: del bot.memory['tell_dict'][nick] except KeyError: bot.msg(channel, 'Er...') finally: bot.memory['tell_lock'].release() for line in tells: bot.msg(tellee, line) storage.put('tell',bot.memory['tell_dict'])
def seen(bot, trigger): """Reports when and where the user was last seen. Use * on the end of [recipient] to match multiple nicks (e.g Tell*)""" if not trigger.group(2): return bot.say("Seen whom?") nick = trigger.group(2).strip().lower() if nick == str(trigger.nick).lower(): return bot.action('holds up a mirror.') if nick == bot.nick.lower() or nick == 'cashy': return bot.say("I'm right here.") true_nick = None if not nick.endswith('*'): if nick in bot.memory['seen_dict']: true_nick = nick nick_string = trigger.group(2).strip() else: start = nick.rstrip('*:') test_time = 0 for n in bot.memory['seen_dict'].keys(): if n.startswith(start) and bot.memory['seen_dict'][n]['timestamp']>test_time and n != str(trigger.nick).lower(): test_time = bot.memory['seen_dict'][n]['timestamp'] true_nick = n if true_nick: if 'name' in bot.memory['seen_dict'][true_nick]: name = bot.memory['seen_dict'][true_nick]['name'] else: name = true_nick if bot.memory['seen_dict'][true_nick]['channel'].lower() == trigger.sender.lower(): message = bot.memory['seen_dict'][true_nick]['message'] if len(message) > 100: message = message[:97]+'...' msg = "I saw %s %s, saying '%s'" % (name, pretty_date(bot.memory['seen_dict'][true_nick]['timestamp']), message) else: msg = "I saw %s %s in another channel." % (name, pretty_date(bot.memory['seen_dict'][true_nick]['timestamp'])) bot.say(str(trigger.nick) + ': ' + msg) else: bot.say("I've never seen %s." % trigger.group(2).strip())
def message(bot, trigger): tellee = trigger.nick channel = trigger.sender tells = [] nicks = list(reversed(sorted(bot.memory['tell_dict'].keys()))) for nick in nicks: if tellee == nick or (nick.endswith('*') and tellee.startswith(nick.rstrip('*:'))): bot.memory['tell_lock'].acquire() try: new_key = [] for (teller, verb, datetime, msg) in bot.memory['tell_dict'][nick]: if verb.lower()=='tell': tells.append("[Sent %s] <%s> %s" % (pretty_date(datetime), teller, msg)) if verb.lower()=='inform': tells.append("[I] [Sent %s] <%s> %s" % (pretty_date(datetime), teller, msg)) elif verb.lower()=='watch': if trigger.is_privmsg is False: bot.msg(teller, "%s just spoke in %s." % (tellee, channel)) else: if datetime-time.time()<86400: new_key.append((teller, verb, datetime, msg)) if new_key: bot.memory['tell_dict'][nick] = new_key else: try: del bot.memory['tell_dict'][nick] except KeyError: bot.msg(channel, 'Er...') finally: bot.memory['tell_lock'].release() for line in tells: bot.msg(tellee, line) storage.put('tell',bot.memory['tell_dict'])
def channels(bot, trigger): """Lists all channels the bot is in. This is an admin-only command.""" # Can only be done in privmsg by an admin if not trigger.is_privmsg: return if trigger.admin: channel_list = [] for c in bot.privileges.keys(): if 'channel_timer_dict' in bot.memory and c.lower() in bot.memory['channel_timer_dict']: channel_list.append("%s (%s): %i" % (c, pretty_date(bot.memory['channel_timer_dict'][c.lower()]), len(bot.privileges[c]))) else: channel_list.append("%s (?): %i" % (c, len(bot.privileges[c]))) return bot.say(" | ".join(channel_list),10)