From: Vincent Le Gallic Date: Sun, 5 Apr 2015 17:03:50 +0000 (+0200) Subject: more PEP8 (oubli de " - " et " + ") X-Git-Url: http://gitweb.pimeys.fr/?a=commitdiff_plain;h=a6f2ea603edf67961ef6624030d7ffa999d2ff02;p=bots%2Fskeleton.git more PEP8 (oubli de " - " et " + ") --- diff --git a/skeleton.py b/skeleton.py index 8511c93..4ddf64a 100755 --- a/skeleton.py +++ b/skeleton.py @@ -33,7 +33,7 @@ def log(serveur, channel, auteur=None, message=None): chain = "%s %s" % (time.strftime("%F %T"), channel) else: chain = "%s [%s:%s] %s" % (time.strftime("%F %T"), channel, auteur, message) - f.write(chain+"\n") + f.write(chain + "\n") if config.debug_stdout: print chain f.close() @@ -43,8 +43,8 @@ def is_something(chain, matches, avant=u".*(?:^| )", apres=u"(?:$|\.| |,|;).*", chain = unicode(chain, "utf8") else: chain = unicode(chain, "utf8").lower() - allmatches = "("+"|".join(matches)+")" - reg = (avant+allmatches+apres).lower() + allmatches = "(" + "|".join(matches) + ")" + reg = (avant + allmatches + apres).lower() o = re.match(reg, chain) return o @@ -52,7 +52,7 @@ 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")" + 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): @@ -101,13 +101,13 @@ def bot_unicode(chain): class Skeleton(ircbot.SingleServerIRCBot): def __init__(self, serveur, debug=False): - temporary_pseudo = config.irc_pseudo+str(random.randrange(10000, 100000)) + temporary_pseudo = config.irc_pseudo + str(random.randrange(10000, 100000)) ircbot.SingleServerIRCBot.__init__(self, [(serveur, 6667)], temporary_pseudo, "Ceci est l'ircname du bot", 10) self.debug = debug self.serveur = serveur self.overops = config.overops - self.ops = self.overops+config.ops + self.ops = self.overops + config.ops self.chanlist = config.chanlist self.stay_channels = config.stay_channels self.quiet_channels = config.quiet_channels @@ -135,7 +135,7 @@ class Skeleton(ircbot.SingleServerIRCBot): pseudo = self.nick size = len(pseudo) if message[:size] == pseudo and len(message)>size and message[size] == ":": - return (True, message[size+1:].lstrip(" ")) + return (True, message[size + 1:].lstrip(" ")) else: return (False, message) @@ -196,12 +196,12 @@ class Skeleton(ircbot.SingleServerIRCBot): helpmsg = helpmsgs[0] if op and helpmsgs[1]: if helpmsg: - helpmsg += "\n"+helpmsgs[1] + helpmsg += "\n" + helpmsgs[1] else: helpmsg = helpmsgs[1] if overop and helpmsgs[2]: if helpmsg: - helpmsg += "\n"+helpmsgs[2] + helpmsg += "\n" + helpmsgs[2] else: helpmsg = helpmsgs[2] for ligne in helpmsg.split("\n"): @@ -214,10 +214,10 @@ class Skeleton(ircbot.SingleServerIRCBot): else: serv.join(message[1]) self.chanlist.append(message[1]) - serv.privmsg(auteur, "Channels : "+" ".join(self.chanlist)) + serv.privmsg(auteur, "Channels : " + " ".join(self.chanlist)) log(self.serveur, "priv", auteur, " ".join(message)) else: - serv.privmsg(auteur, "Channels : "+" ".join(self.chanlist)) + serv.privmsg(auteur, "Channels : " + " ".join(self.chanlist)) else: notunderstood = True elif cmd == "leave": @@ -226,10 +226,10 @@ class Skeleton(ircbot.SingleServerIRCBot): if not (message[1] in self.stay_channels) or auteur in self.overops: self.quitter(message[1], " ".join(message[2:])) self.chanlist.remove(message[1]) - log(self.serveur, "priv", auteur, " ".join(message)+"[successful]") + log(self.serveur, "priv", auteur, " ".join(message) + "[successful]") else: serv.privmsg(auteur, "Non, je reste !") - log(self.serveur, "priv", auteur, " ".join(message)+"[failed]") + log(self.serveur, "priv", auteur, " ".join(message) + "[failed]") else: serv.privmsg(auteur, "Je ne suis pas sur %s" % (message[1])) else: @@ -238,32 +238,32 @@ class Skeleton(ircbot.SingleServerIRCBot): if auteur in self.overops: if len(message)>1: if message[1] in self.stay_channels: - log(self.serveur, "priv", auteur, " ".join(message)+"[failed]") + log(self.serveur, "priv", auteur, " ".join(message) + "[failed]") serv.privmsg(auteur, "Je stay déjà sur %s." % (message[1])) else: - log(self.serveur, "priv", auteur, " ".join(message)+"[successful]") + log(self.serveur, "priv", auteur, " ".join(message) + "[successful]") self.stay_channels.append(message[1]) - serv.privmsg(auteur, "Stay channels : "+" ".join(self.stay_channels)) + serv.privmsg(auteur, "Stay channels : " + " ".join(self.stay_channels)) else: - serv.privmsg(auteur, "Stay channels : "+" ".join(self.stay_channels)) + serv.privmsg(auteur, "Stay channels : " + " ".join(self.stay_channels)) else: notunderstood = True elif cmd == "nostay": if auteur in self.overops: if len(message)>1: if message[1] in self.stay_channels: - log(self.serveur, "priv", auteur, " ".join(message)+"[successful]") + log(self.serveur, "priv", auteur, " ".join(message) + "[successful]") self.stay_channels.remove(message[1]) - serv.privmsg(auteur, "Stay channels : "+" ".join(self.stay_channels)) + serv.privmsg(auteur, "Stay channels : " + " ".join(self.stay_channels)) else: - log(self.serveur, "priv", auteur, " ".join(message)+"[failed]") + log(self.serveur, "priv", auteur, " ".join(message) + "[failed]") serv.privmsg(auteur, "Je ne stay pas sur %s." % (message[1])) else: notunderstood = True elif cmd == "die": if auteur in self.overops: - log(self.serveur, "priv", auteur, " ".join(message)+"[successful]") + log(self.serveur, "priv", auteur, " ".join(message) + "[successful]") self.mourir() else: notunderstood = True @@ -272,13 +272,13 @@ class Skeleton(ircbot.SingleServerIRCBot): if len(message)>1: if message[1] in self.quiet_channels: serv.privmsg(auteur, "Je me la ferme déjà sur %s" % (message[1])) - log(self.serveur, "priv", auteur, " ".join(message)+"[failed]") + log(self.serveur, "priv", auteur, " ".join(message) + "[failed]") else: self.quiet_channels.append(message[1]) - serv.privmsg(auteur, "Quiet channels : "+" ".join(self.quiet_channels)) - log(self.serveur, "priv", auteur, " ".join(message)+"[successful]") + serv.privmsg(auteur, "Quiet channels : " + " ".join(self.quiet_channels)) + log(self.serveur, "priv", auteur, " ".join(message) + "[successful]") else: - serv.privmsg(auteur, "Quiet channels : "+" ".join(self.quiet_channels)) + serv.privmsg(auteur, "Quiet channels : " + " ".join(self.quiet_channels)) else: notunderstood = True elif cmd == "noquiet": @@ -286,11 +286,11 @@ class Skeleton(ircbot.SingleServerIRCBot): if len(message)>1: if message[1] in self.quiet_channels: self.quiet_channels.remove(message[1]) - serv.privmsg(auteur, "Quiet channels : "+" ".join(self.quiet_channels)) - log(self.serveur, "priv", auteur, " ".join(message)+"[successful]") + serv.privmsg(auteur, "Quiet channels : " + " ".join(self.quiet_channels)) + log(self.serveur, "priv", auteur, " ".join(message) + "[successful]") else: serv.privmsg(auteur, "Je ne me la ferme pas sur %s." % (message[1])) - log(self.serveur, "priv", auteur, " ".join(message)+"[failed]") + log(self.serveur, "priv", auteur, " ".join(message) + "[failed]") else: notunderstood = True elif cmd == "say": @@ -351,28 +351,28 @@ class Skeleton(ircbot.SingleServerIRCBot): args = "" if cmd in ["meurs", "die", "crève"]: if auteur in self.overops: - log(self.serveur, canal, auteur, message+"[successful]") + log(self.serveur, canal, auteur, message + "[successful]") self.mourir() else: serv.privmsg(canal, ("%s: %s" % (auteur, random.choice(config.quit_fail_messages))).encode("utf8")) - log(self.serveur, canal, auteur, message+"[failed]") + log(self.serveur, canal, auteur, message + "[failed]") elif cmd in ["part", "leave", "dégage", "va-t-en", "tut'tiresailleurs, c'estmesgalets"]: if auteur in self.ops and (not (canal in self.stay_channels) or auteur in self.overops): self.quitter(canal) - log(self.serveur, canal, auteur, message+"[successful]") + log(self.serveur, canal, auteur, message + "[successful]") if canal in self.chanlist: self.chanlist.remove(canal) else: serv.privmsg(canal, ("%s: %s" % (auteur, random.choice(config.leave_fail_messages))).encode("utf8")) - log(self.serveur, canal, auteur, message+"[failed]") + log(self.serveur, canal, auteur, message + "[failed]") elif cmd in ["deviens", "pseudo"]: if auteur in self.ops: become = args serv.nick(become) - log(self.serveur, canal, auteur, message+"[successful]") + 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)) @@ -394,9 +394,9 @@ class Skeleton(ircbot.SingleServerIRCBot): 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) + i = random.randrange(n1 + n2) if i >= n1: - serv.action(canal, l2[i-n1].encode("utf8")) + 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: @@ -430,8 +430,8 @@ class Skeleton(ircbot.SingleServerIRCBot): 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)(\.| ?!)?$" + 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")) @@ -451,17 +451,17 @@ class Skeleton(ircbot.SingleServerIRCBot): 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) + i = random.randrange(n1 + n2) if i >= n1: - serv.action(channel, l2[i-n1].format(auteur).encode("utf8")) + 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) + i = random.randrange(n1 + n2) if i >= n1: - serv.action(channel, l2[i-n1].format(auteur).format(auteur).encode("utf8")) + serv.action(channel, l2[i - n1].format(auteur).format(auteur).encode("utf8")) else: serv.privmsg(channel, l1[i].format(auteur).format(auteur).encode("utf8")) @@ -476,9 +476,9 @@ class Skeleton(ircbot.SingleServerIRCBot): serv.join(channel) l1, l2 = config.kick_answers, config.kick_actions n1, n2 = len(l1), len(l2) - i = random.randrange(n1+n2) + i = random.randrange(n1 + n2) if i >= n1: - serv.action(channel, l2[i-n1].format(auteur).encode("utf8")) + serv.action(channel, l2[i - n1].format(auteur).encode("utf8")) else: serv.privmsg(channel, l1[i].format(auteur).encode("utf8"))