简体   繁体   English

我的python扭曲的IRC机器人响应命令

[英]My python twisted irc bot responding to commands

Hello People I'm building an irc bot using python twisted, everything is built but the bot doesn't respond to commands like i want it to. 大家好,我正在使用python twist建立一个irc机器人,所有东西都已构建,但是该机器人没有响应我想要的命令。 For example if i want to call a bot command on the irc channel i want to be able to call it like this $time and have the bot reply what time it is, i am able to get it to work like this -> crazybot $time and it prints the time but i don't want to have to type the name every time...How do i get the the bot to run the commands without calling the name first ? 例如,如果我想在irc通道上调用bot命令,我希望能够像这样$ time一样调用它,并让bot答复现在的时间,我就能使它像这样工作-> crazybot $时间并打印时间,但我不想每次都键入名称...我如何让bot在不首先调用名称的情况下运行命令? Here is the update -> everything connects ....... 这是更新->一切都连接.......

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()

.... When i type !time there is no error and no output .. ....当我输入!time时,没有错误,也没有输出..

You could modify MyFirstIrcBot : 您可以修改MyFirstIrcBot

Replace ! 更换! by $ in: $ in:

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

Add: 加:

from datetime import datetime

# ...
def command_time(self, rest):
    return  datetime.utcnow().isoformat()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM