generated from Nemesis/Exemple
showquote
This commit is contained in:
parent
45c52b5ee0
commit
db67536611
1 changed files with 83 additions and 36 deletions
57
asmodee.py
57
asmodee.py
|
@ -248,8 +248,11 @@ class Parser: #Pour parser la ligne de commande
|
|||
return True
|
||||
return False
|
||||
|
||||
def msg(room,msg):
|
||||
def msg(room,msg,content=False):
|
||||
try:
|
||||
if content:
|
||||
bot.client.api.send_message_event(room.room_id, 'm.room.message', msg, None, None)
|
||||
else:
|
||||
room.send_text(msg)
|
||||
except:
|
||||
room.send_text("Impossible d'envoyer le message")
|
||||
|
@ -802,9 +805,9 @@ def rollTypePoint(): # Parser le nombre de faces du dé
|
|||
parser.arg["error"] = True
|
||||
|
||||
|
||||
def reponses(room, phrases): # Afficher une réponse aléatoire dans la liste
|
||||
def reponses(room, phrases, content=False): # Afficher une réponse aléatoire dans la liste
|
||||
i = random.randrange(0,len(phrases))
|
||||
msg(room,phrases[i])
|
||||
msg(room,phrases[i],content)
|
||||
|
||||
def jdr(room, event):
|
||||
global modules
|
||||
|
@ -1256,7 +1259,13 @@ def quote(room,event): # Gestion des citations
|
|||
else:
|
||||
msg(room,"Je n'ai pas de citations pour ce salon")
|
||||
|
||||
def addquote(room,event):
|
||||
def addquote(room,event): # enregistrer les citations mode reponses matrix
|
||||
global modules
|
||||
try:
|
||||
rmod = modules[room.room_id, 'quote']
|
||||
except:
|
||||
modules[room.room_id, 'quote'] = False
|
||||
if (modules[room.room_id, 'quote']):
|
||||
global citations
|
||||
|
||||
content = event['content']
|
||||
|
@ -1271,7 +1280,7 @@ def addquote(room,event):
|
|||
content['formatted_body'] = content['formatted_body'].replace("addquote", "")
|
||||
except:
|
||||
print("\n\nerreur formatted_body " + json.dumps(content))
|
||||
#print(json.dumps(content))
|
||||
|
||||
# Récupération de l'auteur
|
||||
auteur = "Un nain connu"
|
||||
match = re.search(r"<(@\w+:\w+.\w+)>", content['body'])
|
||||
|
@ -1294,6 +1303,42 @@ def addquote(room,event):
|
|||
msg(room,"Ajout de la citation de " + auteur + ":")
|
||||
bot.client.api.send_message_event(room.room_id, 'm.room.message', content, None, None)
|
||||
|
||||
def showquote(room, event): # afficher les citations mode reponse matrix
|
||||
global modules
|
||||
try:
|
||||
rmod = modules[room.room_id, 'quote']
|
||||
except:
|
||||
modules[room.room_id, 'quote'] = False
|
||||
if (modules[room.room_id, 'quote']):
|
||||
args = event['content']['body'].split()
|
||||
args.pop(0)
|
||||
famous = {}
|
||||
try:
|
||||
famous = quotes[room.room_id]
|
||||
except:
|
||||
famous = {}
|
||||
|
||||
if (len(args) == 1):
|
||||
# cite une quote d'une personne precise
|
||||
nick = args[0]
|
||||
phrases = []
|
||||
for cle,valeur in famous.items():
|
||||
if (cle[0] == nick):
|
||||
phrases.append(valeur)
|
||||
if (len(phrases) > 0 ):
|
||||
reponses(room,phrases,True)
|
||||
else:
|
||||
msg(room,"Je n'ai pas de citations pour " + nick)
|
||||
else:
|
||||
# cite une quote aleatoire
|
||||
phrases = []
|
||||
for cle,valeur in famous.items():
|
||||
phrases.append(valeur)
|
||||
if (len(phrases) > 0 ):
|
||||
reponses(room,phrases,True)
|
||||
else:
|
||||
msg(room,"Je n'ai pas de citations pour ce salon")
|
||||
|
||||
|
||||
def biere(room,event): # Gestion des boissons
|
||||
global modules
|
||||
|
@ -1709,6 +1754,8 @@ def main():
|
|||
citations_read()
|
||||
addquote_handler = MEndHandler("addquote", addquote)
|
||||
bot.add_handler(addquote_handler)
|
||||
showquote_handler = MCommandHandler("showquote", showquote)
|
||||
bot.add_handler(showquote_handler)
|
||||
|
||||
# bieres
|
||||
if ('biere' in liste_mod):
|
||||
|
|
Loading…
Reference in a new issue