def handle_aliasset(bot, ievent): """ alias-set <from> <to> .. set alias. """ global aliases try: (aliasfrom, aliasto) = (ievent.args[0], ' '.join(ievent.args[1:])) except IndexError: ievent.missing('<from> <to>') return if not aliasto: ievent.missing('<from> <to>') return if aliases.data.has_key(aliasto): ievent.reply("can't alias an alias") return if cmnds.has_key(aliasfrom): ievent.reply('command with same name already exists.') return # add alias and save aliasset(aliasfrom, aliasto) aliases.save() ievent.reply('alias added')
# wait for timer to expire sleep(counter) # check if persist data still exists (no cut event) and kick if so. if bomb.data: # data from different instance, dont cut if not bomb.data[-1] == instancetime: return else: #kick victim bot.sendraw('KICK %s %s :%s' % (ievent.channel, bomb.data[0], 'B000000M!')) #ievent.reply('user: %s, userhost: %s' % (bomb.data[0], bomb.data[3])) bomb.data = [] def cut(bot, ievent): # check if there is a timebomb running if bomb.data: # right userhost? if bomb.data[3] == ievent.ruserhost: # right wire? if ievent.args[0] == bomb.data[2]: bomb.data=[] ievent.reply('%s has defused the bomb.' % ievent.nick) else: bot.sendraw('KICK %s %s :%s' % (ievent.channel, bomb.data[0], 'snip...B000000M!')) bomb.data=[] cmnds.add('timebomb', timebomb, 'USER', threaded=True) aliasset('tb', 'timebomb') cmnds.add('cut', cut, 'USER', threaded=True)
# gozerplugs/trac.py # # from gozerbot.commands import cmnds from gozerbot.examples import examples from gozerbot.aliases import aliasset def handle_tracwiki(bot, ievent): if not ievent.rest: ievent.missing("<item>") return ievent.reply('http://trac.edgewall.org/wiki/%s' % ievent.rest) cmnds.add('trac-wiki', handle_tracwiki, 'USER') examples.add('trac-wiki', 'give t.e.o wiki url', 'trac-wiki TracAdmin') aliasset('wiki', 'trac-wiki')
try: wind_km = round(int(wind[-6:-4]) * 1.609344) except ValueError: wind_km = "" if (not condition == ""): condition = " Oh, and it's " + condition + "." resultstr = "As of %s, %s (%s) has a temperature of %sC/%sF with %s. %s (%s km/h).%s" % (time, city, zip, temp_c, temp_f, humidity, wind, wind_km, condition) elif ievent.command == "forecast": forecasts = gweather.getElementsByTagName('forecast_conditions') for forecast in forecasts: condition = forecast.getElementsByTagName('condition')[0].attributes["data"].value low_f = forecast.getElementsByTagName('low')[0].attributes["data"].value high_f = forecast.getElementsByTagName('high')[0].attributes["data"].value day = forecast.getElementsByTagName('day_of_week')[0].attributes["data"].value low_c = round((int(low_f) - 32) * 5.0 / 9.0) high_c = round((int(high_f) - 32) * 5.0 / 9.0) resultstr += "[%s: F(%sl/%sh) C(%sl/%sh) %s]" % (day, low_f, high_f, low_c, high_c, condition) if not resultstr: ievent.reply('%s not found!' % loc) return else: ievent.reply(resultstr) cmnds.add('weather', handle_weather, 'USER', options={'--u': ''}) aliasset('forecast', 'weather') examples.add('weather', 'get weather for <LOCATION> or <nick>', '1) weather London, \ England 2) weather dunker')
from gozerbot.aliases import aliasset from gozerbot.examples import examples from gozerbot.plughelp import plughelp import random plughelp.add("lart", "do the lart") cfg = PersistConfig() cfg.define("lartlist", []) def handle_lart(bot, ievent): try: who = ievent.args[0] except IndexError: ievent.missing("<who>") return try: txt = random.choice(cfg.get("lartlist")) except IndexError: ievent.reply('lart list is empty .. use lart-add to add entries .. use "<who>" as a nick holder') return txt = txt.replace("<who>", who) bot.action(ievent.channel, txt) cmnds.add("lart", handle_lart, "USER") examples.add("lart", "echo a lart message", "lart dunker") aliasset("lart-add", "lart-cfg lartlist add") aliasset("lart-del", "lart-cfg lartlist remove")
userstate = UserState(username) if item and value: userstate[item] = value userstate.save() result = [] for i, j in userstate.data.iteritems(): result.append("%s=%s" % (i, j)) if result: ievent.reply("userstate of %s: " % username, result, dot=True) else: ievent.reply('no userstate of %s known' % username) cmnds.add('userstate', handle_userstate, 'USER') examples.add('userstate', 'get or set userstate', '1) userstate 2) \ userstate TZ -1') aliasset('set', 'userstate') def handle_userstateget(bot, ievent): if not ievent.rest: ievent.missing('<username>') return userstate = UserState(ievent.rest) result = [] for i, j in userstate.data.iteritems(): result.append("%s=%s" % (i, j)) if result: ievent.reply("userstate of %s: " % ievent.rest, result, dot=True) else: ievent.reply('no userstate of %s known' % ievent.rest) cmnds.add('userstate-get', handle_userstateget, 'OPER')
cfg.save() b = fleet.makebot(name, cfg) try: ievent.reply('adding bot: %s' % str(b)) fleet.addbot(b) ievent.reply('connecting to %s' % server) fleet.connect(name) ievent.reply('%s started' % name) except Exception, ex: ievent.reply(str(ex)) fleet.delete(b) cmnds.add('fleet-addirc', handle_fleetaddirc, 'OPER', options={'--port': '6667'}, threaded=True) examples.add('fleet-addirc', 'fleet-addirc <name> <nick> <server> [ipv6] [port] [passwd] .. add new server to fleet', 'fleet-addirc test3 gozertest localhost') aliasset('fleet-add', 'fleet-addirc') tests.add('fleet-add local test localhost', 'started').add('fleet-del local') def handle_fleetaddjabber(bot, ievent): """ fleed-addjabber <name> <host> <user> <password> [port] .. add jabber bot to fleet. """ try: import xmpp except ImportError: ievent.reply('xmpp is not enabled .. install the xmpppy package') return from gozerbot.jabber.jabberbot import Jabberbot
from gozerbot.plugins import plugins from gozerbot.aliases import aliasset from gozerbot.plughelp import plughelp from gozerbot.tests import tests plughelp.add('code', 'the code plugin provides code related commands') def handle_showexceptions(bot, ievent): """ show exception list. """ ievent.reply(str(exceptionlist)) cmnds.add('code-exceptions' , handle_showexceptions, 'OPER') examples.add('code-exceptions', 'show exception list', 'code-exceptions') aliasset('exceptions', 'code-exceptions') tests.add('code-exceptions') def handle_funcnames(bot, ievent): """ show function names of a plugin. """ try: plugname = ievent.args[0] except IndexError: ievent.missing('<plugname>') return if not plugins.exist(plugname): ievent.reply('no %s plugin exists' % plugname) return
cmnds.add('encoding', handle_encoding, ['USER', 'OPER']) examples.add('encoding', 'show default encoding', 'encoding') tests.add('encoding') def handle_uptime(bot, ievent): """ show uptime. """ ievent.reply("uptime is %s" % elapsedstring(time.time() - bot.starttime)) cmnds.add('uptime', handle_uptime, ['USER', 'WEB', 'JCOLL']) examples.add('uptime', 'show uptime of the bot', 'uptime') aliasset('up', 'uptime') tests.add('uptime', 'uptime is') def handle_userhostcache(bot, ievent): """ show bots userhost cache. """ ievent.reply(str(bot.userhosts.data)) cmnds.add('userhostcache', handle_userhostcache, 'OPER') tests.add('userhostcache', 'dunker') def handle_list(bot, ievent): """ list [<plugin>] .. list loaded plugins or list commands provided by \
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')
if not bot.jabber: stress = re_stress.split(rstr) if len(stress)==3: rstr = "%s\037%s\037%s" % (stress[0], stress[1], stress[2]) # strip html chars rstr = striphtml(rstr) # count if rstr.split(" ", 1)[0][-1] in "0123456789": w, r = rstr.split(" ", 1) rstr = "%s (%s) %s" % (w[:-1], w[-1], r) # bold brac = rstr.find(")1") if brac!=-1: rstr = "%s .. %s" % (rstr[:brac+1], rstr[brac+1:]) else: rstr = "%s" % (rstr) results.append(rstr) pos = pos+spos+epos if results: ievent.reply(url % woord + ' ==>' + ' | '.join(results)) return else: ievent.reply('not found') return cmnds.add('vandale', handle_vandale, 'USER') examples.add('vandale','Lookup <woord> in vandale .. use % for wildcards', 'vandale test%n') aliasset('vd', 'vandale') aliasset('woord', 'vandale')
else: ievent.reply('dispatching "%s" onto %s nodes - wait (%s)' % (cmnd, \ cloud.size(), wait)) cloud.dopost('gozernet/+dispatch', cb, cmnd=cmnd, channel=ievent.channel) if '-d' in ievent.optionset: return time.sleep(wait) aggregator.output(id, ievent) cmnds.add('dispatch', handle_clouddispatch, ['USER', ], allowqueue=False, \ threaded=True, options={'--node': '', '-e': '', '--w': '4', '-d': ''}) examples.add('dispatch', 'dispatch [-d] [-e] [--w <seconds to wait>] \ [--node <nodename>] <cmnd> .. execute <cmnd> in the cloud', \ '1) dispatch version 2) dispatch -d version 3) dispatch -e version 4) \ dispatch --w 10 version') aliasset('d', 'dispatch') aliasset('dd', 'dispatch -d') def handle_cloudping(bot, ievent): """ do a ping on a cloud node """ if not cfg.get('enable'): ievent.reply('cloud is not enabled .. see cloud-enable') return try: name = ievent.args[0] except IndexError: ievent.missing('<name>') return node = cloud.byname(name) if not node: ievent.reply('there is not node named %s' % name)
cloud.dopost('gozernet/+dispatch', cb, cmnd=cmnd, channel=ievent.channel) if '-d' in ievent.optionset: return time.sleep(wait) aggregator.output(id, ievent) cmnds.add('dispatch', handle_clouddispatch, ['USER', ], allowqueue=False, \ threaded=True, options={'--node': '', '-e': '', '--w': '4', '-d': ''}) examples.add('dispatch', 'dispatch [-d] [-e] [--w <seconds to wait>] \ [--node <nodename>] <cmnd> .. execute <cmnd> in the cloud' , \ '1) dispatch version 2) dispatch -d version 3) dispatch -e version 4) \ dispatch --w 10 version' ) aliasset('d', 'dispatch') aliasset('dd', 'dispatch -d') def handle_cloudping(bot, ievent): """ do a ping on a cloud node """ if not cfg.get('enable'): ievent.reply('cloud is not enabled .. see cloud-enable') return try: name = ievent.args[0] except IndexError: ievent.missing('<name>') return node = cloud.byname(name) if not node:
errorlist = [] for i, j in errors.iteritems(): errordict.add(j, i) for error, sites in errordict.iteritems(): errorlist.append("%s => %s" % (' , '.join(sites), error)) ievent.reply("errors: ", errors, dot=True) cmnds.add('install-plug', handle_installplug, 'OPER', threaded=True) examples.add( 'install-plug', 'install-plug <list of plugins> .. try to \ install plugins checking all known sites', '1) install-plug 8b 2) \ install-plug 8b koffie') aliasdel('install-plug') aliasset( 'install-defaultplugs', 'install-plug alarm idle remind quote karma infoitem log ops rss todo seen url snarf dns popcon udp' ) def handle_installkey(bot, ievent): """ install a remote gpg key into the keyring """ if not bot.ownercheck(ievent): return if len(ievent.args) != 1: return ievent.missing('<key id> or <key file url>') url = ievent.args[0] if url.startswith('http://'): try: pubkey = geturl2(url) except urllib2.HTTPError: return ievent.reply('failed to fetch key from %s' % ievent.args[0])
except KeyError: ievent.reply('%s handler is not enabled' % handler) cmnds.add('web-disablehandler', handle_disablehandler, 'OPER') examples.add('web-disablehandler', 'disable web plugin', 'web-disablehandler \ quotes') def handle_enablehandler(bot, ievent): """ enable a web handler """ if not httpd: ievent.reply('webserver is not running') return try: handler = ievent.args[0] except IndexError: ievent.missing('<handler>') return try: if handler in cfg.get('denyplugs'): cfg.remove('denyplugs', handler) httpd.reloadhandler(handler) ievent.reply('%s handler enabled' % handler) except: ievent.reply('failed to enable %s handler' % handler) cmnds.add('web-enablehandler', handle_enablehandler, 'OPER') examples.add('web-enablehandler', 'enable web plugin', 'web-enablehandler \ quotes') aliasset('web-cfg', 'server-cfg')
ievent.reply('default encoding is %s' % sys.getdefaultencoding()) cmnds.add('encoding', handle_encoding, ['USER', 'OPER']) examples.add('encoding', 'show default encoding', 'encoding') tests.add('encoding') def handle_uptime(bot, ievent): """ show uptime. """ ievent.reply("uptime is %s" % elapsedstring(time.time()-bot.starttime)) cmnds.add('uptime', handle_uptime, ['USER', 'WEB', 'JCOLL']) examples.add('uptime', 'show uptime of the bot', 'uptime') aliasset('up', 'uptime') tests.add('uptime', 'uptime is') def handle_userhostcache(bot, ievent): """ show bots userhost cache. """ ievent.reply(str(bot.userhosts.data)) cmnds.add('userhostcache', handle_userhostcache, 'OPER') tests.add('userhostcache', 'dunker') def handle_list(bot, ievent): """ list [<plugin>] .. list loaded plugins or list commands provided by \ plugin.