Python Twisted IRC bot KeyError

时间:2014-07-03 23:22:27

标签: python twisted bots irc

我试图在机器人上运行反垃圾邮件,但是当有人发送垃圾邮件时我会遇到以下错误。

Exception in thread Thread-249:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/ircbot/ftb/system/irc.py", line 455, in privmsg
    difference = msg_time - self.chanlist[channel][user]["last_time"]
KeyError: 'last_time'

以下是反垃圾邮件的代码

if self.use_antispam:
            msg_time = float(time.time())
            if not ((authorized) or self.is_voice(user, channel)) and channel.startswith("#"):
                difference = msg_time - self.chanlist[channel][user]["last_time"]
                if difference < 0.15:
                    # User is a dirty spammer!
                    if self.is_op(channel, self.nickname):
                        if not user in self.kicked:
                            self.sendLine("KICK %s %s :%s is a dirty spammer!" % (channel, user, user))
                            self.logs.warn("Kicked %s from %s for spamming." % (user, channel))
                            self.kicked.append(user)
                            return

                        else:
                            self.sendLine(
                                "MODE %s +bbb *!%s@* %s!*@* *!*@%s" % (
                                    channel, userhost.split("@")[0].split("!")[1], user, userhost.split("@")[1]))
                            self.sendLine("KICK %s %s :%s is a dirty spammer!" % (channel, user, user))
                            self.logs.warn(" Banned %s from %s for spamming." % (user, channel))
                            return

感谢任何帮助

0 个答案:

没有答案