From 3a497eae97672d56274030abfd3563affeb92ba1 Mon Sep 17 00:00:00 2001 From: nemesis Date: Mon, 10 Nov 2025 13:55:55 +0100 Subject: [PATCH] global displayName --- asmodee.py | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/asmodee.py b/asmodee.py index 141902a..ffb12aa 100644 --- a/asmodee.py +++ b/asmodee.py @@ -710,13 +710,15 @@ async def getNick(room, message): # Obtenir le DisplayName à partir du mxid. #except: # nick = room.user_name(sender) try: - members = await bot.client.api.get_room_members(room.room_id) - for member in members: - if member['state_key'] == sender: - nick = member['content'].get('displayname') - break + nick = await bot.client.get_displayname(sender) + #members = await bot.client.api.get_room_members(room.room_id) + #for member in members: + # if member['state_key'] == sender: + # nick = member['content'].get('displayname') + # break except: nick = sender + nick = nick if nick is not None else sender return(nick) async def msg(room,mess,sender,content=False): @@ -929,14 +931,13 @@ async def verifPMRoom(room, message): # Pour obtenir ou créer un salon pour les bot_nick = await getNick(room, message) salon = None room_id = prive.get(sender) - members = [] + create = False try: - members = await bot.client.api.get_room_members(room_id) - print("Les membres du salon prive :") - print(members) + await bot.api.send_text_message(room_id, "Information : ") except: print("Pas d'accès au salon, on le refait") - if (room_id and members is not None and len(members) > 0): + create = True + if (room_id and not create): await bot.async_client.room_invite(room_id=room_id, user_id=sender) new_salon = nio.rooms.MatrixRoom(room_id, client_id) new_salon.name=bot_nick @@ -1255,12 +1256,13 @@ async def bienvenue(room,message): # Affichage d'un message d'accueil aux nouvea modules[room.room_id, 'welcome'] = False if (modules[room.room_id, 'welcome']): sender = getUser(message) - nick = None - members = await bot.client.api.get_room_members(room.room_id) - for member in members: - if member['state_key'] == message.state_key: - nick = member['content'].get('displayname') - break + #nick = None + nick = await bot.client.get_displayname(message.state_key) + #members = await bot.client.api.get_room_members(room.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 @@ -1336,6 +1338,7 @@ async def addquote(room,message): # enregistrer les citations mode reponses matr content = getMessage(message) sender = getUser(message) + nick = None if len(content) > 42: # Récupération de l'auteur auteur = "Un nain connu" @@ -1344,13 +1347,13 @@ async def addquote(room,message): # enregistrer les citations mode reponses matr auteur = match.group(1) #nick = room.user_name(auteur) try: - members = await bot.client.api.get_room_members(room.room_id) - for member in members: - if member['state_key'] == auteur: - nick = member['content'].get('displayname') - break + nick = await bot.client.get_displayname(auteur) + # members = await bot.client.api.get_room_members(room.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