Omnimaga
General Discussion => Technology and Development => Computer Programming => Topic started by: Munchor on May 07, 2011, 08:57:50 am
-
I made a score bot for IRC:
#!/usr/bin/env python
import datetime
import hashlib
import os
import random
import sys
import time
import urllib
from twisted.words.protocols import irc
from twisted.internet import protocol
from twisted.internet import reactor
class 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()
If you say stuff like:
netham45++
It will set netham45's score to what it was +1.
You can also do netham45--.
If you say !score netham45 it will say in a public message netham45's score.
It also won't let you ++ yourself.
The code is quite clean, but for variables' names. There is not a linking function yet (to link usernames). What do you think?
-
Looks nice, didn't try it though.
Good work!
-
Nice work, do you have permission for this (just asking, I think you have though :))
-
does this account for omnom messages (meaning messages prefixed by "<username>")
-
Oh my, I should have mentioned this is not online in omnimaga's channel (#omnimaga). I have not asked permission for that and I have no idea how it would account for user messages in the forums (there is already a website rating for that).
-
***BUMP***
I'd like to know what you think (mainly the poll) so I know if I'll contact an admin.
-
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.
-
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.
Oh yeah that will work no problem :D
-
Honestly, I don't really see much of a point for this. I could definitely see it adding to spam in the chat though.
-
Yeah it should be separate from the forums. However I kinda agree with Art, we already got enough randomness anyway.
-
I mean, UBystand has the same functionality, but have you ever seen it running in #omnomaga? Nope, I only turn it on it #IRP ;) That sort of thing is just a bit spammy =P
-
Honestly, I don't really see much of a point for this. I could definitely see it adding to spam in the chat though.
cemetech has it, and their channel has less spam than ours ;)
there's no proven correlation between the two.
-
Yeah but #cemetech had less spam than us without the bot, so adding it there wasn't too bad. In #omnimaga there's more randomness so imagine how bad it will be if people go random and starts abusing the bot too. And then it gets much harder for admins to stop the sapam if there is too much.
-
I voted no for this, seems like it'd just promote spamming and conflict.
-
Although I like the idea and think it has the potential to work quite well, I voted no because I can imagine users abusing the system and because IRC isn't where we place important updates and posts there is really no need for a respect system. We really just use IRC as a notifier, place for discussions, and randomness.
-
Yeah true. Also, I think two rating systems would get confusing, and I would prefer that rating remains only on posts.
-
Yeah but #cemetech had less spam than us without the bot, so adding it there wasn't too bad. In #omnimaga there's more randomness so imagine how bad it will be if people go random and starts abusing the bot too. And then it gets much harder for admins to stop the sapam if there is too much.
It definitely can get spammy. There're also a lot of junk entries that I go through and clean up. An addition that helps to abate everyone wanting to check all the scores is that you can access the scores online, so if people get overly spammy you can point them there. I think if you include that, you can lessen the abuse. That being said, we do have to be pretty vigilant when it comes to moderating DecBot abuse.
-
Thanks everyone for your opinions. I changed my opinion and will not even ask to upload this at #omnimaga.
-
Ah ok. Yeah I think the issue is that it could get out of control, and since moderators are often busy, it would be hard to stop :<
-
As much as I like Decbot on #cemetech, it'd definitely get abused in #omnimaga. For example, "Lobster" would probably get >9000 ratings in the first 42 hours. And the memes that I'm obviously inserting in here would get inflated respect too. Let's just keep it on the forums.
-
Indeed, and I am sure some people would try to make sure someone's rating remains exactly at 666. Omnimaga in general mostly got younger users since it attracts a lot more newer coders than other ones, so inevitably there are some strange things that are going to happen. :P (no offense intended of course)
-
Even if this is never going to be in #omnimaga, I worked a bit on it:
#!/usr/bin/env python
import datetime
import hashlib
import os
import random
import sys
import time
import urllib
from twisted.words.protocols import irc
from twisted.internet import protocol
from twisted.internet import reactor
class 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 by %s" % (msg.split('++')[0],user)
return
except KeyError:
self.myDict[msg.split('++')[0]] = 1
print "The first +1 for %s by %s" % (msg.split('++')[0],user)
return
if msg[len(msg)-2:] == "--":
try:
self.myDict[msg.split('--')[0]] = self.myDict[msg.split('--')[0]] - 1
print "-1 for %s by %s" % (msg.split('++')[0],user)
return
except:
self.myDict[msg.split('--')[0]] = -1
print "The first -1 for %s by %s" % (msg.split('++')[0],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()
Actually, I just made even more updates:
#!/usr/bin/env python
import datetime
import hashlib
import os
import random
import sys
import time
import urllib
from twisted.words.protocols import irc
from twisted.internet import protocol
from twisted.internet import reactor
class 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 by %s" % (msg.split('++')[0],user)
return
except KeyError:
self.myDict[msg.split('++')[0]] = 1
print "The first +1 for %s by %s" % (msg.split('++')[0],user)
return
elif msg[len(msg)-2:] == "--":
try:
self.myDict[msg.split('--')[0]] = self.myDict[msg.split('--')[0]] - 1
print "-1 for %s by %s" % (msg.split('++')[0],user)
return
except:
self.myDict[msg.split('--')[0]] = -1
print "The first -1 for %s by %s" % (msg.split('++')[0],user)
return
elif msg.split()[0] == '!score':
try:
msgToDisplay=msg.split()[1]+": %s" % str(self.myDict[msg.split()[1]])
self.msg(channel,msgToDisplay)
print "I answered to %s: %s" % (user,msgToDisplay)
return
except KeyError:
msgToDisplay="Non-existing member: %s" % msg.split()[1]
self.msg(channel,msgToDisplay)
print "I answered to %s: Non-existing member: %s" % (user,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()