def privmsg(self, user, channel, msg): # Quand le bot reçoit un message user = user.split('!', 1)[0] if channel == BOTNICKNAME: # si msg global return self.logger.log(user, channel, _.unicode2ascii(unicode(msg, "UTF-8"))) # sinon log # Verification si on m'envois un send if channel == self.nickname: if channel == BOTNICKNAME or channel == "AUTH": # si msg global return msg = MSGDIRECTSEND self.msg(user, _.unicode2ascii(unicode(msg, "UTF-8"))) return # Vérification si quelqu'un m'ecris sur le chan - reponse con if msg.startswith(self.nickname + ":"): msg = "%s: Je suis un bot tres limite intellectuellement.. " % user self.msg(channel, _.unicode2ascii(unicode(msg, "UTF-8"))) self.logger.log(self.nickname, channel, _.unicode2ascii(unicode(msg, "UTF-8"))) # Commandes a executer if user == BOTOWNERNICKNAME: # COMMANDE: QUITTER if msg.startswith("~quit"): msg = "Bisous, Bye !" self.msg(channel, msg) self.logger.log(self.nickname, channel, _.unicode2ascii(unicode(msg, "UTF-8"))) # on stopper le reacteur et on quitte time.sleep(1) reactor.stop() sys.exit(0) # COMMANDE: TWITTER if msg.startswith("~tweet"): tweet = re.findall(r'"(.*?)"', _.unicode2ascii(unicode(msg, "UTF-8"))) # Si la REGEX retourne un array tweet de 0 on note une erreur et on lui balance la syntaxe # en pleine gueule, sinon on envois le tout a l'API twit. if len(tweet) == 1: api = twitter.Api(username = TWITUSERNAME, password = TWITPASSWORD) status = api.PostUpdate(tweet[0]) self.msg(channel, "%s : %s" % (TWITMSGSENT, tweet[0])) self.logger.log(self.nickname, channel, "%s : %s" % (TWITMSGSENT, tweet[0])) else: msg = "%s: Je n'ai pas compris, la syntaxe: ~tweet \"mon texte\"" % user self.msg(channel, _.unicode2ascii(unicode(msg, "UTF-8"))) self.logger.log(self.nickname, channel, _.unicode2ascii(unicode(msg, "UTF-8"))) # COMMANDE: ABOIS if msg.startswith("~abois"): msg = "Wof, wof !" self.msg(channel, _.unicode2ascii(unicode(msg, "UTF-8"))) self.logger.log(self.nickname, channel, _.unicode2ascii(unicode(msg, "UTF-8")))
def irc_NICK(self, prefix, params): # Quand quelqu'un change son pseudo old_nick = prefix.split('!')[0] new_nick = params[0] self.logger.log(self.nickname, self.factory.channel, _.unicode2ascii("%s est maintenant connu comme %s" % (old_nick, new_nick)))
def action(self, user, channel, msg): # Quand quelqu'un affectue une action on rajoute une * en tete du msg dans le log user = user.split("!", 1)[0] self.logger.log(user, channel, _.unicode2ascii(unicode(msg, "UTF-8")))