0 Members and 2 Guests are viewing this topic.
#!/usr/bin/env pythonimport datetimeimport hashlibimport osimport randomimport sysimport timeimport urllibfrom twisted.words.protocols import ircfrom twisted.internet import protocolfrom twisted.internet import reactorclass MyBot(irc.IRCClient): def _get_nickname(self): return self.factory.nickname nickname = property(_get_nickname) def signedOn(self): self.join(self.factory.channel) def joined(self, channel): print "*** Joined %s" % channel self.myDict = {} def privmsg(self, user, channel, msg): user = user.split('!')[0] if msg[len(msg)-2:] == "++": if msg.split('++')[0] == user: self.msg(channel,"You can't plus yourself") return try: self.myDict[msg.split('++')[0]] += 1 print "+1 for %s" % user return except KeyError: self.myDict[msg.split('++')[0]] = 1 print "The first +1 for %s" % user return if msg[len(msg)-2:] == "--": try: self.myDict[msg.split('--')[0]] = self.myDict[msg.split('--')[0]] - 1 print "-1 for "+user return except: self.myDict[msg.split('--')[0]] = -1 print "The first -1 for %s" % user return if msg.split()[0] == '!score': try: msgToDisplay = msg.split()[1] + ": " + str(self.myDict[msg.split()[1]]) self.msg(channel,msgToDisplay) print "I answered to %s: %s" % (user,msgToDisplay) return except KeyError: self.msg(channel,"Non-existing member: %s" % msg.split()[1]) print "Non-existing member: %s" % msg.split()[1]class MyBotFactory(protocol.ClientFactory): protocol = MyBot def __init__(self, channel, nickname='scoreBot'): self.channel = channel self.nickname = nickname def clientConnectionLost(self, connector, reason): print "Lost connection (%s), reconnecting." % (reason,) connector.connect() def clientConnectionFailed(self, connector, reason): print "Could not connect: %s" % (reason,)def main(): network = 'irc.freenode.net' reactor.connectTCP(network, 6667, MyBotFactory('#python-forum')) reactor.run()if __name__ == "__main__": main()
netham45++
I am aware that it is not yet in the channel, but if it is going to be in the channel, then it should account for users posting through omnom. That's all I was saying.
Honestly, I don't really see much of a point for this. I could definitely see it adding to spam in the chat though.