def init(): global stopped callbacks.add("ALL", simplelogcb, presimplelogcb) jcallbacks.add("ALL", jabbersimplelogcb, jabberpresimplelogcb) outmonitor.add("simplelog", simplelogcb, presimplelogcb) jabbermonitor.add("simplelog", jabbersimplelogcb, jabberpresimplelogcb) stopped = False return 1
def init(): global stopped callbacks.add('ALL', supylogcb, presupylogcb) jcallbacks.add('ALL', jabbersupylogcb, jabberpresupylogcb) outmonitor.add('supylog', supylogcb, presupylogcb) jabbermonitor.add('supylog', jabbersupylogcb, jabberpresupylogcb) stopped = False return 1
def init(): """ init plugin """ # check if enabled if not cfg.get('enable'): return 1 # if so register callbacks callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True) callbacks.add('JOIN', cb_markovjoin, threaded=True) jcallbacks.add('Message', cb_markovtalk, cb_jmarkovtalk_test, \ threaded=True) # learn log or url on startup start_new_thread(markovtrain, (markovlearn.data,)) return 1
def init(): """ init plugin """ # check if enabled if not cfg.get('enable'): return 1 # if so register callbacks callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True) callbacks.add('JOIN', cb_markovjoin, threaded=True) jcallbacks.add('Message', cb_markovtalk, cb_jmarkovtalk_test, \ threaded=True) # learn log or url on startup start_new_thread(markovtrain, (markovlearn.data, )) return 1
jabbermonitor.add('log', jcblogsay, jprelogsay) def prelog(bot, ievent): """ log pre condition """ if ievent.channel and ievent.channel in logs.loglist: return 1 def logcb(bot, ievent): """ callback that logs ievent """ logs.log(bot.name, time.time(), ievent) callbacks.add('ALL', logcb, prelog) jcallbacks.add('Message', logcb, prelog) def handle_logon(bot, ievent): """ log-on .. enable logging in channel the command was given in """ if not ievent.channel in logs.loglist: logs.loglist.append(ievent.channel) ievent.reply('logging enabled in %s' % ievent.channel) else: ievent.reply('%s already in loglist' % ievent.channel) cmnds.add('log-on', handle_logon, 'OPER') examples.add('log-on', 'enable logging of the channel in which the command \ was given', 'log-on')
result = "[%s] %s" % (ievent.nick, ievent.origtxt) relay.check(bot.name, ievent.channel, result, fromm=ievent.userhost) callbacks.add('PRIVMSG', cbrelaypriv, prerelay, threaded=True) def cbMessage(bot, msg): """ jabber relay message callback """ if msg.usercmnd and not msg.groupchat: return if bot.google: result = "[%s] %s" % (msg.userhost, msg.origtxt) else: result = "[%s] %s" % (msg.nick, msg.origtxt) relay.check(bot.name, msg.channel, result, fromm=msg.userhost) jcallbacks.add('Message', cbMessage, prerelay, threaded=True) def cbPresence(bot, msg): """ jabber relay presence callback """ result = None got = False if msg.type == 'unavailable': result = "%s (%s) left %s" % (msg.nick, msg.userhost, msg.channel) try: jabberjoined[msg.channel].remove(msg.nick) except (ValueError, KeyError): pass elif msg.joined: try: if msg.nick in jabberjoined[msg.channel]: got = True
def preremind(bot, ievent): """ remind precondition """ return remind.wouldremind(ievent.userhost) def remindcb(bot, ievent): """ remind callbacks """ remind.remind(bot, ievent.userhost) # monitor privmsg and joins callbacks.add('PRIVMSG', remindcb, preremind, threaded=True) callbacks.add('JOIN', remindcb, preremind, threaded=True) jcallbacks.add('Message', remindcb, preremind, threaded=True) def handle_remind(bot, ievent): """ remind <nick> <txt> .. add a remind """ try: who = ievent.args[0] txt = ' '.join(ievent.args[1:]) except IndexError: ievent.missing('<nick> <txt>') return if not txt: ievent.missing('<nick> <txt>') return userhost = getwho(bot, who) if not userhost:
plughelp.add('autoreply', 'jabber autoreply') def preautoreply(bot, ievent): """ check where autoreply callbacks should fire """ if not ievent.usercmnd and cfg.get('txt') and not ievent.groupchat: return 1 def cbautoreply(bot, ievent): """ do the auto reply """ bot.say(ievent.userhost, cfg.get('txt')) jcallbacks.add('Message', cbautoreply, preautoreply) def handle_autoreplydisable(bot, ievent): """ disable autoreply """ cfg.set('txt', '') ievent.reply('autoreply is disabled') cmnds.add('autoreply-disable', handle_autoreplydisable, 'OPER') examples.add('autoreply-disable', 'disable the autoreply functionality', \ 'autoreply-disable') aliasset('autoreply-set', 'autoreply-cfg txt') aliasset('autoreply-enable', 'autoreply-cfg txt') tests.add('autoreply-enable mekker', 'set').add('autoreply-disable')
cmnds.add('validate', handle_validate, 'USER') examples.add('validate', 'validate an URL', 'validate http://gozerbot.org') aliases.data['valid'] = 'validate' def privmsgpre(bot, ievent): test_url = re_url_match.search(ievent.txt) if test_url: return 1 def privmsgcb(bot, ievent): """ callback for urlcache """ test_url = re_url_match.search(ievent.txt) url = test_url.group(1) if not urlcache.has_key(bot.name): urlcache[bot.name] = {} urlcache[bot.name][ievent.printto] = url rlog(0, 'snarf', 'cached url %s on %s (%s)' % (url, ievent.printto, \ bot.name)) if cfg.data.has_key(bot.name) and cfg.data[bot.name]\ .has_key(ievent.printto) and cfg.data[bot.name][ievent.printto]: nevent = copy.copy(ievent) nevent.rest = url handle_snarf(bot, nevent, False) callbacks.add('PRIVMSG', privmsgcb, privmsgpre, threaded=True) jcallbacks.add('Message', privmsgcb, privmsgpre, threaded=True)
if not remind.data: remind = Remind(datadir + os.sep + 'plugs' + os.sep + 'remind' + os.sep + \ 'remind') def preremind(bot, ievent): """ remind precondition """ return remind.wouldremind(ievent.userhost) def remindcb(bot, ievent): """ remind callbacks """ remind.remind(bot, ievent.userhost) # monitor privmsg and joins callbacks.add('PRIVMSG', remindcb, preremind, threaded=True) callbacks.add('JOIN', remindcb, preremind, threaded=True) jcallbacks.add('Message', remindcb, preremind, threaded=True) def handle_remind(bot, ievent): """ remind <nick> <txt> .. add a remind """ try: who = ievent.args[0] txt = ' '.join(ievent.args[1:]) except IndexError: ievent.missing('<nick> <txt>') return if not txt: ievent.missing('<nick> <txt>') return userhost = getwho(bot, who) if not userhost: ievent.reply("can't find userhost for %s" % who)
return logs.logbot(botname, time.time(), to, txt) jabbermonitor.add('log', jcblogsay, jprelogsay) def prelog(bot, ievent): """ log pre condition """ if ievent.channel and ievent.channel in logs.loglist: return 1 def logcb(bot, ievent): """ callback that logs ievent """ logs.log(bot.name, time.time(), ievent) callbacks.add('ALL', logcb, prelog) jcallbacks.add('Message', logcb, prelog) def handle_logon(bot, ievent): """ log-on .. enable logging in channel the command was given in """ if not ievent.channel in logs.loglist: logs.loglist.append(ievent.channel) ievent.reply('logging enabled in %s' % ievent.channel) else: ievent.reply('%s already in loglist' % ievent.channel) cmnds.add('log-on', handle_logon, 'OPER') examples.add('log-on', 'enable logging of the channel in which the command \ was given', 'log-on') def handle_logoff(bot, ievent): """ log-off .. disable logging in channel the command was given in"""
from gozerbot.tests import tests cfg = PersistConfig() cfg.define('txt', "") plughelp.add('autoreply', 'jabber autoreply') def preautoreply(bot, ievent): """ check where autoreply callbacks should fire """ if not ievent.usercmnd and cfg.get('txt') and not ievent.groupchat: return 1 def cbautoreply(bot, ievent): """ do the auto reply """ bot.say(ievent.userhost, cfg.get('txt')) jcallbacks.add('Message', cbautoreply, preautoreply) def handle_autoreplydisable(bot, ievent): """ disable autoreply """ cfg.set('txt', '') ievent.reply('autoreply is disabled') cmnds.add('autoreply-disable', handle_autoreplydisable, 'OPER') examples.add('autoreply-disable', 'disable the autoreply functionality', \ 'autoreply-disable') aliasset('autoreply-set', 'autoreply-cfg txt') aliasset('autoreply-enable', 'autoreply-cfg txt') tests.add('autoreply-enable mekker', 'set').add('autoreply-disable')
tuple([host] + [result[x] for x in ['result', 'modified', \ 'server', 'size', 'content', 'encoding', 'doctype']])) cmnds.add('validate', handle_validate, 'USER') examples.add('validate', 'validate an URL', 'validate http://gozerbot.org') aliases.data['valid'] = 'validate' def privmsgpre(bot, ievent): test_url = re_url_match.search(ievent.txt) if test_url: return 1 def privmsgcb(bot, ievent): """ callback for urlcache """ test_url = re_url_match.search(ievent.txt) url = test_url.group(1) if not urlcache.has_key(bot.name): urlcache[bot.name] = {} urlcache[bot.name][ievent.printto] = url rlog(0, 'snarf', 'cached url %s on %s (%s)' % (url, ievent.printto, \ bot.name)) if cfg.data.has_key(bot.name) and cfg.data[bot.name]\ .has_key(ievent.printto) and cfg.data[bot.name][ievent.printto]: nevent = copy.copy(ievent) nevent.rest = url handle_snarf(bot, nevent, False) callbacks.add('PRIVMSG', privmsgcb, privmsgpre, threaded=True) jcallbacks.add('Message', privmsgcb, privmsgpre, threaded=True)
""" idle precondition aka check if it is not a command """ if ievent.usercmnd: return 0 else: return 1 def idlecb(bot, ievent): """ idle PRIVMSG callback .. set time for channel and nick """ ttime = time.time() idle.data[jsonstring((bot.name, ievent.channel))] = ttime idle.data[jsonstring((bot.name, ievent.userhost))] = ttime callbacks.add('PRIVMSG', idlecb, preidle) jcallbacks.add('Message', idlecb, preidle) def handle_idle(bot, ievent): """ idle [<nick>] .. show how idle an channel/user has been """ try: who = ievent.args[0] except IndexError: handle_idle2(bot, ievent) return userhost = getwho(bot, who) if not userhost: ievent.reply("can't get userhost of %s" % who) return try: elapsed = elapsedstring(time.time() -
plughelp.add('googletalk', 'the google talk plugin make it possible to link \ to the googletalk servers .. google changes the JID of the bot so this \ plugin detects this and sets the bots JID .. for this to work the bot must \ be in a googletalk users buddieslist') def googletalktest(bot, msg): """ check if presence callbacks should fire. """ if not 'google' in bot.host: return 0 if "vcard-temp:x:update" in str(msg): newjid = msg.getAttrs()['to'] if bot.me != str(newjid): if bot.me in str(newjid): return 1 def googlejidchange(bot, msg): """ set bot jid to the google jid. """ import xmpp newjid = msg.getAttrs()['to'] bot.jid = xmpp.JID(newjid) bot.me = str(bot.jid) bot.google = True rlog(10, 'googletalk', "changed ident to %s" % bot.me) jcallbacks.add('Presence', googlejidchange, googletalktest)
def preidle(bot, ievent): """ idle precondition aka check if it is not a command """ if ievent.usercmnd: return 0 else: return 1 def idlecb(bot, ievent): """ idle PRIVMSG callback .. set time for channel and nick """ ttime = time.time() idle.data[jsonstring((bot.name, ievent.channel))] = ttime idle.data[jsonstring((bot.name, ievent.userhost))] = ttime callbacks.add('PRIVMSG', idlecb, preidle) jcallbacks.add('Message', idlecb, preidle) def handle_idle(bot, ievent): """ idle [<nick>] .. show how idle an channel/user has been """ try: who = ievent.args[0] except IndexError: handle_idle2(bot, ievent) return userhost = getwho(bot, who) if not userhost: ievent.reply("can't get userhost of %s" % who) return try: elapsed = elapsedstring(time.time() - idle.data[jsonstring((bot.name, userhost))]) except KeyError: