本文整理汇总了Python中tl.lib.commands.cmnds.add函数的典型用法代码示例。如果您正苦于以下问题:Python add函数的具体用法?Python add怎么用?Python add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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")
开发者ID:buzzworkers,项目名称:tl,代码行数:10,代码来源:fish.py
示例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()
开发者ID:buzzworkers,项目名称:tl,代码行数:31,代码来源:plug.py
示例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')
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:karma.py
示例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))
开发者ID:buzzworkers,项目名称:tl,代码行数:29,代码来源:overflow.py
示例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
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:admin.py
示例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()
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:geo.py
示例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')
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:wikipedia.py
示例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]')
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:gatekeeper.py
示例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)
开发者ID:buzzworkers,项目名称:tl,代码行数:31,代码来源:controlchar.py
示例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()
开发者ID:buzzworkers,项目名称:tl,代码行数:29,代码来源:forward.py
示例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')
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:snarf.py
示例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"])
开发者ID:buzzworkers,项目名称:tl,代码行数:29,代码来源:yacy.py
示例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')
开发者ID:buzzworkers,项目名称:tl,代码行数:31,代码来源:koffie.py
示例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()
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:irc.py
示例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
开发者ID:buzzworkers,项目名称:tl,代码行数:29,代码来源:urban.py
示例16: handle_uniq
# tl/plugs/core/uniq.py
#
#
""" used in a pipeline .. unique elements. """
__author__ = "Wijnand 'tehmaze' Modderman - http://tehmaze.com"
__license__ = 'BSD'
## tl imports
from tl.lib.examples import examples
from tl.lib.commands import cmnds
from tl.utils.generic import waitforqueue
## basic imports
import time
## uniq command
def handle_uniq(bot, ievent):
""" no arguments - uniq the result list, use this command in a pipeline. """
if not ievent.inqueue: time.sleep(0.5)
result = list(ievent.inqueue)
if not result: ievent.reply('no result')
else: ievent.reply("result: ", result)
cmnds.add('uniq', handle_uniq, ['OPER', 'USER', 'GUEST'])
examples.add('uniq', 'sort out multiple elements', 'list ! uniq')
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:uniq.py
示例17: handle_to
""" send output to another user .. used in a pipeline. """
## tl imports
from tl.lib.commands import cmnds
from tl.utils.generic import getwho, waitforqueue
from tl.lib.examples import examples
## basic imports
import time
## to command
def handle_to(bot, ievent):
""" arguments: <nick> - direct output to <nick>, use this command in a pipeline. """
try: nick = ievent.args[0]
except IndexError: ievent.reply('to <nick>') ; return
if nick == 'me': nick = ievent.nick
if not getwho(bot, nick): ievent.reply("don't know %s" % nick) ; return
if not ievent.inqueue: time.sleep(1)
if ievent.inqueue:
bot.say(nick, "%s sends you this:" % ievent.nick)
bot.say(nick, " ".join(ievent.inqueue))
if len(ievent.inqueue) == 1: ievent.reply('1 element sent')
else: ievent.reply('%s elements sent' % len(ievent.inqueue))
else: ievent.reply('nothing to send')
cmnds.add('to', handle_to, ['OPER', 'USER', 'TO'])
examples.add('to', 'send pipeline output to another user', 'list ! to dunker')
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:to.py
示例18: handle_op1
## op command
def handle_op1(bot, ievent):
""" op [<nick>] .. op an user """
chan = ievent.channel.lower()
#if bot.state.has_key('no-op') and chan in bot.state['no-op']:
# ievent.reply('opping is disabled in %s' % ievent.channel)
# return
try: nick = ievent.args[0]
except IndexError: nick = ievent.nick
userhost = getwho(bot, nick)
if not userhost: userhost = ievent.userhost
if (ievent.user and 'OPER' in ievent.user.data.perms) or (ievent.chan and userhost in ievent.chan.data.ops): bot.doop(chan, nick)
ievent.done()
cmnds.add('op', handle_op1, 'USER', threaded=True, speed=9)
examples.add('op', 'op [<nick>] .. give ops to <nick> or op the person giving the command', '1) op 2) op dunker')
## ops-permadd command
def handle_permadd(bot, ievent):
if not ievent.chan: ievent.reply("channel is not set in event") ; return
try: nick = ievent.args[0]
except IndexError: nick = ievent.nick
userhost = getwho(bot, nick)
if not userhost: userhost = ievent.userhost
if not userhost in ievent.chan.data.ops:
ievent.chan.data.ops.append(userhost)
ievent.chan.save()
ievent.reply("added %s to the permenent ops list" % userhost)
else: ievent.reply("%s is already in permops list" % userhost)
开发者ID:buzzworkers,项目名称:tl,代码行数:31,代码来源:ops.py
示例19: handle_autovoiceon
chandata = 0
if not ievent.chan: ievent.bind(bot, force=True)
try: chandata = ievent.chan.data.autovoice
except KeyError: return
if chandata: bot.voice(ievent.channel, ievent.nick)
callbacks.add('JOIN', cbautovoice, preautovoice)
## autovoice-on command
def handle_autovoiceon(bot, ievent):
""" autovoice-on .. enable autovoice for channel the command was given in """
try: ievent.chan.data.autovoice = 1
except TypeError: ievent.reply('no %s in channel database' % ievent.channel) ; return
ievent.reply('autovoice enabled on %s' % ievent.channel)
cmnds.add('autovoice-on', handle_autovoiceon, 'OPER')
examples.add('autovoice-on', 'enable autovoice on channel in which the command is given', 'autovoice-on')
## autovoice-off command
def handle_autovoiceoff(bot, ievent):
""" autovoice-off .. disable autovoice for the channel the command was given in """
try:
ievent.chan.data.autovoice = 0
ievent.reply('autovoice disabled on %s' % ievent.channel)
except TypeError: ievent.reply('no %s channel in database' % ievent.channel)
cmnds.add('autovoice-off', handle_autovoiceoff, 'OPER')
examples.add('autovoice-off', 'disable autovoice on channel in which the command is given', 'autovoice-off')
开发者ID:buzzworkers,项目名称:tl,代码行数:30,代码来源:autovoice.py
示例20: handle_count
# tl/plugs/core/count.py
#
#
""" count number of items in result queue. """
## tl imports
from tl.lib.commands import cmnds
from tl.utils.generic import waitforqueue
from tl.lib.examples import examples
## basic imports
import time
## count command
def handle_count(bot, ievent):
""" no arguments - show nr of elements in result list .. use this command in a pipeline. """
#if ievent.prev: ievent.prev.wait()
a = ievent.inqueue
size = len(a)
ievent.reply(str(size))
cmnds.add('count', handle_count, ['OPER', 'USER', 'GUEST'])
examples.add('count', 'count nr of items', 'list ! count')
开发者ID:buzzworkers,项目名称:tl,代码行数:27,代码来源:count.py
注:本文中的tl.lib.commands.cmnds.add函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论