Don't mention @everyone or @here

This commit is contained in:
git-bruh 2020-11-14 18:09:44 +05:30
parent da2ed9bf52
commit 1c760f760c
No known key found for this signature in database
GPG key ID: E1475C50075ADCE6

22
main.py
View file

@ -39,6 +39,10 @@ logging.basicConfig(level=logging.INFO)
async def on_ready(): async def on_ready():
print(f"Logged in as {discord_client.user}") print(f"Logged in as {discord_client.user}")
global channel_
channel_ = int(config["channel_id"])
channel_ = discord_client.get_channel(channel_)
# Start Matrix bot # Start Matrix bot
await create_matrix_client() await create_matrix_client()
@ -102,16 +106,12 @@ async def process(message, category):
async def webhook_send(author, avatar, message): async def webhook_send(author, avatar, message):
# Get Discord channel from channel ID
channel = int(config["channel_id"])
channel = discord_client.get_channel(channel)
# Create webhook if it doesn't exist # Create webhook if it doesn't exist
hook_name = "matrix_bridge" hook_name = "matrix_bridge"
hooks = await channel.webhooks() hooks = await channel_.webhooks()
hook = discord.utils.get(hooks, name=hook_name) hook = discord.utils.get(hooks, name=hook_name)
if hook is None: if hook is None:
hook = await channel.create_webhook(name=hook_name) hook = await channel_.create_webhook(name=hook_name)
# Replace emote names # Replace emote names
message = await process(message, "emote") message = await process(message, "emote")
@ -120,12 +120,8 @@ async def webhook_send(author, avatar, message):
async def partial_mention(user): async def partial_mention(user):
# Get Discord channel from channel ID
channel = int(config["channel_id"])
channel = discord_client.get_channel(channel)
# Get guild to parse member list # Get guild to parse member list
guild = channel.guild guild = channel_.guild
# Remove "@" # Remove "@"
user = user[1:] user = user[1:]
@ -189,6 +185,10 @@ async def message_callback(room, event):
homeserver = author.split(":")[-1] homeserver = author.split(":")[-1]
url = "https://matrix.org/_matrix/media/r0/download" url = "https://matrix.org/_matrix/media/r0/download"
# Don't mention @everyone or @here
message = message.replace("@everyone", "@\u200Beveryone")
message = message.replace("@here", "@\u200Bhere")
# Replace partial mention of Discord user with ID # Replace partial mention of Discord user with ID
if message.startswith("@"): if message.startswith("@"):
user = message.split()[0] user = message.split()[0]