.. _fbf.plugs.extra.remind: remind ~~~~~~ .. automodule:: fbf.plugs.extra.remind :show-inheritance: :members: :undoc-members: CODE ---- :: # fbf/plugs/common/remind.py # # """ remind people .. say txt when somebody gets active """ .. _fbf.plugs.extra.remind_fbf_imports: fbf imports -------------- :: from fbf.utils.generic import getwho from fbf.lib.commands import cmnds from fbf.lib.examples import examples from fbf.lib.callbacks import callbacks from fbf.lib.persist import PlugPersist .. _fbf.plugs.extra.remind_basic_imports: basic imports ---------------- :: import time import os .. _fbf.plugs.extra.remind_Remind-class_: Remind-class --------------- :: class Remind(PlugPersist): """ remind object """ def __init__(self, name): PlugPersist.__init__(self, name) def add(self, who, data): """ add a remind txt """ if who not in self.data: self.data[who] = [] self.data[who].append(data) self.save() def wouldremind(self, userhost): """ check if there is a remind for userhost """ try: reminds = self.data[userhost] if reminds == None or reminds == []: return False except KeyError: return False return True def remind(self, bot, userhost): """ send a user all registered reminds """ reminds = self.data[userhost] if not reminds: return for i in reminds: ttime = None try: (tonick, fromnick, txt, ttime) = i except ValueError: (tonick, fromnick, txt) = i txtformat = '[%s] %s wants to remind you of: %s' if ttime: timestr = time.ctime(ttime) else: timestr = None bot.saynocb(tonick, txtformat % (timestr, fromnick, txt)) bot.saynocb(fromnick, '[%s] reminded %s of: %s' % (timestr, tonick, txt)) try: del self.data[userhost] except KeyError: pass self.save() .. _fbf.plugs.extra.remind_defines_: defines ---------- :: remind = Remind('remind.data') assert remind .. _fbf.plugs.extra.remind_callbacks_: callbacks ------------ :: def preremind(bot, ievent): """ remind precondition """ return remind.wouldremind(ievent.userhost) def remindcb(bot, ievent): """ remind callbacks """ remind.remind(bot, ievent.userhost) callbacks.add('PRIVMSG', remindcb, preremind, threaded=True) callbacks.add('JOIN', remindcb, preremind, threaded=True) callbacks.add('MESSAGE', remindcb, preremind, threaded=True) callbacks.add('WEB', remindcb, preremind, threaded=True) callbacks.add('TORNADO', remindcb, preremind, threaded=True) .. _fbf.plugs.extra.remind_remind_command: remind command ----------------- :: def handle_remind(bot, ievent): """ arguments: - add a remind for a user, as soon as he/she gets online or says something the txt will be send. """ try: who = ievent.args[0] ; txt = ' '.join(ievent.args[1:]) except IndexError: ievent.missing(' ') ; return if not txt: ievent.missing(' ') ; return userhost = getwho(bot, who) if not userhost: ievent.reply("can't find userhost for %s" % who) ; return else: remind.add(userhost, [who, ievent.nick, txt, time.time()]) ievent.reply("remind for %s added" % who) cmnds.add('remind', handle_remind, ['OPER', 'USER', 'GUEST'], allowqueue=False) examples.add('remind', 'remind ', 'remind dunker check the bot !')