Use regex for emotes
This commit is contained in:
parent
b1a211c995
commit
5d62e3ade2
1 changed files with 5 additions and 6 deletions
9
main.py
9
main.py
|
@ -108,20 +108,19 @@ async def process_discord(message):
|
||||||
|
|
||||||
|
|
||||||
async def process_matrix(message):
|
async def process_matrix(message):
|
||||||
# Don't mention @everyone or @here
|
|
||||||
message = message.replace("@everyone", "@\u200Beveryone")
|
message = message.replace("@everyone", "@\u200Beveryone")
|
||||||
message = message.replace("@here", "@\u200Bhere")
|
message = message.replace("@here", "@\u200Bhere")
|
||||||
|
|
||||||
mentions = re.findall(r"(^|\s)(@(\w*))", message)
|
mentions = re.findall(r"(^|\s)(@(\w*))", message)
|
||||||
|
emotes = re.findall(r":(.*?):", message)
|
||||||
|
|
||||||
channel = await get_channel()
|
channel = await get_channel()
|
||||||
guild = channel.guild
|
guild = channel.guild
|
||||||
|
|
||||||
for emote in message.split():
|
for emote in emotes:
|
||||||
if emote[0] == emote[-1] == ":":
|
emote_ = discord.utils.get(guild.emojis, name=emote)
|
||||||
emote_ = discord.utils.get(guild.emojis, name=emote[1:-1])
|
|
||||||
if emote_:
|
if emote_:
|
||||||
message = message.replace(emote, str(emote_))
|
message = message.replace(f":{emote}:", str(emote_))
|
||||||
|
|
||||||
for mention in mentions:
|
for mention in mentions:
|
||||||
member = await guild.query_members(query=mention[2])
|
member = await guild.query_members(query=mention[2])
|
||||||
|
|
Loading…
Reference in a new issue