fork of https://f-hub.org/XMPP/xmpp-discord-bridge

Tried to make it more accessible.

+107 -53
+32 -53
README.md
··· 13 13 - XMPP Avatar spoofing on the Discord side 14 14 - Support for proxying media sent via Discord (With [this miniproxy](https://git.polynom.me/PapaTutuWawa/miniproxy)) 15 15 16 - ## Usage 16 + ## Install 17 17 18 - The bridge can be configured via `config.toml` at either the current working directory or `/etc/xmpp-discord-bridge/config.toml`. 18 + ⚠️ This is how I set it up on Debian Bookworm. If you need help adapting it to your distribution, please open an issue or ask for help on [Jabber](xmpp:bridging@joinjabber.org?join). 19 + 20 + ⚠️ This guide also does not use a "venv" (virtual environment). I had an issue running it in its own "venv". If someone wants to troubleshoot it, contributions are welcome. 19 21 20 - ```toml 21 - [general] 22 - jid = "discord.server.example" # JID of the server component 23 - secret = "secret" # Component secret 24 - server = "server.example" # Address of the actual XMPP server 25 - port = 5869 # Component port 26 - discord_token "...." # Token of your Discord bot 22 + 1. Install needed dependencies. `sudo apt install git python3-full pip cmake` 23 + 2. Create a new system user to run it under. `sudo adduser --system --home /var/lib/xmpp-discord-bridge xmpp-discord-bridge` 24 + 3. Now open a shell as that user. `sudo -u xmpp-discord-bridge -s` 25 + 4. Run: `cd && git clone "https://codeberg.org/queer-spark/xmpp-discord-bridge.git" && cd xmpp-discord-bridge && python3 -m pip install . --user --break-system-packages && cd` 26 + 5. Create and edit `~/config.toml`. Refer to [example.toml](example.toml) for options. 27 + 6. `exit` to leave the shell. 28 + 7. Copy the service file to systemd's system directory. `sudo cp /var/lib/xmpp-discord-bridge/xmpp-discord-bridge/optional/xmpp-discord-bridge.service /etc/systemd/system/` 29 + 8. Read through the [XMPP](#XMPP) and [Discord](#Discord) sections and make sure the listed requirements are met. 30 + 9. Start and enable the bridge. `sudo systemctl enable --now xmpp-discord-bridge.service` 31 + 32 + ### XMPP 27 33 28 - # If a message is reacted to, send the following to the MUC: 29 - # > [Message content] 30 - # + :someemoji: 31 - reactions_compat = true 34 + In order for the bridge to work, it needs to have an affiliation of `owner` before joining. Going off of the example.toml, it would have the JID of `bot@discord.example.com`. 35 + The virtual users that follow will be automatically added to the room with an affiliation 36 + of `member`. 32 37 33 - # Use the XMPP user's avatar in the webhook. For options, see 34 - # the [avatars] section 35 - relay_xmpp_avatars = false 38 + ### Discord 36 39 37 - # When a user is mentioned, also add the display name infront of the message body, e.g. 38 - # SomeUser, PapaTutuWawa: Hello @SomeUser and @PapaTutuWawa 39 - muc_mention_compat = true 40 + (based upon https://github.com/42wim/matterbridge/wiki/Discord-bot-setup) 40 41 41 - # If true, then xmpp-discord-bridge will also make offline Discord users appear in the MUC. 42 - # If they are offline, then they will have a presence of "xa". If false, then offline users 43 - # will leave the MUC. 44 - dont_ignore_offline = true 42 + #### Create Bot 45 43 46 - # If true, when receiving a file to embed in Discord, the bridge will remove the URL from 47 - # the content, leaving only the embed behind. This prevents Discord users who disabled 48 - # link previews from viewing the embed. 49 - remove_url_on_embed = true 44 + You need to setup a "Bot" on Discord. Go [here](https://discord.com/developers/applications) and click "New Application". 50 45 51 - # When sending files from Discord to XMPP, proxy the URLS with this template. "<hmac>" and 52 - # and "<url>" will be substituted. Proxy will not be used if not set. 53 - proxy_discord_urls_to = "https://proxy.server.example/proxy/<hmac>/<url>" 46 + Then give your bot a name. Click "Create". On the next screen, you can optionally set an Avatar Icon for your app and description. 54 47 55 - # Secret for the proxy. Only used when the proxy is used. 56 - hmac_secret = "some-secret" 48 + Next, click on "Bot" on the left-hand menu. Then click "Add Bot", then "Yes Do It". 57 49 58 - # Set to false to prevent the Discord channel description from being mirrored to the MUC ubject. 59 - mirror_subject = true 50 + On the "Bot" screen, click "Reset Token" and "Yes. Do It!". Then click "Copy" to copy it. Then paste it to "discord_token" in your `config.toml`. 60 51 61 - # Set to false to prevent the Discord guild avatar from being copied to the MUC avatar. 62 - mirror_icon = true 52 + Optional: Here, you can also toggle if the bot is public, which will allow others to invite it to their servers. 63 53 64 - [avatars] 65 - # Path where avatars can be stored 66 - path = "/some/path" 54 + Make sure to also toggle the "Server Members Intent" and "Message Content Intent" options further down under "Privileged Gateway Intents" to allow the bot to see the member list. 67 55 68 - # URL on which the avatars will be available 69 - url = "https://im.server.example/avatars/" 56 + #### Invite Bot 70 57 71 - [discord] 72 - [[discord.channels]] 73 - # The ID of the guild 74 - guild = 00000000000 58 + Now it's time to invite your bot to your server. Don't worry about your bot being started for this next step. On the left-hand menu click "OAuth2" and copy the Client ID into this URL then navigate to it. 75 59 76 - # The ID of the channel to mirror 77 - channel = 000000000 60 + https://discordapp.com/oauth2/authorize?&client_id=YOUR_CLIENT_ID_HERE&scope=bot&permissions=536870912 78 61 79 - # The MUC to mirror into 80 - muc = "channel@muc.server.example" 81 - ``` 62 + The "permissions=536870912" at the end of the URL corresponds to the "Manage Webhooks" permission. It is required for the bridge to work correctly. 82 63 83 - In order for the bridge to work, it needs to have an affiliation of `owner` before joining. 84 - The virtual users that follow will be automatically added to the room with an affiliation 85 - of `member`. 64 + Discord will ask you which guild to invite it to. Select the guild then Authorize it. 86 65 87 66 ## License 88 67
+61
example.toml
··· 1 + [general] 2 + jid = "discord.example.com" # JID of the server component 3 + secret = "" # Component secret 4 + server = "example.com" # Address of the actual XMPP server 5 + port = "5347" # Component port 6 + discord_token = "" # Token of your Discord bot 7 + 8 + # If a message is reacted to, send the following to the MUC: 9 + # > [Message content] 10 + # + :someemoji: 11 + reactions_compat = true 12 + 13 + # Use the XMPP user's avatar in the webhook. For options, see 14 + # the [avatars] section 15 + relay_xmpp_avatars = false 16 + 17 + # When a user is mentioned, also add the display name infront of the message body, e.g. 18 + # SomeUser, PapaTutuWawa: Hello @SomeUser and @PapaTutuWawa 19 + muc_mention_compat = true 20 + 21 + # If true, then xmpp-discord-bridge will also make offline Discord users appear in the MUC. 22 + # If they are offline, then they will have a presence of "xa". If false, then offline users 23 + # will leave the MUC. 24 + dont_ignore_offline = false 25 + 26 + # If true, when receiving a file to embed in Discord, the bridge will remove the URL from 27 + # the content, leaving only the embed behind. This prevents Discord users who disabled 28 + # link previews from viewing the embed. 29 + remove_url_on_embed = true 30 + 31 + # When sending files from Discord to XMPP, proxy the URLS with this template. "<hmac>" and 32 + # and "<url>" will be substituted. Proxy will not be used if not set. 33 + proxy_discord_urls_to = "https://proxy.example.com/<hmac>/<url>" 34 + 35 + # Secret for the proxy. Only used when the proxy is used. 36 + hmac_secret = "" 37 + 38 + # Set to false to prevent the Discord channel description from being mirrored to the MUC ubject. 39 + mirror_subject = true 40 + 41 + # Set to false to prevent the Discord guild avatar from being copied to the MUC avatar. 42 + mirror_icon = true 43 + 44 + [avatars] 45 + # Path where avatars can be stored. Make sure it is writable by the user the bridge is running under 46 + # and readable by your http service. 47 + path = "/var/www/html/avatars" 48 + 49 + # URL on which the avatars will be available 50 + url = "https://example.com/avatars/" 51 + 52 + [discord] 53 + [[discord.channels]] 54 + # The ID of the guild 55 + guild = 000000000 56 + 57 + # The ID of the channel to mirror 58 + channel = 000000000 59 + 60 + # The MUC to mirror into 61 + muc = "channel@muc.server.example"
+14
optional/xmpp-discord-bridge.service
··· 1 + [Unit] 2 + Description=Jabber-Discord Bridge 3 + After=network-online.target 4 + 5 + [Service] 6 + Type=simple 7 + ExecStart=/var/lib/xmpp-discord-bridge/.local/bin/xmpp-discord-bridge 8 + WorkingDirectory=/var/lib/xmpp-discord-bridge 9 + Restart=always 10 + RestartSec=5s 11 + User=xmpp-discord-bridge 12 + 13 + [Install] 14 + WantedBy=multi-user.target