我的python扭曲irc bot响应命令

时间:2012-01-26 06:26:17

标签: python command twisted irc bots

Hello People我正在使用python twisted建立一个irc机器人,一切都已构建但机器人不响应我想要的命令。例如,如果我想在irc频道上调用bot命令,我希望能够像这个$ time一样调用它并让机器人回复它的时间,我能够让它像这样工作 - > crazybot $ time它打印时间,但我不想每次都输入名称...如何让机器人运行命令而不先调用名字? 这是更新 - >一切都相连 .......

def privmsg(self, user, channel, msg):
    user = user.split('!', 1)[0]

   if not msg.startswith('#'): # not a trigger command
        return # do nothing
    command, sep, rest = msg.lstrip('#').partition(' ')
    func = getattr(self, 'command_' + command, None)

def command_time(self, *args):
    return time.asctime()

.... 当我键入!时间没有错误,没有输出..

1 个答案:

答案 0 :(得分:0)

您可以修改MyFirstIrcBot

!替换为$ in:

if not message.startswith('!'): # not a trigger command
   return # do nothing
command, sep, rest = message.lstrip('!').partition(' ')

添加:

from datetime import datetime

# ...
def command_time(self, rest):
    return  datetime.utcnow().isoformat()
相关问题