本文整理汇总了Python中tl.lib.commands.cmnds.add函数的典型用法代码示例。如果您正苦于以下问题:Python add函数的具体用法?Python add怎么用?Python add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
def init():
""" Init """
if not got: raise RequireError("PyCrypto is required for FiSH. Please install this library if you want to use this plug")
if cfg.enable:
inputmorphs.add(fishin)
outputmorphs.add(fishout)
callbacks.add("NOTICE", dh1080_exchange)
cmnds.add("fish", handle_fish, "OPER")
examples.add("fish", "command that handles fish enrypting over IRC", "fish help")
else: logging.warn("fish plugin is not enabled - use fish-cfg enable 1")
示例2: handle_plugenable
## plug-enable command
def handle_plugenable(bot, event):
""" arguments" <plugname> - enable a plugin. """
if not event.rest: event.missing("<plugname>") ; return
if "." in event.rest: mod = event.rest
else: mod = bot.plugs.getmodule(event.rest)
if not mod: event.reply("can't find module for %s" % event.rest) ; return
event.reply("reloading and enabling %s" % mod)
plugenable(mod)
bot.enable(mod)
bot.plugs.reload(mod, force=True)
update_mod(mod)
event.done()
cmnds.add("plug-enable", handle_plugenable, ["OPER", ])
examples.add("plug-enable", "enable a plugin", "plug-enable rss")
## plug-disable command
def handle_plugdisable(bot, event):
""" arguments: <plugname> - disable a plugin. """
if not event.rest: event.missing("<plugin>") ; return
mod = bot.plugs.getmodule(event.rest)
if mod in default_plugins: event.reply("can't remove a default plugin") ; return
if not mod: event.reply("can't find module for %s" % event.rest) ; return
event.reply("unloading and disabling %s" % mod)
bot.plugs.unload(mod)
plugdisable(mod)
bot.disable(mod)
event.done()
示例3: handle_exception
try: ratelimited.remove(name)
except ValueError: pass
return 1
except Exception as ex: handle_exception(ievent)
## karma-get command
def handle_karmaget(bot, ievent):
""" karma-get <item> .. show karma of item """
if not ievent.rest: ievent.missing('<item>') ; return
else: item = ievent.rest
result = karma.get(item)
if result: ievent.reply("%s has karma %s" % (item, str(result)))
else: ievent.reply("%s has no karma yet" % item)
cmnds.add('karma-get', handle_karmaget, ['USER', 'WEB', 'ANON', 'ANONKARMA'])
examples.add('karma-get', 'karma-get <item> .. show karma of <item>', 'karma-get dunker')
## karma-del command
def handle_karmadel(bot, ievent):
""" karma-del <item> .. delete karma item """
if not ievent.rest: ievent.missing('<item>') ; return
item = ievent.rest
result = karma.delete(item)
if result: ievent.reply("%s deleted" % item)
else: ievent.reply("can't delete %s" % item)
cmnds.add('karma-del', handle_karmadel, ['OPER'])
examples.add('karma-del', 'karma-del <item> .. delete karma item', 'karma-del dunker')
示例4: handle_overflowstart
def handle_overflowstart(bot, event):
global state
for bla in event.args:
try: name, gid = bla.split(":")
except: name = gid = bla
state.data.names[gid] = name
target = [bot.cfg.name, event.channel]
if gid not in state.data.ids: state.data.ids[gid] = []
if not gid in state.data.watch or not target in state.data.ids[gid]: state.data.ids[gid].append(target) ; state.data.watch.append(gid)
else: event.reply("we are already monitoring %s in %s" % (gid, str(target)))
state.save()
sync()
event.done()
cmnds.add("overflow-start", handle_overflowstart, ["OPER", ])
examples.add("overflow-start", "start monitoring a stackoverflow id into the channel", "overflow-start feedbackoverflow:625681")
## overflow-stop command
def handle_overflowstop(bot, event):
if not event.args: event.missing("<stackoveflow id") ; return
global state
id = event.args[0]
try:
del state.data.ids[id]
del state.data.names[id]
state.save()
event.done()
except (KeyError, ValueError): event.reply("we are not monitoring %s in %s" % (id, event.channel))
示例5: handle_adminsave
import logging
## admin-save command
def handle_adminsave(bot, ievent):
""" no arguments - boot the bot .. do some initialisation. """
ievent.reply("saving mainconfig")
getmainconfig().save()
ievent.reply("saving fleet bots")
getfleet().save()
ievent.reply("saving all plugins")
plugs.save()
ievent.done()
cmnds.add('admin-save', handle_adminsave, 'OPER')
examples.add('admin-save', 'initialize the bot', 'admin-boot')
## admin-boot command
def handle_adminboot(bot, ievent):
""" no arguments - boot the bot .. do some initialisation. """
ievent.reply("reloading all plugins")
if 'saveperms' in ievent.rest: boot(force=True, saveperms=True, clear=True)
else: boot(force=True, saveperms=False, clear=True)
ievent.done()
cmnds.add('admin-boot', handle_adminboot, 'OPER')
examples.add('admin-boot', 'initialize the bot', 'admin-boot')
## admin-bootthreaded command
示例6: handle_geo
## geo command
def handle_geo(bot, event):
""" arguments: <ipnr> - do a geo lookup. """
if not event.rest:
event.missing("<ipnr>")
return
query = event.rest.strip()
ip = host2ip(query)
if not ip: event.reply("Couldn't look up the hostname") ; return
res = querygeoipserver(ip)
if res: event.reply("geo of %s is: " % ip, res)
else: event.reply("no result")
cmnds.add("geo", handle_geo, ["OPER", "GEO"])
examples.add("geo", "do a geo lookup on ip nr", "geo 127.0.0.1")
## callbacks
def handle_geoPRE(bot, event):
if "." in event.hostname and event.chan and event.chan.data.dogeo: return True
def handle_geoJOIN(bot, event):
event.reply("geo - doing query on %s" % event.hostname)
try:
result = querygeoipserver(host2ip(event.hostname))
if result: event.reply("%s lives in %s, %s (%s)" % (event.nick, result['city'], result['country_name'], result['country_code']))
else: event.reply("no result")
except: handle_exception()
示例7: handle_wikipedia
txt = re.sub('\s+', ' ', txt)
txt = txt.replace('|', ' - ')
return txt
## wikipedia command
resultre1 = re.compile("(<li>.*?</li>)")
resultre2 = re.compile("(<h2>.*?</h2>)")
def handle_wikipedia(bot, ievent):
""" arguments: <searchtxt> ["-"<countrycode>] - search wikipedia, you can provide an optional country code. """
if not ievent.rest: ievent.missing('<searchtxt>') ; return
showall = False
res = searchwiki(ievent.rest)
if not res[0]: ievent.reply('no result found') ; return
prefix = '%s ===> ' % res[1]
result = resultre1.findall(res[0])
if result:
if bot.type == "sxmpp" and not ievent.groupchat: showall = True
ievent.reply(prefix, result, dot="<br>", showall=showall)
return
result2 = resultre2.findall(res[0])
if result2:
if bot.type == "sxmpp" and not ievent.groupchat: showall = True
ievent.reply(prefix, result2, dot="<br>", showall=showall)
return
else: ievent.reply("no data found on %s" % event.rest)
cmnds.add('wikipedia', handle_wikipedia, ['USER', 'GUEST'])
examples.add('wikipedia', 'search wikipedia for <what>','1) wikipedia bot 2) wikipedia -nl bot')
示例8: handle_gatekeeperallow
#
""" gatekeeper commands. """
## tl imports
from tl.lib.commands import cmnds
from tl.lib.examples import examples
## gatekeeper-allow command
def handle_gatekeeperallow(bot, event):
""" arguments: <userhost> - allow user on bot. """
if not event.rest: event.missing("<userhost>") ; return
bot.gatekeeper.allow(event.rest)
event.done()
cmnds.add('gatekeeper-allow', handle_gatekeeperallow, 'OPER')
examples.add('gatekeeper-allow', 'add JID of remote bot that we allow to receice events from', 'gatekeeper-allow [email protected]')
## gatekeeper-deny command
def handle_gatekeeperdeny(bot, event):
""" arguments: userhost - deny user on bot. """
if not event.rest: event.missing("<userhost>") ; return
bot.gatekeeper.deny(event.rest)
event.done()
cmnds.add('gatekeeper-deny', handle_gatekeeperdeny, 'OPER')
examples.add('gatekeeper-deny', 'remove JID of remote bot', 'gatekeeper-deny [email protected]')
示例9: len
if len(what) > 1:
ievent.reply("only one character is allowed")
return
try: ievent.chan.data.cc = what
except (KeyError, TypeError):
ievent.reply("no channel %s in database" % chan)
return
ievent.chan.save()
ievent.reply('control char set to %s' % what)
except IndexError:
try:
cchar = ievent.getcc()
ievent.reply('controlchar are/is %s' % cchar)
except (KeyError, TypeError): ievent.reply("default cc is %s" % bot.cfg['defaultcc'])
cmnds.add('cc', handle_cc, 'USER')
examples.add('cc', 'set control char of channel or show control char of channel','1) cc ! 2) cc')
## cc-add command
def handle_ccadd(bot, ievent):
""" arguments: <character> - add a control char to the channels cc list. """
try:
what = ievent.args[0]
if not bot.users.allowed(ievent.userhost, 'OPER'): return
if len(what) > 1:
ievent.reply("only one character is allowed")
return
try: ievent.chan.data.cc += what
except (KeyError, TypeError):
ievent.reply("no channel %s in database" % ievent.channel)
示例10: handle_forwardadd
def handle_forwardadd(bot, event):
""" arguments: <bot JID> - add a new forward (xmpp account). """
if not event.rest:
event.missing('<bot JID>')
return
if "@" in event.rest:
forward.data.outs[event.rest] = event.user.data.name
forward.save()
if not event.rest in event.chan.data.forwards: event.chan.data.forwards.append(event.rest)
else: event.reply("arguments must be a JID (Jabber ID).") ; return
if event.rest:
event.chan.save()
event.done()
cmnds.add("forward-add", handle_forwardadd, 'OPER')
examples.add("forward-add" , "add a bot JID to forward to", "forward-add [email protected]")
## forward-del command
def handle_forwarddel(bot, event):
""" arguments: <bot JID> - delete a forward. """
if not event.rest:
event.missing('<bot JID>')
return
try: del forward.data.outs[event.rest]
except KeyError: event.reply("no forward out called %s" % event.rest) ; return
forward.save()
if event.rest in event.chan.data.forwards: event.chan.data.forwards.remove(event.rest) ; event.chan.save()
event.done()
示例11: str
except SnarfException as e:
if direct: ievent.reply('unable to snarf: %s' % str(e))
return
except urllib.error.HTTPError as e: ievent.reply('unable to snarf: %s' % str(e)) ; return
except urllib.error.URLError as ex: ievent.reply('unable to snarf: %s' % str(ex)) ; return
if not url: ievent.reply('invalid url') ; return
try: title = geturl_title(url)
except socket.timeout: ievent.reply('%s socket timeout' % url) ; return
except urllib.error.HTTPError as e: ievent.reply('error: %s' % e) ; return
if title:
host = urllib.parse.urlparse(url)[1]
if len(host) > 20: host = host[0:20] + '...'
ievent.reply('%s: %s' % (host, title))
else: ievent.reply('no title found at %s' % urllib.parse.urlparse(url)[1])
cmnds.add('snarf', handle_snarf, 'USER', threaded=True)
cmnds.add('@', handle_snarf, 'USER', threaded=True)
examples.add('snarf', 'fetch the title from an URL', 'snarf http://ggzpreventie.nl')
## snarf-enable command
def handle_snarf_enable(bot, ievent):
""" enable snarfing in channel """
if bot.name not in cfg.data: cfg.data[bot.name] = {}
cfg.data[bot.name][ievent.printto] = True
cfg.save()
ievent.reply('ok')
cmnds.add('snarf-enable', handle_snarf_enable, 'OPER')
examples.add('snarf-enable', 'enable snarfing in the channel', 'snarf-enable')
示例12: getresults
def getresults(url):
logging.warn(url)
result = geturl2(url)
return result
## yacy command
def handle_yacy(bot, event):
if not event.rest: event.missing("<searchitem>") ; return
global hosts
random.shuffle(hosts)
got = ""
r = None
logging.warn("error hosts is %s" % str(errorhosts))
if len(hosts) == len(errorhosts): event.reply("no alive server found") ; return
for h in prio1 + hosts:
if h in errorhosts: continue
try:
r = json.loads(getresults(queryurl % (h, urllib.parse.quote_plus(event.rest))))
if r: got = h ; break
except Exception as ex: errorhosts.append(h) ; handle_exception() ; continue
result = []
for channel in r['channels']:
for item in channel['items']: result.append("%s - %s (%s)" % (item['title'], item['link'], item['size']))
if result: event.reply("results from %s: " % got, result, dot=" || ")
else: event.reply("no result")
cmnds.add("yacy", handle_yacy, ["OPER", "USER"])
示例13: handle_koffie
if not bot.allowall: bot.action(ievent.channel, txt, event=ievent)
else: bot.say(ievent.channel, txt, event=ievent)
## koffie command
def handle_koffie(bot, ievent):
""" arguments: [<nick>] - get/give a coffee """
rand = random.randint(0,len(koffie)-1)
try:
input = ievent.args[0]
nick = '%s' % input
except:
if len('%s') >= 0: nick = ievent.nick
do(bot, ievent, koffie[rand] + " " + nick)
cmnds.add('koffie', handle_koffie, 'USER')
examples.add('koffie', 'get a koffie quote', 'koffie')
## thee command
def handle_thee(bot, ievent):
""" arguments: [<nick>] - get/give a thee """
rand = random.randint(0,len(thee)-1)
try:
input = ievent.args[0]
nick = '%s' % input
except:
if len('%s') >= 0: nick = ievent.nick
do(bot, ievent, thee[rand] + " " + nick)
cmnds.add('thee', handle_thee, 'USER')
示例14: handle_broadcast
ignorenicks = []
## broadcast command
def handle_broadcast(bot, ievent):
""" arguments: <txt> - broadcast txt to all joined channels. """
if not ievent.rest:
ievent.missing('<txt>')
return
ievent.reply('broadcasting')
getfleet().broadcast(ievent.rest)
partyline.say_broadcast(ievent.rest)
ievent.reply('done')
cmnds.add('broadcast', handle_broadcast, 'OPER', threaded=True)
examples.add('broadcast', 'send a message to all channels and dcc users', 'broadcast good morning')
## jump command
def handle_jump(bot, ievent):
""" arguments: <server> <port> - change server. """
if bot.jabber:
ievent.reply('jump only works on irc bots')
return
if len(ievent.args) != 2:
ievent.missing('<server> <port>')
return
(server, port) = ievent.args
ievent.reply('changing to server %s' % server)
bot.shutdown()
示例15: handle_urban
def handle_urban(bot, ievent):
""" urban <what> .. search urban for <what> """
if len(ievent.args) > 0:
what = " ".join(ievent.args)
else:
ievent.missing("<search query>")
return
try:
data = geturl2(url + urllib.parse.quote_plus(what))
if not data:
ievent.reply("word not found: %s" % what)
return
data = json.loads(data)
if data["result_type"] == "no_result":
ievent.reply("word not found: %s" % what)
return
res = []
for r in data["list"]:
res.append(r["definition"])
ievent.reply("result: ", res)
except Exception as ex:
ievent.reply(str(ex))
cmnds.add("urban", handle_urban, ["OPER", "USER", "GUEST"])
examples.add("urban", "urban <what> .. search urbandictionary for <what>", "1) urban bot 2) urban shizzle")
#### BHJTW 23-01-2012
#### BHJTW 10-03-2012