Sélectionner une révision Git
nardco.py 10,76 Kio
# -*- coding: utf8 -*-
import irclib
import ircbot
import random
import time
import module_red as red
import rateau
from fuzzywuzzy import fuzz
# import rateau
def couper(pseudo):
return pseudo.split("!")[0]
def aram():
Champ = [" Aatrox ", " Ahri ", " Akali ", " Alistar ", " Amumu ", " Anivia ", " Annie ", " Ashe ", " Azir ",
" Bard ", " Blitzcrank ", " Brand ", " Braum ", " Caitlyn ", " Cassiopeia ", " Cho'Gath ", " Corki ",
" Darius ", " Diana ", " Dr.Mundo ", " Draven ", " Ekko ", " Elise ", " Evelynn ", " Ezreal ",
" Fiddlesticks ", " Fiora ", " Fizz ", " Galio ", " Gangplank ", " Garen ", " Gnar ", " Gragas ",
" Graves ", " Hecarim ", " Heimerdinger ", " Irelia ", " Janna ", " Jarvan IV ", " Jayce ", " Jax ",
" Jinx ", " Kalista ", " Karma ", " Karthus ", " Kassadin ", " Katarina ", " Kayle ", " Kennen ",
" Kha'Zix", " Kog'Maw ", " LeBlanc ", " Lee Sin ", " Leona ", " Lissandra ", " Lucian ", " Lulu ", " Lux ",
" Maître Yi ", " Malphite ", " Malzahar ", " Maokai ", " Miss Fortune ", " Mordekaiser ", " Morgana ",
" Nami ", " Nasus ", " Nautilus ", " Nidalee ", " Nocturne ", " Nunu ", " Olaf ", " Orianna ",
" Pantheon ", " Poppy ", " Quinn ", " Rammus ", " Rek'Sai ", " Renekton ", " Rengar ", " Riven ",
" Rumble ", " Ryze ", " Sejuani ", " Shaco ", " Shen ", " Shyvana ", " Singed ", " Sion ", " Sivir ",
" Skarner ", " Sona ", " Soraka ", " Swain ", " Syndra ", " Tahm Kench ", " Talon ", " Taric ", " Teemo ",
" Thresh ", " Tristana ", " Trundle ", " Tryndamere ", " Twisted Fate ", " Twitch ", " Udyr ", " Urgot ",
" Varus ", " Vayne ", " Veigar ", " Vel'Koz ", " Vi ", " Viktor ", " Vladimir ", " Volibear ", " Warwick ",
" Wukong ", " Xerath ", " Xin Zhao ", " Yasuo ", " Yorick ", " Zac ", " Zed ", " Ziggs ", " Zilean ",
" Zyra"]
return Champ[random.randint(0, len(Champ) - 1)]
global pour
pour = []
global suple
suple = -1
global cmdCarac
cmdCarac = "$"
def isCommande(string):
global cmdCarac
return string[0] == cmdCarac
class Boooob(ircbot.SingleServerIRCBot):
def __init__(self):
ircbot.SingleServerIRCBot.__init__(self, [("irc.iiens.net", 6667)], "nardco", "Je suis un bot")
self.temps = 0
self.reddit_temps = 0
self.fichier_reddit = "canaux_reddit.txt"
self.clever = -1
#
def on_welcome(self, serv, ev):
serv.join("#nardco")
serv.join("#fokontest")
serv.join("#Titch")
# serv.join("#gynecoloc")
serv.privmsg("NickServ", "IDENTIFY MotDePasse") # rejoint #nardco à sa connexion
#
def on_join(self, serv, ev): # Quand qq entre dans le chann, le bot inclus
auteur = str(irclib.nm_to_n(ev.source()))
canal = ev.target()
def on_privmsg(self, serv, ev): # msg privé
personne = ev.source()
canal = ""
if "tichadou" in personne:
msg = ev.arguments()[0]
msg = msg.split(" ")
a = 0
for f in msg:
a = a + 1
if f[0] == "#":
canal = f
msg.pop(a - 1)
break
msg = " ".join(msg)
try:
serv.privmsg(canal, msg)
except:
serv.privmsg("#nardco", "probleeeeme")
def on_invite(self, serv, ev):
personne = ev.source()
canal = ev.arguments()[0]
serv.privmsg("Titch", couper(personne) + " m'a invité sur " + canal)
serv.join(canal)
def on_kick(self, serv, ev):
serv.join("#nardco")
print("kick")
personne = ev.source()
personne = couper(personne)
canal = ev.target()
if canal == "#Titch" and personne != "Titch" :
serv.mode(canal, "-o " + personne)
def on_pubmsg(self, serv, ev): # quand qq ecrit dans le chat
global suple
global cmdCarac
canal = ev.target()
personne = ev.source()
personne = couper(personne)
message = ev.arguments()[0]
message = message.lower() # Passe le message en minuscules
split = message.split(" ")
if "op pls" in message or "op plz" in message :
serv.mode(canal, "+o "+personne)
if 'nardco' in split[0] and ' ou ' in message :
splt = split[1:]
idx = splt.index("ou")
choice = random.randint(0,1)
if choice == 0 :
res = splt[:idx]
else :
if '?' in splt[-1] :
res = splt[idx+1:-1]
else :
res = splt[idx+1:]
serv.privmsg(canal, ' '.join(res)+ "!")
# lol of legends
if " aram " in message:
people = ["Jara", "Nami"]
if personne in people:
if "Jara" in personne:
serv.privmsg(canal, "TOURBILOL DEBILE MOUHAHAHA")
if "Nami" in personne:
serv.privmsg(canal, "Non Nami, ton main n'est pas op ! <3")
else:
serv.privmsg(canal, "A l'evidence," + aram() + "est totalement op.")
# les lignes suivantes sont pour le lol
if "Titch" in personne and "tg" in message:
serv.privmsg(canal, "Oui maitre...")
suple = -1
if "Titch" in personne and "openbar" in message:
serv.privmsg(canal, "OPEN BAAAAAAR")
suple = 1
if "souple" in message and suple == 1:
serv.privmsg(canal, "et fruité")
if "fruité" in message and suple == 1:
serv.privmsg(canal, "et gouleyant")
if "gouleyant" in message and suple == 1:
serv.privmsg(canal, "et souple")
if suple == 1 and ("dur" in message or "long" in message or "court" in message or "molle" in message):
serv.privmsg(canal, "Comme ta bite " + personne + "! ")
if suple == 1:
if "aucun lien" in message:
serv.privmsg(canal, "Je suis fils unique...")
# fonctions de deplacement dans les chann
if "Titch" in personne and "goto" in message and "nardco" in message:
f = 0
for f in range(len(message) - 4):
if message[f:f + 4] == "goto":
serv.join("#" + message[f + 5:])
break
if "Titch" in personne and "leave" in message and "nardco" in message:
serv.part(canal)
# REDDIT // A COMPLETER
if isCommande(message):
args = message[1:].split(" ")
cmd = args[0]
if cmd == "help":
if len(message.split(" ")) > 1:
if "reddit" in message.split(" ")[1]:
serv.privmsg(
canal,
"Commandes : {0}reddit <sub> ; {0}addsub <sub> ; {0}delsub <sub> ; {0}getsub . (getsub renvoie des infos sur tous les subs enregistrés pour le chann) ".format(cmdCarac))
else:
serv.privmsg(canal,
"Commandes disponibles : {0}help reddit , sinon, tentez de dire 'op plz' ...".format(cmdCarac))
if cmd == "rateau" :
serv.privmsg(canal, "{0} : {1}".format(personne, rateau.getRateau())
if cmd == "getsub":
res = red.get_new(self.fichier_reddit, canal)
for f in res:
serv.privmsg(canal, f)
if cmd == "sub":
bd = open(self.fichier_reddit, "r")
for f in bd:
try:
if canal == f.split("|")[0]:
serv.privmsg(canal, "Liste des subs pour " + canal + " : " + f.split("|")[1])
except:
pass
if cmd == "delsub":
sub = message.split(" ")[1]
bd = open(self.fichier_reddit, "r")
rem = 0
tmp = []
for f in bd:
tmp.append(f)
try:
if sub in f.split("|")[1] and canal == f.split("|")[0]:
rem = 1
except:
pass
bd.close()
if rem == 1:
bd = open(self.fichier_reddit, "w")
for f in tmp:
if canal == f.split("|")[0]:
h = f.split("|")[1]
h = h.split(",")
h.remove(sub)
g = f.split("|")[0] + "|" + ",".join(h)
else:
g = f
bd.write(g)
serv.privmsg(canal, "sub : " + sub + " enlevé de la bd pour " + canal)
else:
serv.privmsg(canal, "Erreur, le sub n'est pas dans la bd")
if cmd == "addsub":
sub = message.split(" ")[1]
bd = open(self.fichier_reddit, "r")
add = 1
tmp = []
for f in bd:
tmp.append(f) # On ajoute la ligne -> tmpt est une image de la bd
try:
if sub in f.split("|")[1] and canal == f.split("|")[0]:
add = 0
except:
pass
bd.close()
if add == 1:
canalok = 0
bd = open(self.fichier_reddit, "w")
for f in tmp:
if canal == f.split("|")[0]:
g = f + sub + ","
canalok = 1
else:
g = f
bd.write(g)
if canalok == 0:
bd.write("\n" + canal + "|" + sub + ",")
bd.close()
serv.privmsg(canal, "Subreddit : " + sub + " ajouté a la bd pour " + canal)
else:
serv.privmsg(canal, "Subreddit deja dans la bd...")
if fuzz.ratio(cmd, "reddit") > 80 :
if time.time() - self.reddit_temps > 10:
self.reddit_temps = time.time()
try:
tmp = red.joke(message.split(" ")[1])
except:
tmp = red.joke()
try:
for f in tmp:
serv.privmsg(canal, f)
time.sleep(0.5)
time.sleep(1)
except:
serv.privmsg(canal, "oups, c'est cassé...")
else:
serv.privmsg(canal, personne + ": Merci de patienter :)")
if __name__ == "__main__":
Boooob().start()