From: Vincent Le Gallic Date: Thu, 17 May 2012 22:43:06 +0000 (+0200) Subject: Maintenant quand on matche un truc, on renvoie le matching object X-Git-Url: http://gitweb.pimeys.fr/?p=bots%2Fbasile.git;a=commitdiff_plain;h=5c0de884696330bf237fdec5dcd1fdf370f53dce Maintenant quand on matche un truc, on renvoie le matching object pour l'instant ça sert que pour "gros" --- diff --git a/basile.py b/basile.py index 6f30650..e456eb3 100755 --- a/basile.py +++ b/basile.py @@ -58,7 +58,7 @@ u"Si tu allais voir sur un autre chan si j'y suis ?", u"Permets-moi de te retourner le compliment.", u"Mais je ne te permets pas !"] -config_gros=[u"gros"] +config_gros=[u"gros",u"énorme",u"lourd"] config_buffer_fail_answers=["haha !","You type like you drive","encore un effort ;)"] @@ -201,16 +201,15 @@ def login_NK(username,password,typ="bdd"): return json.loads(out),sock -def is_something(chain,matches,avant=u".*(^| )",apres=u"($|\.| |,|;).*",case_sensitive=False,debug=False): +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() - if re.match(reg,chain): - return True - return False + o=re.match(reg,chain) + return o def is_insult(chain,debug=True): return is_something(chain,config_insultes,avant=".*(^| |')") @@ -759,9 +758,10 @@ class Basile(ircbot.SingleServerIRCBot): answer=random.choice(config_insultes_answers) for ligne in answer.split("\n"): serv.privmsg(canal,"%s: %s"%(auteur,ligne.encode("utf8"))) - if is_gros(message) and not canal in self.quiet_channels: + gros_match=is_gros(message) + if gros_match and not canal in self.quiet_channels: taille=get_filesize() - answer=u"Mais non, je ne suis pas gros, %sKo tout au plus…"%(taille) + answer=u"Mais non, je ne suis pas %s, %sKo tout au plus…"%(gros_match.groups()[0],taille) serv.privmsg(canal,"%s: %s"%(auteur,answer.encode("utf8"))) if is_tesla(message) and not canal in self.quiet_channels: l1,l2=config_tesla_answers,config_tesla_actions