From f4e4e502506a84ece0edf837af3e2eb833cbe580 Mon Sep 17 00:00:00 2001 From: nemesis Date: Mon, 10 Nov 2025 11:16:10 +0100 Subject: [PATCH] Changement de fonction pour obtenir le DisplayName --- asmodee.py | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/asmodee.py b/asmodee.py index 1b6b59d..2ec711e 100644 --- a/asmodee.py +++ b/asmodee.py @@ -700,15 +700,24 @@ def getUser(message): if match: return str(match.group()) else: - return "personne" + return "Quelqu'un" def getNick(room, message): # Obtenir le DisplayName à partir du mxid. sender = getUser(message) nick = None + #try: + # nick = room.user_name(sender).split(' ')[0] + #except: + # nick = room.user_name(sender) try: - nick = room.user_name(sender).split(' ')[0] + members = await bot.client.get_room_members(room_id) + for member in members: + if member['state_key'] == sender: + nick = member['content'].get('displayname') + break except: - nick = room.user_name(sender) + print(members) + nick = sender return(nick) async def msg(room,mess,sender,content=False): @@ -1239,8 +1248,16 @@ async def bienvenue(room,message): # Affichage d'un message d'accueil aux nouvea except: modules[room.room_id, 'welcome'] = False if (modules[room.room_id, 'welcome']): - sender = message.sender - nick = room.user_name(message.state_key) if room.user_name(message.state_key) else message.state_key + sender = getUser(message) + nick = None + members = await bot.client.get_room_members(room_id) + for member in members: + if member['state_key'] == message.state_key: + nick = member['content'].get('displayname') + break + #nick = room.user_name(message.state_key) if room.user_name(message.state_key) else message.state_key + if nick == None: + nick = sender membership = message.membership prev_member = message.prev_membership @@ -1258,7 +1275,11 @@ async def bienvenue(room,message): # Affichage d'un message d'accueil aux nouvea except: reponse = "" if (membership == "join" and prev_member != "join"): - await msg(room,"Bienvenue sur " + alias + ", " + nick + ". " + reponse,sender) + try: + await msg(room,"Bienvenue sur " + alias + ", " + nick + ". " + reponse,sender) + except: + print(alias) + print(nick) elif (membership == "leave" and prev_member != "leave"): await msg(room,"Au revoir " + nick + "!",sender) else: @@ -1315,7 +1336,16 @@ async def addquote(room,message): # enregistrer les citations mode reponses matr match = re.search(r"<(@\w+:\w+.\w+)>", content) if match: auteur = match.group(1) - nick = room.user_name(auteur) + #nick = room.user_name(auteur) + try: + members = await bot.client.get_room_members(room_id) + for member in members: + if member['state_key'] == auteur: + nick = member['content'].get('displayname') + break + except: + print(members) + nick = sender # Enlève la commande de la citation try: