Exemplo n.º 1
0
class Bot(SingleServerIRCBot):
    def __init__(self, config):
        ircaddr = parse_host_port(config.get('main', 'host'), 6667)
        self.channel = config.get('main', 'channel')
        self.nickname = config.get('main', 'nickname')
        try:
            self.nickpass = config.get('main', 'nickpass')
        except ConfigParser.NoOptionError:
            self.nickpass = None
        try:
            self.needinvite = (config.get('main', 'needinvite') == 'yes')
        except ConfigParser.NoOptionError:
            self.needinvite = False

        SingleServerIRCBot.__init__(self, [ircaddr], self.nickname, self.nickname, 5)
        self.queue = OutputManager(self.connection, .9)
        self.queue.start()

        self.handlers = {}

        def handler_for_key(self, key):
            return lambda c, e: self.execute_handlers(key, c, e)

        for handler in (logbot.Logbot(config, self.queue),
                        beanbot.Beanbot(config, self.queue),
                        decisionbot.Decisionbot(config, self.queue)):
            for props in handler.__dict__, handler.__class__.__dict__:
                for key in props.iterkeys():
                    if not key.startswith('on_'):
                        continue
                    value = getattr(handler, key)
                    if not hasattr(value, '__call__'):
                        continue

                    if not key in self.handlers:
                        # Set up handling for this message
                        self.handlers[key] = []
                        if hasattr(self, key):
                            self.handlers[key].append(getattr(self, key))
                        setattr(self, key, handler_for_key(self, key))

                    # Add new handler for this message
                    self.handlers[key].append(value)

        try:
            self.start()
        except KeyboardInterrupt:
            self.connection.quit("Ctrl-C at console")
        except Exception, e:
            self.connection.quit("%s: %s" % (e.__class__.__name__, e.args))
            raise
Exemplo n.º 2
0
class Bot(SingleServerIRCBot):
  def __init__(self, channel, nickname, nickpass, ircaddr, udpaddr,
      debug=False):
    SingleServerIRCBot.__init__(self, [ircaddr], nickname, nickname, 5)
    self.channel = channel
    # self.nickname is the nickname we _want_. The nickname we actually
    # have at any particular time is c.get_nickname().
    self.nickname = nickname
    self.nickpass = nickpass
    self.debug = debug
    self.queue = OutputManager(self.connection, .9)
    self.queue.start()
    self.inputthread = UDPInput(self, udpaddr)
    self.inputthread.start()
    try:
      self.start()
    except KeyboardInterrupt:
      self.connection.quit("Ctrl-C at console")
      print "Quit IRC."
    except Exception, e:
      self.connection.quit("%s: %s" % (e.__class__.__name__, e.args))
      raise
Exemplo n.º 3
0
    def __init__(self, nick, chan, url):
        """
        Constructeur qui pourrait prendre des paramètres dans un "vrai" programme.
        """
        ircbot.SingleServerIRCBot.__init__(self, [("irc.freenode.net", 6667)],
                                           nick, "IRC bot for Calorine radio")
        self.queue = OutputManager(self.connection, .9)
        self.queue.start()

        self.inputthread = sockinput(self)
        self.inputthread.start()
        self.chan = chan
        self.nick = nick
        self.url = url
Exemplo n.º 4
0
class WolfBot(SingleServerIRCBot):
  GAMESTATE_NONE, GAMESTATE_STARTING, GAMESTATE_RUNNING  = range(3)
  def __init__(self, channel, nickname, nickpass, server, port=defaultPort,
      debug=False):
    SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
    self.channel = channel
    # self.nickname is the nickname we _want_. The nickname we actually
    # have at any particular time is c.get_nickname().
    self.nickname = nickname
    self.nickpass = nickpass
    self.debug = debug
    self.moderation = True
    self._reset_gamedata()
    self.queue = OutputManager(self.connection)
    self.queue.start()
    try:
      self.start()
    except KeyboardInterrupt:
      self.connection.quit("Ctrl-C at console")
      print "Quit IRC."
    except Exception, e:
      self.connection.quit("%s: %s" % (e.__class__.__name__, e.args))
      raise
