Browse Source

test addquote

master
Nemesis 6 years ago
parent
commit
1b39f25eb5
  1. 53
      asmodee.py

53
asmodee.py

@ -35,6 +35,7 @@ bot = None
clock = {} # horloges pbta
stats = {} # Statistiques sur les messages
quotes = {} # Citations
citations = {} #addquote
bieres = {} # Boissons a offrir
welcome = {} # Messages d'accueil des salons
admins = [] # Admins du bot
@ -70,6 +71,16 @@ def quotes_read():
except:
quotes = {}
def citations_read():
global citations
try:
with open("citations", "rb") as fichier:
loader = pickle.Unpickler(fichier)
citations = loader.load()
except:
citations = {}
def bieres_read():
global bieres
try:
@ -119,6 +130,9 @@ def save_obj():
with open("quotes", "wb") as fichier:
saver = pickle.Pickler(fichier)
saver.dump(quotes)
with open("citations", "wb") as fichier:
saver = pickle.Pickler(fichier)
saver.dump(citations)
if ('biere' in liste_mod):
with open("bieres", "wb") as fichier:
saver = pickle.Pickler(fichier)
@ -1243,7 +1257,43 @@ def quote(room,event): # Gestion des citations
msg(room,"Je n'ai pas de citations pour ce salon")
def addquote(room,event):
room.send_text(json.dumps(event['content']))
global citations
content = event['content']
if len(json.dumps(content) > 420):
# Enlève la commande de la citation
try:
content['body'] = string.replace(content['body'],"\naddquote", "")
except:
print("erreur body " + json.dumps(content))
try:
content['formatted_body'] = string.replace(content['formatted_body'], "<p>addquote</p>\n", "")
content['formatted_body'] = string.replace(content['formatted_body'], "addquote", "")
except:
print("erreur formatted_body " + json.dumps(content))
# Récupération de l'auteur
auteur = "Un nain connu"
match = re.search(r"<(\w@\w:\w)>", content['body'])
if match:
auteur = match.group(1)
# Id
tps = datetime.now().microsecond
# récupérations des citations du salon
famous = {}
try:
famous = citations[room.room_id]
except:
famous = {}
# enregistrement de la citation
famous[auteur,tps] = content
quotes[room.room_id] = famous
msg(room,"Ajout de la citation de " + auteur + ":")
bot.client.api.send_message_event(room.room_id, 'm.room.message', content, None, None)
def biere(room,event): # Gestion des boissons
global modules
@ -1656,6 +1706,7 @@ def main():
quotes_read()
quote_handler = MCommandHandler("quote", quote)
bot.add_handler(quote_handler)
citations_read()
addquote_handler = MEndHandler("addquote", addquote)
bot.add_handler(addquote_handler)

Loading…
Cancel
Save