#! /usr/bin/env python #-*- encoding: utf-8 -*- # # Bot qui utilise ircbot.py from ircbot import SingleServerIRCBot from irclib import nm_to_n, nm_to_h, irc_lower, ip_numstr_to_quad, ip_quad_to_numstr class TestBot(SingleServerIRCBot): def nice_nick(self): import random prenoms = ["Adolf", "Staline", "Mao", "Boris", "Bjorn", "Eudoxie", "Hyacinthe", "Jean_Philippe", "MrChrist", "Jesus", "Joris", "Ishmael", "Pierre_Henri", "Jose", "Alfonso", "Gerhart", "Hans", "Jorgen"] return prenoms[random.randrange(0, len(prenoms))] def __init__(self, channel, nickname, server, port=6667): nickname = self.nice_nick() SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname, "89.88.158.74") self.channel = channel def on_nicknameinuse(self, c, e): c.nick(self.nice_nick()) def on_welcome(self, c, e): c.privmsg("Q@CServe.quakenet.org", "AUTH delrothbot the_delroth_bot") c.mode(c.get_nickname(), "+x") c.join(self.channel) def on_privmsg(self, c, e): self.do_command(e, e.arguments()[0]) def on_pubmsg(self, c, e): self.parse(e.arguments()[0]) a = e.arguments()[0].split(":", 1) if len(a) > 1 and irc_lower(a[0]) == irc_lower(self.connection.get_nickname()): self.do_command(e, a[1].strip()) return alternate = True def parse(self, msg): UNKNOWN = 0 NEGATION = 1 DTC_WORD = 2 CMB_WORD = 3 CTB_WORD = 4 DEMONSTRATIF = 5 QUESTION_MARK = 6 DOT = 7 if self.alternate: dtc_str = "DTC!" cmb_str = "CLB2 delroth!" ctb_str = "CTB!" self.alternate = not self.alternate else: dtc_str = "DTC !" cmb_str = "CLB2 delroth !" ctb_str = "CTB !" self.alternate = not self.alternate dtc_words = ['où'] cmb_words = ['grand', 'gigantesque', 'immense', 'gros', 'impressionnant', 'lourd', 'voyant', 'beau'] ctb_words = ['petit', 'minuscule', 'microscopique', 'fin', 'pue', 'sale', 'malformé', 'léger', 'moche'] negations = ['pas', "n'est", 'plus'] demonstrs = ['tu', "c'est", 'ça', 'je suis', "t'es"] for txt_phrase in msg.split('.'): mots = txt_phrase.split(' ') phrase = [] for mot in mots: if mot[-1:] == ".": phrase += [DOT] elif mot[-1:] == "?": phrase += [QUESTION_MARK] elif mot in dtc_words: phrase += [DTC_WORD] elif mot in cmb_words: phrase += [CMB_WORD] elif mot in ctb_words: phrase += [CTB_WORD] elif mot in negations: phrase += [NEGATION] elif mot in demonstrs: phrase += [DEMONSTRATIF] else: phrase += [UNKNOWN] print phrase for p in phrase: if p == UNKNOWN: break else: p += 1 if QUESTION_MARK in phrase and DTC_WORD in phrase and len(phrase) < 8: self.connection.privmsg(self.channel, dtc_str) elif not(NEGATION in phrase) and DEMONSTRATIF in phrase and CTB_WORD in phrase and len(phrase) < 8: self.connection.privmsg(self.channel, ctb_str) elif not(NEGATION in phrase) and DEMONSTRATIF in phrase and CMB_WORD in phrase and len(phrase) < 8: self.connection.privmsg(self.channel, cmb_str) def do_command(self, e, cmd): nick = nm_to_n(e.source()) c = self.connection if cmd == "disconnect" and nick == "delroth": self.disconnect() elif cmd == "die" and nick == "delroth": self.die() elif cmd.startswith("say") and nick == "delroth": self.connection.privmsg(self.channel, cmd[4:]) elif cmd == "change nick" and nick == "delroth": c.nick(self.nice_nick()) else: c.notice(nick, "Tu connais la commande " + cmd + " toi ? Pas moi en tout cas, donc si tu veux que je fasse ça, ben va te faire voir DTC !") def main(): import sys if len(sys.argv) < 3: print "Usage: dtcbot [nickname]" sys.exit(1) s = sys.argv[1].split(":", 1) server = s[0] if len(s) == 2: try: port = int(s[1]) except ValueError: print "Error: Erroneous port." sys.exit(1) else: port = 6667 channel = sys.argv[2] if len(sys.argv) == 4: nickname = sys.argv[3] else: nickname = "" bot = TestBot(channel, nickname, server, port) bot.start() if __name__ == "__main__": main()