【问题标题】:My python twisted irc bot responding to commands我的 python 扭曲 irc 机器人响应命令
【发布时间】:2023-04-08 11:02:01
【问题描述】:

大家好,我正在使用 python twisted 构建一个 irc 机器人,一切都已构建,但机器人不会像我想要的那样响应命令。例如,如果我想在 irc 频道上调用一个机器人命令,我希望能够像这样调用它 $time 并让机器人回复它是什么时间,我可以让它像这样工作 -> crazybot $时间,它会打印时间,但我不想每次都输入名称...如何让机器人在不先调用名称的情况下运行命令? 这是更新->一切都连接 .......

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

.... 当我输入 !time 时没有错误也没有输出..

【问题讨论】:

  • 您是否开始使用现有项目?还是你从头开始写的?
  • sscce.org 否则你不会得到有用的答案。

标签: python command twisted irc bots


【解决方案1】:

你可以修改MyFirstIrcBot:

! 替换为$

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-09-13
  • 2021-07-22
  • 2011-06-19
  • 2023-03-07
  • 2010-09-29
  • 2022-10-24
  • 2022-12-15
  • 2021-10-06
相关资源
最近更新 更多