generated from Nemesis/Exemple
Changement de fonction pour obtenir le DisplayName
This commit is contained in:
parent
a362c8840b
commit
f4e4e50250
1 changed files with 37 additions and 7 deletions
42
asmodee.py
42
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"):
|
||||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue