serveurs = {"acoeur.crans.org" : "acoeur", "irc.crans.org" : "crans"}
return config.logfile_template % (serveurs[serveur])
-def get_filesize():
- """Récupère la taille de ce fichier."""
- return ex("ls -s %s" % (config.thisfile))[1].split()[0]
-
def log(serveur, channel, auteur=None, message=None):
f = open(get_config_logfile(serveur), "a")
if auteur == message == None:
print chain
f.close()
-def is_something(chain, matches, avant=u".*(?:^| )", apres=u"(?:$|\.| |,|;).*", case_sensitive=False, debug=False):
- if case_sensitive:
- chain = unicode(chain, "utf8")
- else:
- chain = unicode(chain, "utf8").lower()
- allmatches = "(" + "|".join(matches) + ")"
- reg = (avant + allmatches + apres).lower()
- o = re.match(reg, chain)
- return o
-
-def is_insult(chain, debug=True):
- return is_something(chain, config.insultes, avant=".*(?:^| |')")
-def is_not_insult(chain):
- chain = unicode(chain, "utf8")
- insult_regexp = u"(" + u"|".join(config.insultes) + u")"
- middle_regexp = u"(une? (?:(?:putain|enfoiré) d(?:e |'))*|)(?:| super )(?: (?:gros|petit|grand|énorme) |)"
- reg = ".*pas %s%s.*" % (middle_regexp, insult_regexp)
- if re.match(reg, chain):
- return True
- else:
- return False
-def is_compliment(chain, debug=True):
- return is_something(chain, config.compliment_triggers, avant=".*(?:^| |')")
-def is_tag(chain):
- return is_something(chain, config.tag_triggers)
-def is_tesla(chain):
- return is_something(chain, config.tesla_triggers, avant=u"^", apres=u"$", debug=True)
-def is_merci(chain):
- return is_something(chain, config.merci_triggers)
-def is_tamere(chain):
- return is_something(chain, config.tamere_triggers)
-def is_bad_action_trigger(chain, pseudo):
- return is_something(chain, config.bad_action_triggers, avant=u"^",
- apres="(?: [a-z]*ment)? %s($|\.| |,|;).*" % (pseudo))
-def is_good_action_trigger(chain, pseudo):
- return is_something(chain, config.good_action_triggers, avant=u"^",
- apres="(?: [a-z]*ment)? %s($|\.| |,|;).*" % (pseudo))
-def is_bonjour(chain):
- return is_something(chain, config.bonjour_triggers, avant=u"^")
-def is_bonne_nuit(chain):
- return is_something(chain, config.bonne_nuit_triggers, avant=u"^")
-def is_pan(chain):
- return re.match(u"^(pan|bim|bang)( .*)?$", unicode(chain, "utf8").lower().strip())
-
-def is_time(conf):
- _, _, _, h, m, s, _, _, _ = time.localtime()
- return (conf[0], 0, 0) < (h, m, s) < (conf[1], 0, 0)
-def is_day():
- return is_time(config.daytime)
-def is_night():
- return is_time(config.nighttime)
-
-
class UnicodeBotError(Exception):
pass
def bot_unicode(chain):
Me rend silencieux sur le channel.""", None],
"noquiet" : [None, """NOQUIET <channel>
Me rend la parole sur le channel.""", None],
- "lost" : [None, """LOST <channel>
- Me fait perdre sur le channel.""", None],
"say" : [None, None, """SAY <channel> <message>
Me fait parler sur le channel."""],
"do" : [None, None, """DO <channel> <action>
serv.nick(become)
log(self.serveur, canal, auteur, message + "[successful]")
- if cmd in ["meur", "meurt", "meurre", "meurres"] and not canal in self.quiet_channels:
- serv.privmsg(canal, '%s: Mourir, impératif, 2ème personne du singulier : "meurs" (de rien)' % (auteur))
elif cmd in ["ping"] and not canal in self.quiet_channels:
serv.privmsg(canal, "%s: pong" % (auteur))
- if is_insult(message) and not canal in self.quiet_channels:
- if is_not_insult(message):
- answer = random.choice(config.compliment_answers)
- for ligne in answer.split("\n"):
- serv.privmsg(canal, "%s: %s" % (auteur, ligne.encode("utf8")))
- else:
- answer = random.choice(config.insultes_answers)
- for ligne in answer.split("\n"):
- serv.privmsg(canal, "%s: %s" % (auteur, ligne.encode("utf8")))
- elif is_compliment(message) and not canal in self.quiet_channels:
- answer = random.choice(config.compliment_answers)
- for ligne in answer.split("\n"):
- serv.privmsg(canal, "%s: %s" % (auteur, ligne.encode("utf8")))
- if is_tesla(message) and not canal in self.quiet_channels:
- l1, l2 = config.tesla_answers, config.tesla_actions
- n1, n2 = len(l1), len(l2)
- i = random.randrange(n1 + n2)
- if i >= n1:
- serv.action(canal, l2[i - n1].encode("utf8"))
- else:
- serv.privmsg(canal, "%s: %s" % (auteur, l1[i].encode("utf8")))
- if is_tamere(message) and not canal in self.quiet_channels:
- answer = random.choice(config.tamere_answers)
- for ligne in answer.split("\n"):
- serv.privmsg(canal, "%s: %s" % (auteur, ligne.encode("utf8")))
- if is_tag(message) and not canal in self.quiet_channels:
- if auteur in self.ops:
- action = random.choice(config.tag_actions)
- serv.action(canal, action.encode("utf8"))
- self.quiet_channels.append(canal)
- else:
- answer = random.choice(config.tag_answers)
- for ligne in answer.split("\n"):
- serv.privmsg(canal, "%s: %s" % (auteur, ligne.encode("utf8")))
- if is_merci(message):
- answer = random.choice(config.merci_answers)
- for ligne in answer.split("\n"):
- serv.privmsg(canal, "%s: %s" % (auteur, ligne.encode("utf8")))
- if is_bonjour(message) and not canal in self.quiet_channels:
- if is_night():
- answer = random.choice(config.night_answers)
- elif is_day():
- answer = random.choice(config.bonjour_answers)
- else:
- answer = random.choice(config.bonsoir_answers)
- serv.privmsg(canal, answer.format(auteur).encode("utf8"))
- if is_bonne_nuit(message) and not canal in self.quiet_channels:
- answer = random.choice(config.bonne_nuit_answers)
- serv.privmsg(canal, answer.format(auteur).encode("utf8"))
else:
if not canal in self.quiet_channels:
- mypseudo = self.nick
- if re.match((u"^(" + u"|".join(config.bonjour_triggers)
- + ur")( {}| all| tout le monde| (à )?tous)(\.| ?!)?$"
- ).format(mypseudo).lower(), message.decode("utf8").strip().lower()):
- answer = random.choice(config.bonjour_answers)
- serv.privmsg(canal, answer.format(auteur).encode("utf8"))
+ pass
def on_action(self, serv, ev):
action = ev.arguments()[0]
return
mypseudo = self.nick
- if is_bad_action_trigger(action, mypseudo) and not channel in self.quiet_channels:
- l1, l2 = config.bad_action_answers, config.bad_action_actions
- n1, n2 = len(l1), len(l2)
- i = random.randrange(n1 + n2)
- if i >= n1:
- serv.action(channel, l2[i - n1].format(auteur).encode("utf8"))
- else:
- serv.privmsg(channel, l1[i].format(auteur).format(auteur).encode("utf8"))
- if is_good_action_trigger(action, mypseudo) and not channel in self.quiet_channels:
- l1, l2 = config.good_action_answers, config.good_action_actions
- n1, n2 = len(l1), len(l2)
- i = random.randrange(n1 + n2)
- if i >= n1:
- serv.action(channel, l2[i - n1].format(auteur).format(auteur).encode("utf8"))
- else:
- serv.privmsg(channel, l1[i].format(auteur).format(auteur).encode("utf8"))
-
def on_kick(self, serv, ev):
auteur = irclib.nm_to_n(ev.source())
channel = ev.target()
log(self.serveur, "%s kické de %s par %s (raison : %s)" % (victime, channel, auteur, raison))
time.sleep(2)
serv.join(channel)
+ return
l1, l2 = config.kick_answers, config.kick_actions
n1, n2 = len(l1), len(l2)
i = random.randrange(n1 + n2)
if __name__ == "__main__":
import sys
if len(sys.argv) == 1:
- print "Usage : skeleton.py <serveur> [--debug]"
+ print "Usage : bbc.py <serveur> [--debug]"
exit(1)
serveur = sys.argv[1]
if "debug" in sys.argv or "--debug" in sys.argv:
debug = False
if "--quiet" in sys.argv:
config.debug_stdout = False
- serveurs = {"a♡" : "acoeur.crans.org", "acoeur" : "acoeur.crans.org", "acoeur.crans.org" : "acoeur.crans.org",
- "irc" : "irc.crans.org", "crans" : "irc.crans.org", "irc.crans.org" : "irc.crans.org"}
+ serveurs = {"irc" : "irc.crans.org", "crans" : "irc.crans.org", "irc.crans.org" : "irc.crans.org"}
try:
serveur = serveurs[serveur]
except KeyError: