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:
|
if match:
|
||||||
return str(match.group())
|
return str(match.group())
|
||||||
else:
|
else:
|
||||||
return "personne"
|
return "Quelqu'un"
|
||||||
|
|
||||||
def getNick(room, message): # Obtenir le DisplayName à partir du mxid.
|
def getNick(room, message): # Obtenir le DisplayName à partir du mxid.
|
||||||
sender = getUser(message)
|
sender = getUser(message)
|
||||||
nick = None
|
nick = None
|
||||||
|
#try:
|
||||||
|
# nick = room.user_name(sender).split(' ')[0]
|
||||||
|
#except:
|
||||||
|
# nick = room.user_name(sender)
|
||||||
try:
|
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:
|
except:
|
||||||
nick = room.user_name(sender)
|
print(members)
|
||||||
|
nick = sender
|
||||||
return(nick)
|
return(nick)
|
||||||
|
|
||||||
async def msg(room,mess,sender,content=False):
|
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:
|
except:
|
||||||
modules[room.room_id, 'welcome'] = False
|
modules[room.room_id, 'welcome'] = False
|
||||||
if (modules[room.room_id, 'welcome']):
|
if (modules[room.room_id, 'welcome']):
|
||||||
sender = message.sender
|
sender = getUser(message)
|
||||||
nick = room.user_name(message.state_key) if room.user_name(message.state_key) else message.state_key
|
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
|
membership = message.membership
|
||||||
prev_member = message.prev_membership
|
prev_member = message.prev_membership
|
||||||
|
|
||||||
|
|
@ -1258,7 +1275,11 @@ async def bienvenue(room,message): # Affichage d'un message d'accueil aux nouvea
|
||||||
except:
|
except:
|
||||||
reponse = ""
|
reponse = ""
|
||||||
if (membership == "join" and prev_member != "join"):
|
if (membership == "join" and prev_member != "join"):
|
||||||
|
try:
|
||||||
await msg(room,"Bienvenue sur " + alias + ", " + nick + ". " + reponse,sender)
|
await msg(room,"Bienvenue sur " + alias + ", " + nick + ". " + reponse,sender)
|
||||||
|
except:
|
||||||
|
print(alias)
|
||||||
|
print(nick)
|
||||||
elif (membership == "leave" and prev_member != "leave"):
|
elif (membership == "leave" and prev_member != "leave"):
|
||||||
await msg(room,"Au revoir " + nick + "!",sender)
|
await msg(room,"Au revoir " + nick + "!",sender)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1315,7 +1336,16 @@ async def addquote(room,message): # enregistrer les citations mode reponses matr
|
||||||
match = re.search(r"<(@\w+:\w+.\w+)>", content)
|
match = re.search(r"<(@\w+:\w+.\w+)>", content)
|
||||||
if match:
|
if match:
|
||||||
auteur = match.group(1)
|
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
|
# Enlève la commande de la citation
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue