所以我有一个基于Skybot的IRC机器人。我已经看过它的文档,但没有说明如何去做。我想让它join,quit,part,set mode和其他irc命令,但是要从chan输入它们。简单示例:
.part#你好~分了陈 .mode#你好+b汤姆-禁止汤姆
这就是它在其关于事件的文档中的内容
@hook.event(irc_command)
Event hooks are called whenever a specific IRC command is issued. For example, if you provide "*" as parameter, it will trigger on every line. If you provide "PRIVMSG", it will only trigger on actual lines of chat (not nick-changes).
The first argument in these cases will be a two-element list of the form ["#channel", "text"].
这就是一个简单命令的工作原理。在
from util import hook, http
@hook.command
def calc(inp,say=None):
'Does calculation'
h = http.get_html('http://www.google.com/search', q=inp)
m = h.xpath('//h2[@class="r"]/text()')
if not m:
say("I can't calculate " + inp + ".")
res = ' '.join(m[0].split())
say(res + ".")
钩子.py
^{pr2}$而且其他副本有一个钩子事件在那里指挥:
#autorejoin channels
@hook.event('KICK')
def rejoin(paraml, conn=None):
if paraml[1] == conn.nick:
if paraml[0].lower() in conn.channels:
conn.join(paraml[0])
#join channels when invited
@hook.event('INVITE')
def invite(paraml, conn=None):
conn.join(paraml[-1])
@hook.event('004')
def onjoin(paraml, conn=None):
# identify to services
nickserv_password = conn.conf.get('nickserv_password', '')
nickserv_name = conn.conf.get('nickserv_name', 'nickserv')
nickserv_command = conn.conf.get('nickserv_command', 'IDENTIFY %s')
if nickserv_password:
conn.msg(nickserv_name, nickserv_command % nickserv_password)
time.sleep(1)
# set mode on self
mode = conn.conf.get('mode')
if mode:
conn.cmd('MODE', [conn.nick, mode])
# join channels
for channel in conn.channels:
conn.join(channel)
time.sleep(1) # don't flood JOINs
# set user-agent
ident, rev = get_version()
主.py,这里定义了conn事物。在
class Input(dict):
def __init__(self, conn, raw, prefix, command, params,
nick, user, host, paraml, msg):
chan = paraml[0].lower()
if chan == conn.nick.lower(): # is a PM
chan = nick
def say(msg):
conn.msg(chan, msg)
def reply(msg):
if chan == nick: # PMs don't need prefixes
conn.msg(chan, msg)
else:
conn.msg(chan, nick + ': ' + msg)
def pm(msg):
conn.msg(nick, msg)
def set_nick(nick):
conn.set_nick(nick)
def me(msg):
conn.msg(chan, "\x01%s %s\x01" % ("ACTION", msg))
def notice(msg):
conn.cmd('NOTICE', [nick, msg])
dict.__init__(self, conn=conn, raw=raw, prefix=prefix, command=command,
params=params, nick=nick, user=user, host=host,
paraml=paraml, msg=msg, server=conn.server, chan=chan,
notice=notice, say=say, reply=reply, pm=pm, bot=bot,
me=me, set_nick=set_nick, lastparam=paraml[-1])
# make dict keys accessible as attributes
def __getattr__(self, key):
return self[key]
def __setattr__(self, key, value):
self[key] = value
我真的不知道我该怎么做。谢谢你的帮助!在
目前没有回答
相关问题 更多 >
编程相关推荐