def help (self, xmpp_message, room, nick, topic): """ List topics or provide help for a specific one. Compensates for some fat fingering. """ # if no specific topic was specified, list all of them. if not topic: topics = self.bot.help.keys() topics.sort() ret = ["I can offer help on the following topics: " + ", ".join(topics)] ret.append("For help on a specific topic, try: .help topic") return ret # otherwise, provide the description for the specified topic. topic_lower = topic.lower() for k, v in self.bot.help.iteritems(): if topic_lower == k.lower(): return v # no match was found, try to compensate for any fat fingering before giving up. acceptable_distance = min(.85 * len(topic), 3) for k, v in self.bot.help.iteritems(): if helpers.levenshtein_distance(topic_lower, k) <= acceptable_distance: return ["(goodnews) i think you probably meant '%s'..." % k, v] # pick a random emotion of disappointment. emotion = random.choice(["disapproval", "areyoukiddingme", "facepalm", "sadpanda"]) return "(%s) don't know anything about that topic." % emotion
def reminder_reset (self, xmpp_message, room, nick, existing_reminder): """ Reset the period for the reminder. If you don't specify the optional existing reminder message then the last reminder to trigger will be reset. Usage: .reset_reminder [existing reminder message] """ # argument parsing and sanitization. existing_reminder = existing_reminder.strip() # if an existing reminder message was not supplied. found = False if not existing_reminder: # if there is something on the last reminders stack, use that... if self.last_reminders.has_key(nick) and self.last_reminders[nick]: reminder = self.last_reminders[nick].pop() found = True # break apart the reminder tuple. room_id, expiration, days, message = reminder # ...otherwise, complain. else: return "%shmmm, please tell me which reminder you're referring to." % EMOTICON # search for the reminder by exact message match. if not found: # walk through reminders. for reminder in self.reminders.get(nick, []): # break apart the reminder tuple. room_id, expiration, days, message = reminder if message.lower() == existing_reminder.lower(): found = True break # search for the reminder by close message match. if not found: # walk through reminders. for reminder in self.reminders.get(nick, []): # break apart the reminder tuple. room_id, expiration, days, message = reminder # try to find a minimal 85% match. acceptable_distance = min(.85 * len(existing_reminder), 3) if helpers.levenshtein_distance(message.lower(), existing_reminder.lower()) <= acceptable_distance: found = True break if not found: return "%ssorry, but i don't recall you ever asking me to remind you about that in this room." % EMOTICON # remove the reminder and add it back in with a fresh expiration. new_expiration = (datetime.datetime.now() + datetime.timedelta(days=days)).strftime("%Y-%m-%d 00:00:00") new_expiration = time.mktime(time.strptime(new_expiration, "%Y-%m-%d 00:00:00")) self.reminders[nick].remove(reminder) self.reminders[nick].append((room_id, new_expiration, days, message)) # commit the data structure to memory. self.bot.memory_remember("reminders", self.reminders) if days == 1: return "%sok, we'll worry about that again tomorrow." % EMOTICON else: return "%sok, we'll worry about that again in %d days." % (EMOTICON, days)
def reminder_reset(self, xmpp_message, room, nick, existing_reminder): """ Reset the period for the reminder. If you don't specify the optional existing reminder message then the last reminder to trigger will be reset. Usage: .reset_reminder [existing reminder message] """ # argument parsing and sanitization. existing_reminder = existing_reminder.strip() # if an existing reminder message was not supplied. found = False if not existing_reminder: # if there is something on the last reminders stack, use that... if self.last_reminders.has_key(nick) and self.last_reminders[nick]: reminder = self.last_reminders[nick].pop() found = True # break apart the reminder tuple. room_id, expiration, days, message = reminder # ...otherwise, complain. else: return "%shmmm, please tell me which reminder you're referring to." % EMOTICON # search for the reminder by exact message match. if not found: # walk through reminders. for reminder in self.reminders.get(nick, []): # break apart the reminder tuple. room_id, expiration, days, message = reminder if message.lower() == existing_reminder.lower(): found = True break # search for the reminder by close message match. if not found: # walk through reminders. for reminder in self.reminders.get(nick, []): # break apart the reminder tuple. room_id, expiration, days, message = reminder # try to find a minimal 85% match. acceptable_distance = min(.85 * len(existing_reminder), 3) if helpers.levenshtein_distance( message.lower(), existing_reminder.lower()) <= acceptable_distance: found = True break if not found: return "%ssorry, but i don't recall you ever asking me to remind you about that in this room." % EMOTICON # remove the reminder and add it back in with a fresh expiration. new_expiration = ( datetime.datetime.now() + datetime.timedelta(days=days)).strftime("%Y-%m-%d 00:00:00") new_expiration = time.mktime( time.strptime(new_expiration, "%Y-%m-%d 00:00:00")) self.reminders[nick].remove(reminder) self.reminders[nick].append((room_id, new_expiration, days, message)) # commit the data structure to memory. self.bot.memory_remember("reminders", self.reminders) if days == 1: return "%sok, we'll worry about that again tomorrow." % EMOTICON else: return "%sok, we'll worry about that again in %d days." % ( EMOTICON, days)