Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
FarisZR edited this page May 12, 2023 · 8 revisions

Discord

Bot setup

so the bridge supports multiple authorization methods, user bot and an oauth token. I choose to use a bot account, so the bot status can reflect the bridge's status. If the bridge is down, the bot will be too.

just create a new “application”, fill some details and head down to the bot section. Enable all permissions under the Privileged Gateway Intents section. Turn public bot off, it's only meant for Aosus.

add bot to aosus server

Adding a bot to a discord server is a bit complex. Copy the Application ID listed in the General Information page. And then use this link with the Bot's ID https://discord.com/api/oauth2/authorize?client_id=xxxxx&permissions=0&scope=bot

create relay for normal users

this bridge is mainly to be used as a puppeting bridge. After setting up a room bridge "!discord bridge " (room ID can be copied from the URL, or there should be a copy ID option if you enabled discords dev mode).

And now let's create the relay !discord set-relay --create <name>

discord login

from the aosus admin account create a new direct chat with the bot and write login-token bot <token> the token should be in the bot section.

CDN redirect

this doesn't seem to work normally bridges just re-upload content to matrix for bridging. However, this massively increases storage costs, and should be avoided as much as possible. Luckily it's avoidable in the discord bridge.

Since the CDN links for discord images is public, we can just directly load images from it. It's not very simple, but through a trick explained here, a few Caddy settings to proxy images from discord are enough.

Yes It's still going to cost us bandwidth, but most importantly no storage costs. Besides when bandwidth gets expensive for some reason, we can do it on the Cloudflare level, however the entire Matrix server needs to be behind Cloudflare for it to work.

Aosus Telegram groups custom settings

change from username to MXID

To prevent spoofing by using multiple servers or changing used names.
We will expose the full MXID, so it can't be faked.

Here is the command used in the room to use MXIDs along with display names, to prevent impersonation, and still make it easy to identify cross-platform users.

!tg config set message_formats m.text: "<pre>$sender_displayname/$sender_mxid</pre>  $message"
m.file: "<pre>$sender_displayname/$sender_mxid:</pre> ارسل ملف  $message"
m.image: "<pre>$sender_displayname/$sender_mxid:</pre> ارسل صورة:  $message"
m.audio: "<pre>$sender_displayname/$sender_mxid</pre> ارسل ملف صوتي:  $message"
m.video: "<pre>$sender_displayname/$sender_mxid</pre> ارسل مقطع مرئي:  $message"
m.location: "<pre>$sender_displayname/$sender_mxid</pre> ارسل موقع جيوغرافي:  $message"
m.notice: "<pre>$sender_displayname/$sender_mxid</pre>: $message"
m.emote: "* <pre>$sender_displayname/$sender_mxid</pre> $message"

mute join, leave and name change events

These are annoying in public groups and are being hidden in the telegram chat.
To mute these events from being forwarded.

!tg config set state_event_formats join: ""
leave: ""
name_change: ""