Append "@" before username

This commit is contained in:
git-bruh 2020-11-16 14:28:56 +05:30
parent 28b63ca798
commit 62314861ac
No known key found for this signature in database
GPG key ID: E1475C50075ADCE6

22
main.py
View file

@ -47,10 +47,13 @@ async def on_ready():
@discord_client.event @discord_client.event
async def on_message(message): async def on_message(message):
# Don't respond to bots/webhooks # Don't act on bots
if message.author.bot: if message.author.bot:
return return
if str(message.channel.id) != config["channel_id"]:
return
# Replace Discord IDs with mentions and emotes # Replace Discord IDs with mentions and emotes
content = await process_discord(message.content) content = await process_discord(message.content)
@ -60,9 +63,8 @@ async def on_message(message):
for attachment in message.attachments: for attachment in message.attachments:
content += f"\n{attachment.url}" content += f"\n{attachment.url}"
if str(message.channel.id) == config["channel_id"]: matrix_message = await message_send(content)
matrix_message = await message_send(content) message_cache[message.id] = matrix_message
message_cache[message.id] = matrix_message
@discord_client.event @discord_client.event
@ -73,15 +75,15 @@ async def on_message_delete(message):
@discord_client.event @discord_client.event
async def on_typing(channel, user, when): async def on_typing(channel, user, when):
channel_ = await get_channel()
# Don't act on bots # Don't act on bots
if user.bot: if user.bot:
return return
if channel == channel_: if str(channel.id) != config["channel_id"]:
# Send typing event return
await matrix_client.room_typing(config["room_id"], timeout=0)
# Send typing event
await matrix_client.room_typing(config["room_id"], timeout=0)
async def get_channel(): async def get_channel():
@ -107,7 +109,7 @@ async def process_discord(message):
mention_ = int(mention[3:-1]) mention_ = int(mention[3:-1])
user = discord_client.get_user(mention_) user = discord_client.get_user(mention_)
message = message.replace(mention, f"{user.name}") message = message.replace(mention, f"@{user.name}")
return message return message