Exemplo n.º 5
0
class BotCalorine(ircbot.SingleServerIRCBot):

    pl_prefix = ["donne moi du", "allez balance", "vas-y envoi", "gimme",
                 "balance"]

    manage = os.path.join(os.path.dirname(__file__),
                          'calorine',
                          'manage.py')

    def __init__(self, nick, chan, url):
        """
        Constructeur qui pourrait prendre des paramètres dans un "vrai" programme.
        """
        ircbot.SingleServerIRCBot.__init__(self, [("irc.freenode.net", 6667)],
                                           nick, "IRC bot for Calorine radio")
        self.queue = OutputManager(self.connection, .9)
        self.queue.start()

        self.inputthread = sockinput(self)
        self.inputthread.start()
        self.chan = chan
        self.nick = nick
        self.url = url

    def on_welcome(self, serv, event):
        """
        Méthode appelée une fois connecté et identifié.
        Notez qu'on ne peut rejoindre les canaux auparavant.
        """
        syslog.syslog("irc: join %s" % self.chan)
        serv.join(self.chan)
        wmsg = ["yo les baiseaux", "salut les bouseux",
                "coucou les filles", "coucou tout le monde",
                "\o calorine est dans la place !", "Yi ah c'est moi !",
                "kikoo les chouchous", "salut les bouseux",
                "yo gros", "bonjour bonjour les amours"]
        rand = int(random() * 10)
        serv.privmsg(self.chan, wmsg[rand])

    def on_kick(self, serv, event):
        """
        auto rejoin on kick
        """
        serv.join(self.chan)
        serv.privmsg(self.chan, "qui c'est qui qui ma kické, kiki ?")

    def on_pubmsg(self, serv, event):
        """
        Méthode appelée à la réception d'un message
        """
        # Il n'est pas indispensable de passer par des variables
        # Ici elles permettent de clarifier le tout.
        auteur = irclib.nm_to_n(event.source())
        canal = event.target()
        message = event.arguments()[0].lower() # Les insultes sont écrites en minuscules.

        insultes = [" con ", " pute ", " connard ", " salope ", " salop ", " crétin ",
                    "pétasse ", " putain ", " bordel "," chier "]

        for insulte in insultes:
            if insulte in message:
                serv.privmsg(self.chan, "ouh que c'est pas beau les gros mots %s" % auteur)
                break

        if message.startswith(self.nick):
            self.action(message, serv, event)

    def on_join(self, serv, event):
        """
        When someone join
        """
        auteur = irclib.nm_to_n(event.source())

        hello = ["salut %s",
                 "coucou %s",
                 "bonjour %s",
                 "quel plaisir de vous accueillir parmi nous %s",
                 "soit le bienvenu parmi nous %s",
                 "yo mon poto %s",
                 "bisous mouillé %s",
                 "allez %s claque m'en 5",
                 "damned voilà %s",
                 "yo %s",
                 "bisous %s",
                 "kiss %s",
                 "ohoho %s",
                 "en ce jour bénit voici que %s arrive parmi nous",
                 "ça fait plaisir de te voir %s",
                 "Big smack pour %s",
                 "%s hi",
                 "%s est dans la place \o/",
                 "hey %s ça claque ?",
                 "tcho %s, ça farte ?",
                 "%s ça va ou bien",
                 "hey what's up %s",
                 "tss % encore dans le coin",
                 "ah bah te v'la %s",
                 "chut le voilà",
                 "kikoo %s",
                 "te voilà enfin %s"]
        rand = int(random() * len(hello))
        if auteur != self.nick:
            self.speak(hello[rand] % auteur)

    def speak(self, message):
        """
        speak on chan
        """
        self.queue.send(message, self.chan)

    def action(self, message, serv, event):
        msg = message.lower()
        if message.startswith(self.nick):

            command = extract_command(message)

            if command == "cassos":
                self.queue.stop()
                sleep(.7)  # ensure the stop was read
                self.speak("ok je comprends")
                self.inputthread.stop()
                ttclient.trigger()
                sleep(.2)
                serv.disconnect("Au revoir, comme aurait dit VGE")
                sleep(2)
                syslog.syslog("quit on cassos irc message")
                sys.exit(0)
            elif command == "asv":
                self.asv()
            elif command == "onair":
                self.onair()
            elif command == "on air":
                self.onair()
            elif command == "like":
                self.like(irclib.nm_to_n(event.source()))
            elif command == "je kiffe":
                self.like(irclib.nm_to_n(event.source()))
            elif command == "love":
                self.like(irclib.nm_to_n(event.source()))
            elif command == "j'aime":
                self.like(irclib.nm_to_n(event.source()))
            elif command == "hate":
                self.hate(irclib.nm_to_n(event.source()))
            elif command == "caca":
                self.hate(irclib.nm_to_n(event.source()))
            elif command == "beurk":
                self.hate(irclib.nm_to_n(event.source()))
            elif command == "pouah":
                self.hate(irclib.nm_to_n(event.source()))
            elif command == "dislike":
                self.hate(irclib.nm_to_n(event.source()))
            elif command == "help":
                self.help()
            else:
                for plp in self.pl_prefix:
                    if command == plp:
                        self.addpl(message)

    def onair(self):
        """asv command
        """
        conn = '127.0.0.1:11211'
        prefix = "calorine_"
        info = "pas d'info"
        try:
            mmc = memcache.Client([conn], debug=0)
            info = "onair : %s " % (mmc.get("%s:1:onair_full" % prefix))
        except:
            syslog.syslog("error on connecting to memcache %s" % conn)

        self.speak(info)

    def hate(self, nick):
        """Hate a song
        """
        syslog.syslog("action: dislike from %s" % nick)
        res = subprocess.check_output([self.manage, 'ircdislike', nick])
        self.speak(res.rstrip())

    def like(self, nick):
        """Like a song
        """
        syslog.syslog("action: like from %s" % nick)
        res = subprocess.check_output([self.manage, 'irclike', nick])
        self.speak(res.rstrip())

    def help(self):
        """Prints help commands on IRC
        """
        self.speak("prefix the following command by 'nick: '")
        self.speak(" asv : critical information, must sign an NDA to know them")
        self.speak(" cassos : irc bot quit")
        self.speak(" like : I like the song")
        self.speak(" onair : display on air song informations")

    def asv(self):
        """asv command
        """
        self.speak("petit curieux va :-) allez rejoint moi sur %s, canailloute" % self.url)

    def addpl(self, message):
        msg = message.lower()

        syslog.syslog("run %s" % self.manage)
        if 'britney' in msg:
            self.speak("euh, ça non je ne peux pas, Britney ça fait saigner les oreilles, désolé")
            return 0

        if ' dion' in msg:
            self.speak("mais tu sais qu'écouter Céline Dion tue un chaton ?")
            return 0

        if ' biolay' in msg:
            self.speak("pitié pas Biolay")
            return 0

        if ';' in msg:
            self.speak("hum j'aime pas trop les points-virgules")
            return 0

        if '&' in msg:
            self.speak("je n'aime pas les esperluettes d'abord")
            return 0

        for plp in self.pl_prefix:
            if msg.startswith("%s: %s" % (self.nick, plp)):
                index = len(self.nick) + 2 + len(plp) + 1
                lookup = message[index:]
                syslog.syslog("action: lookup %s " % lookup)
                res = subprocess.check_output([self.manage, 'lookup_add_playlist', lookup])
                self.speak(res.rstrip())
