def handle_settodo(bot, ievent): """ todo-set <name> <txt> .. add a todo to another user's todo list""" try: who = ievent.args[0] what = ' '.join(ievent.args[1:]) except IndexError: ievent.missing('<nick> <what>') ;return if not what: ievent.missing('<nick> <what>') ; return userhost = getwho(bot, who) if not userhost: ievent.reply("can't find userhost for %s" % who) ; return whouser = getusers().getname(userhost) if not whouser: ievent.reply("can't find user for %s" % userhost) ; return name = getusers().getname(ievent.userhost) if not getusers().permitted(userhost, name, 'todo'): ievent.reply("%s doesn't permit todo sharing for %s " % (who, name)) ; return what = "%s: %s" % (ievent.nick, what) ttime = strtotime(what) nr = 0 if not ttime == None: ievent.reply('time detected ' + time.ctime(ttime)) what = striptime(what) karma = plugs.get("tl.plugs.db.karma2") if karma: alarmnr = alarms.add(bot.name, who, ttime, what) else: alarmnr = None nr = todo.add(whouser, what, ttime, alarmnr) else: nr = todo.add(whouser, what, None) ievent.reply('todo item %s added' % nr)
def handle_alarmadd(bot, ievent): """ alarm <txt-with-time> | <+delta> <txt> .. add an alarm """ if not ievent.rest: ievent.reply('alarm <txt-with-time> or alarm <+delta> <txt>') ; return else: alarmtxt = ievent.rest if alarmtxt[0] == '+': try: sec = int(ievent.args[0][1:]) except ValueError: ievent.reply('use +nrofsecondstosleep') ; return if len(ievent.args) < 2: ievent.reply('i need txt to remind you') ; return try: ttime = time.time() + sec if ttime > 2**31: ievent.reply("time overflow") ; return if bot.type == "xmpp": if ievent.groupchat: nrid = alarms.add(bot.cfg.name, ievent.nick, ttime, ' '.join(ievent.args[1:]), ievent.channel) else: nrid = alarms.add(bot.cfg.name, ievent.stripped, ttime, ' '.join(ievent.args[1:])) elif bot.type == "irc": if ievent.msg: nrid = alarms.add(bot.cfg.name, ievent.nick, ttime, ' '.join(ievent.args[1:]), ievent.nick) else: nrid = alarms.add(bot.cfg.name, ievent.nick, ttime, ' '.join(ievent.args[1:]), ievent.channel) else: nrid = alarms.add(bot.cfg.name, ievent.nick, ttime, ' '.join(ievent.args[1:]), ievent.channel) ievent.reply("alarm %s set at %s" % (nrid, time.ctime(ttime))) return except Exception as ex: handle_exception(ievent) ; return alarmtime = strtotime(alarmtxt) if not alarmtime: ievent.reply("can't detect time") ; return txt = striptime(alarmtxt).strip() if not txt: ievent.reply('i need txt to remind you') ; return if time.time() > alarmtime: ievent.reply("we are already past %s" % time.ctime(alarmtime)) ; return if bot.jabber: nrid = alarms.add(bot.cfg.name, ievent.nick, alarmtime, txt, ievent.channel) else: nrid = alarms.add(bot.cfg.name, ievent.nick, alarmtime, txt, ievent.channel) ievent.reply("alarm %s set at %s" % (nrid, time.ctime(alarmtime)))
def handle_chantodo2(bot, ievent): """ set todo item for channel""" what = ievent.rest ttime = strtotime(what) nr = 0 if not ttime == None: ievent.reply('time detected ' + time.ctime(ttime)) result = '(%s) ' % ievent.nick + striptime(what) alarms = plugs.get("tl.plugs.extra.alarm") if alarms : alarmnr = alarms.add(bot.name, ievent.channel, ttime, result) else: alarmnr = None nr = todo.add(ievent.channel, result, ttime, alarmnr) else: result = '(%s) ' % ievent.nick + what nr = todo.add(ievent.channel, result, None) ievent.reply('todo item %s added' % nr)
def handle_todo2(bot, ievent): """ set todo item """ if not ievent.rest: ievent.missing("<what>") ; return else: what = ievent.rest name = getusers().getname(ievent.userhost) ttime = strtotime(what) nr = 0 if not ttime == None: ievent.reply('time detected ' + time.ctime(ttime)) what = striptime(what) alarms = plugs.get("tl.plugs.extra.alarm") if alarms : alarmnr = alarms.alarms.add(bot.name, ievent.nick, ttime, what) else: alarmnr = None nr = todo.add(name, what, ttime, alarmnr) else: nr = todo.add(name, what, None) ievent.reply('todo item %s added' % nr)
def handle_todosettime(bot, ievent): """ todo-settime [<channel|name>] <itemnr> <timestring> .. set time \ on todo item """ ttime = strtotime(ievent.txt) if ttime == None: ievent.reply("can't detect time") ; return txt = striptime(ievent.txt) try: (who, itemnr) = txt.split() except ValueError: try: (itemnr, ) = txt.split() who = getusers().getname(ievent.userhost) except ValueError: ievent.missing('[<channe|namel>] <itemnr> <timestring>') ; return try: itemnr = int(itemnr) except ValueError: ievent.missing('[<channel|name>] <itemnr> <timestring>') ; return who = who.lower() if not todo.settime(who, itemnr, ttime): ievent.reply('no todo %s found for %s' % (itemnr, who)) ; return ievent.reply('time of todo %s set to %s' % (itemnr, time.ctime(ttime)))
def handle_tomorrow(bot, ievent): """ todo-tomorrow .. show time related todo items for tomorrow """ username = getusers().getname(ievent.userhost) if ievent.rest: what = ievent.rest ttime = strtotime(what) if ttime != None: if ttime < today() or ttime > today() + 24*60*60: ievent.reply("%s is not tomorrow" % time.ctime(ttime + 24*60*60)) return ttime += 24*60*60 ievent.reply('time detected ' + time.ctime(ttime)) what = striptime(what) else: ttime = today() + 42*60*60 todo.add(username, what, ttime) ievent.reply('todo added') return todoos = todo.withintime(username, today()+24*60*60, today()+2*24*60*60) saytodo(bot, ievent, todoos)
def handle_chatlogstats(bot, event): """ no arguments - create log stats of the channel, possible options: --chan <channel> """ what = event.rest.strip() chatlogdir = getdatadir() + os.sep + "chatlogs" if event.options and event.options.channel: chan = event.options.channel else: chan = event.channel logs = os.listdir(chatlogdir) if not logs: event.reply("no logs available for %s" % chan) ; return now = time.time() if what: timetarget = strtotime2(what) ; what = striptime(what) else: timetarget = 0 ; what = None event.reply("creating stats for channel %s (%s)" % (chan, time.ctime(timetarget))) userstats = StatDict() wordstats = StatDict() stop = False for f in logs[::-1]: filename = stripname(f) channel = stripname(chan) if not channel in filename: continue for line in open(chatlogdir + os.sep + filename, 'r'): splitted = line.strip().split() if len(splitted) < 2: continue who = "unknown" for i in splitted: if i.startswith("<"): who = i[1:-1] if what and who != what: continue timestr = "%s %s" % (splitted[0], splitted[1]) logtime = strtotime2(timestr) if logtime: if logtime > timetarget: userstats.upitem(who) else: continue else: userstats.upitem(who) for word in splitted[4:]: wordstats.upitem(word) if what: result = wordstats.top() else: result = userstats.top() if result: res = ["%s: %s" % item for item in result] event.reply("stat results for %s: " % (what or chan), res) else: event.reply("no result found for %s" % (what or chan))