Update process()
This commit is contained in:
parent
8f5f6b7c8e
commit
a28deb82f5
1 changed files with 8 additions and 7 deletions
15
main.py
15
main.py
|
@ -102,12 +102,10 @@ async def process(message, category):
|
||||||
# Replace emote names with emote IDs (Matrix -> Discord)
|
# Replace emote names with emote IDs (Matrix -> Discord)
|
||||||
if category == "emote":
|
if category == "emote":
|
||||||
start = end = ":"
|
start = end = ":"
|
||||||
start_ = 1
|
|
||||||
|
|
||||||
# Replace emote IDs with emote names (Discord -> Matrix)
|
# Replace emote IDs with emote names (Discord -> Matrix)
|
||||||
elif category == "emote_":
|
elif category == "emote_":
|
||||||
start = "<:"
|
start = "<:"
|
||||||
start_ = 2
|
|
||||||
end = ">"
|
end = ">"
|
||||||
|
|
||||||
# Replace mentioned user names with IDs (Matrix -> Discord)
|
# Replace mentioned user names with IDs (Matrix -> Discord)
|
||||||
|
@ -116,18 +114,16 @@ async def process(message, category):
|
||||||
guild = channel.guild
|
guild = channel.guild
|
||||||
|
|
||||||
start = "@"
|
start = "@"
|
||||||
start_ = 0
|
|
||||||
end = ""
|
end = ""
|
||||||
|
|
||||||
# Replace mentioned user IDs with names (Discord -> Matrix)
|
# Replace mentioned user IDs with names (Discord -> Matrix)
|
||||||
elif category == "mention_":
|
elif category == "mention_":
|
||||||
start = "<@!"
|
start = "<@"
|
||||||
start_ = 3
|
|
||||||
end = ">"
|
end = ">"
|
||||||
|
|
||||||
for item in message.split():
|
for item in message.split():
|
||||||
if item.startswith(start) and item.endswith(end):
|
if item.startswith(start) and item.endswith(end):
|
||||||
item_ = item[start_:-1]
|
item_ = item[len(start):-1]
|
||||||
|
|
||||||
if category == "emote":
|
if category == "emote":
|
||||||
emote = discord.utils.get(discord_client.emojis, name=item_)
|
emote = discord.utils.get(discord_client.emojis, name=item_)
|
||||||
|
@ -145,7 +141,12 @@ async def process(message, category):
|
||||||
message = message.replace(item, member.mention)
|
message = message.replace(item, member.mention)
|
||||||
|
|
||||||
elif category == "mention_":
|
elif category == "mention_":
|
||||||
user = discord_client.get_user(int(item_))
|
try:
|
||||||
|
item_ = int(item_)
|
||||||
|
except ValueError:
|
||||||
|
item_ = int(item[3:-1])
|
||||||
|
|
||||||
|
user = discord_client.get_user(item_)
|
||||||
message = message.replace(item, f"@{user.name}")
|
message = message.replace(item, f"@{user.name}")
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
|
Loading…
Reference in a new issue