Exemplo n.º 6
0
class BotCalorine(ircbot.SingleServerIRCBot):

    pl_prefix = ["je kiffe", "j'aime", "je like", "donne moi du",
                 "allez balance", "vas-y envoi"]

    def __init__(self, nick, chan, url):
        """
        Constructeur qui pourrait prendre des paramètres dans un "vrai" programme.
        """
        ircbot.SingleServerIRCBot.__init__(self, [("irc.freenode.net", 6667)],
                                           nick, "IRC bot for Calorine radio")
        self.queue = OutputManager(self.connection, .9)
        self.queue.start()

        self.inputthread = sockinput(self)
        self.inputthread.start()
        self.chan = chan
        self.nick = nick
        self.url = url

    def on_welcome(self, serv, event):
        """
        Méthode appelée une fois connecté et identifié.
        Notez qu'on ne peut rejoindre les canaux auparavant.
        """
        syslog.syslog("irc: join %s" % self.chan)
        serv.join(self.chan)
        wmsg = ["yo les baiseaux", "salut les bouseux",
                "coucou les filles", "coucou tout le monde",
                "\o calorine est dans la place !", "Yi ah c'est moi !",
                "kikoo les chouchous", "salut les bouseux",
                "yo gros", "bonjour bonjour les amours"]
        rand = int(random() * 10)
        serv.privmsg(self.chan, wmsg[rand])

    def on_kick(self, serv, event):
        """
        auto rejoin on kick
        """
        serv.join(self.chan)
        serv.privmsg(self.chan, "qui c'est qui qui ma kické, kiki ?")

    def on_pubmsg(self, serv, event):
        """
        Méthode appelée à la réception d'un message
        """
        # Il n'est pas indispensable de passer par des variables
        # Ici elles permettent de clarifier le tout.
        auteur = irclib.nm_to_n(event.source())
        canal = event.target()
        message = event.arguments()[0].lower() # Les insultes sont écrites en minuscules.

        insultes = ["con ", "pute", "connard", "salope", "salop", "crétin"]

        for insulte in insultes:
            if insulte in message:
                serv.privmsg(self.chan, "t'es gentil %s mais tu te calmes" % auteur)
                break

        if message.startswith(self.nick):
            self.action(message, serv)

    def on_join(self, serv, event):
        """
        When someone join
        """
        auteur = irclib.nm_to_n(event.source())

        hello = ["salut", "coucou", "bonjour",
                 "yo", "bisous", "kiss",
                 "salut", "Big smack pour", "hi",
                 "yo"]
        rand = int(random() * 10)
        if auteur != self.nick:
            self.speak("%s %s" % (hello[rand], auteur))

    def speak(self, message):
        """
        speak on chan
        """
        self.queue.send(message, self.chan)

    def action(self, message, serv):
        msg = message.lower()
        if message.startswith(self.nick):
            if message == "%s: cassos" % self.nick:
                self.queue.stop()
                sleep(.7)  # ensure the stop was read
                self.speak("ok je comprends")
                self.inputthread.stop()
                ttclient.trigger()
                sleep(.2)
                serv.disconnect("Au revoir, comme aurait dit VGE")
                sleep(2)
                syslog.syslog("quit on cassos irc message")
                sys.exit(0)
            elif msg.startswith("%s: asv" % self.nick):
                self.asv()
            elif msg.startswith("%s: onair" % self.nick):
                self.onair()
            else:
                for plp in self.pl_prefix:
                    if msg.startswith("%s: %s" % (self.nick, plp)):
                        self.addpl(message)

    def onair(self):
        """asv command
        """
        conn = '127.0.0.1:11211'
        prefix = "calorine_"
        info = "pas d'info"
        try:
            mmc = memcache.Client([conn], debug=0)
            info = "onair : %s " % (mmc.get("%s:1:onair_full" % prefix))
        except:
            syslog.syslog("error on connecting to memcache %s" % conn)

        self.speak(info)

    def asv(self):
        """asv command
        """
        self.speak("petit curieux va :-) allez rejoint moi sur %s, canailloute" % self.url)

    def addpl(self, message):
        msg = message.lower()

        manage = os.path.join(os.path.dirname(__file__),
                              'calorine',
                              'manage.py')
        syslog.syslog("run %s" % manage)
        if 'britney' in msg:
            self.speak("euh, ça non je ne peux pas, Britney ça fait saigner les oreilles, désolé")
            return 0

        if ' dion' in msg:
            self.speak("mais tu sais qu'écouter Céline Dion tue un chaton ?")
            return 0

        if ' biolay' in msg:
            self.speak("pitié pas Biolay")
            return 0

        if ';' in msg:
            self.speak("hum j'aime pas trop les points-virgules")
            return 0

        if '&' in msg:
            self.speak("je n'aime pas les esperluettes d'abord")
            return 0

        for plp in self.pl_prefix:
            if msg.startswith("%s: %s" % (self.nick, plp)):
                index = len(self.nick) + 2 + len(plp) + 1
                lookup = message[index:]
                syslog.syslog("action: lookup %s " % lookup)
                res = subprocess.check_output([manage, 'lookup_add_playlist', lookup])
                self.speak(res.rstrip())