|
|
@ -37,6 +37,7 @@ stats = {} # Statistiques sur les messages |
|
|
|
quotes = {} # Citations |
|
|
|
citations = {} #addquote |
|
|
|
bieres = {} # Boissons a offrir |
|
|
|
salons = {} # Boissons a offrir |
|
|
|
welcome = {} # Messages d'accueil des salons |
|
|
|
admins = [] # Admins du bot |
|
|
|
modos = {} # Moderateurs des salons |
|
|
@ -91,6 +92,15 @@ def bieres_read(): |
|
|
|
except: |
|
|
|
bieres = {} |
|
|
|
|
|
|
|
def salons_read(): |
|
|
|
global salons |
|
|
|
try: |
|
|
|
with open("salons", "rb") as fichier: |
|
|
|
loader = pickle.Unpickler(fichier) |
|
|
|
salons = loader.load() |
|
|
|
except: |
|
|
|
salons = {} |
|
|
|
|
|
|
|
def welcome_read(): |
|
|
|
global welcome |
|
|
|
try: |
|
|
@ -138,6 +148,10 @@ def save_obj(): |
|
|
|
with open("bieres", "wb") as fichier: |
|
|
|
saver = pickle.Pickler(fichier) |
|
|
|
saver.dump(bieres) |
|
|
|
if ('salon' in liste_mod): |
|
|
|
with open("salons", "wb") as fichier: |
|
|
|
saver = pickle.Pickler(fichier) |
|
|
|
saver.dump(salons) |
|
|
|
if ('welcome' in liste_mod): |
|
|
|
with open("welcome", "wb") as fichier: |
|
|
|
saver = pickle.Pickler(fichier) |
|
|
@ -1257,7 +1271,7 @@ def quote(room,event): # Gestion des citations |
|
|
|
id = args[1] |
|
|
|
reponse = "Voici la citation supprimée : \n" |
|
|
|
rid = room.room_id |
|
|
|
fame = bieres[rid] |
|
|
|
fame = quotes[rid] |
|
|
|
for cle,valeur in fame.items(): |
|
|
|
if (str(cle[1]) == id): |
|
|
|
del fame[cle[0],cle[1]] |
|
|
@ -1287,6 +1301,88 @@ def quote(room,event): # Gestion des citations |
|
|
|
else: |
|
|
|
msg(room,"Je n'ai pas de citations pour ce salon") |
|
|
|
|
|
|
|
@not_myself |
|
|
|
def salons(room,event): # Gestion des listes de salons recommandes |
|
|
|
global modules |
|
|
|
try: |
|
|
|
rmod = modules[room.room_id, 'salon'] |
|
|
|
except: |
|
|
|
modules[room.room_id, 'salon'] = False |
|
|
|
if (modules[room.room_id, 'salon']): |
|
|
|
global salons |
|
|
|
args = event['content']['body'].split() |
|
|
|
args.pop(0) |
|
|
|
famous = {} |
|
|
|
try: |
|
|
|
famous = salons[room.room_id] |
|
|
|
except: |
|
|
|
famous = {} |
|
|
|
|
|
|
|
if (len(args) > 3 and args[0] == "add"): |
|
|
|
#ajoute un salon recommande |
|
|
|
ref = "" |
|
|
|
desc = "" |
|
|
|
args.pop(0) |
|
|
|
if (args[0] == "desc"): |
|
|
|
args.pop(0) |
|
|
|
ref = "desc" |
|
|
|
desc = " ".join(args) |
|
|
|
else: |
|
|
|
ref = args[0] |
|
|
|
desc = " ".join(args) |
|
|
|
famous[ref] = desc |
|
|
|
salons[room.room_id] = famous |
|
|
|
msg(room,"Ajout du salon " + ref + " : " + desc) |
|
|
|
elif (len(args) > 1 and args[0] == "del"): |
|
|
|
salon = verifPMRoom(room,event) |
|
|
|
lmod = modos[room.room_id] |
|
|
|
if (event['sender'] in admins): |
|
|
|
id = args[1] |
|
|
|
reponse = "Voici le salon supprimé : \n" |
|
|
|
for rid,fame in salons.items(): |
|
|
|
for cle,valeur in fame.items(): |
|
|
|
if (str(cle[0]) == id): |
|
|
|
del fame[cle[0]] |
|
|
|
reponse = reponse + rid + " / " + cle[0] + " : " + valeur + "\n" |
|
|
|
break |
|
|
|
msg(salon,reponse) |
|
|
|
elif (event['sender'] in lmod): |
|
|
|
id = args[1] |
|
|
|
reponse = "Voici le salon supprimé : \n" |
|
|
|
rid = room.room_id |
|
|
|
fame = salons[rid] |
|
|
|
for cle,valeur in fame.items(): |
|
|
|
if (str(cle[0]) == id): |
|
|
|
del fame[cle[0]] |
|
|
|
reponse = reponse + rid + " / " + cle[0] + " : " + valeur + "\n" |
|
|
|
break |
|
|
|
msg(salon,reponse) |
|
|
|
else: |
|
|
|
msg(salon,"Vous n'êtes pas autorisés à supprimer des salons.") |
|
|
|
elif (len(args) > 0): |
|
|
|
# cite un salon precis |
|
|
|
ref = args[0] |
|
|
|
trouve = 0 |
|
|
|
for cle,valeur in famous.items(): |
|
|
|
if (cle[0] == ref): |
|
|
|
msg(salon,cle[0] + " : " + valeur) |
|
|
|
trouve = 1 |
|
|
|
break |
|
|
|
if (trouve == 0): |
|
|
|
msg(room,"Je n'ai pas de salons nomme " + ref) |
|
|
|
else: |
|
|
|
# cite tous les salons |
|
|
|
reponse = "" |
|
|
|
trouve = 0 |
|
|
|
if ("desc" in famous): |
|
|
|
reponse = reponse + famous["desc"] + "\n" |
|
|
|
for cle,valeur in famous.items(): |
|
|
|
if (cle[0] != "desc"): |
|
|
|
reponse = reponse + cle[0] + " : " + valeur + "\n" |
|
|
|
trouve = 1 |
|
|
|
if (trouve == 0): |
|
|
|
msg(room,"Je n'ai pas de salons recommandes pour ce salon") |
|
|
|
|
|
|
|
@not_myself |
|
|
|
def addquote(room,event): # enregistrer les citations mode reponses matrix |
|
|
|
global modules |
|
|
@ -1701,7 +1797,7 @@ def main(): |
|
|
|
USERNAME = "" # Bot's username |
|
|
|
PASSWORD = "" # Bot's password |
|
|
|
SERVER = "" # Matrix server URL |
|
|
|
mods = ["roll", "quote", "biere", "stats", "liste", "horloge", "carte", "card", "cristal", "welcome", "salut", "jdr", "gens", "va"] |
|
|
|
mods = ["roll", "quote", "biere", "stats", "liste", "horloge", "carte", "card", "cristal", "welcome", "salut", "jdr", "gens", "va", "salon"] |
|
|
|
global admins |
|
|
|
if ('AUTH' in config): |
|
|
|
USERNAME = config['AUTH']['username'] # Bot's username |
|
|
@ -1808,6 +1904,12 @@ def main(): |
|
|
|
boisson_handler = MCommandHandler("", boissons, '%') |
|
|
|
bot.add_handler(boisson_handler) |
|
|
|
|
|
|
|
# salons |
|
|
|
if ('salon' in liste_mod): |
|
|
|
salons_read() |
|
|
|
salon_handler = MCommandHandler("salon", salon) |
|
|
|
bot.add_handler(salon_handler) |
|
|
|
|
|
|
|
# Accueil |
|
|
|
if ('welcome' in liste_mod): |
|
|
|
welcome_read() |
|
|
|