Author Topic: IRC Score Bot  (Read 8389 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
IRC Score Bot
« on: May 07, 2011, 08:57:50 am »
I made a score bot for IRC:

Code: [Select]
#!/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:

Code: [Select]
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?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: IRC Score Bot
« Reply #1 on: May 07, 2011, 09:37:43 am »
Looks nice, didn't try it though.

Good work!

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: IRC Score Bot
« Reply #2 on: May 07, 2011, 09:53:59 am »
Nice work, do you have permission for this (just asking, I think you have though :))
I'm not a nerd but I pretend:

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: IRC Score Bot
« Reply #3 on: May 07, 2011, 09:56:24 am »
does this account for omnom messages (meaning messages prefixed by "<username>")
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: IRC Score Bot
« Reply #4 on: May 07, 2011, 10:40:41 am »
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).

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: IRC Score Bot
« Reply #5 on: May 08, 2011, 08:43:13 am »
***BUMP***

I'd like to know what you think (mainly the poll) so I know if I'll contact an admin.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: IRC Score Bot
« Reply #6 on: May 09, 2011, 08:12:30 am »
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.
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: IRC Score Bot
« Reply #7 on: May 09, 2011, 08:20:54 am »
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

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: IRC Score Bot
« Reply #8 on: May 09, 2011, 08:49:08 am »
Honestly, I don't really see much of a point for this. I could definitely see it adding to spam in the chat though.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: IRC Score Bot
« Reply #9 on: May 09, 2011, 08:19:10 pm »
Yeah it should be separate from the forums. However I kinda agree with Art, we already got enough randomness anyway.

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: IRC Score Bot
« Reply #10 on: May 09, 2011, 08:21:38 pm »
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
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Ashbad

  • Guest
Re: IRC Score Bot
« Reply #11 on: May 09, 2011, 08:23:55 pm »
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.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: IRC Score Bot
« Reply #12 on: May 09, 2011, 08:25:49 pm »
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.

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: IRC Score Bot
« Reply #13 on: May 09, 2011, 08:50:14 pm »
I voted no for this, seems like it'd just promote spamming and conflict.
Omnimaga Admin

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: IRC Score Bot
« Reply #14 on: May 09, 2011, 08:54:37 pm »
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.

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)