tangled
alpha
login
or
join now
zenfyr.dev
/
xmpp-discord-bridge
0
fork
atom
fork of https://f-hub.org/XMPP/xmpp-discord-bridge
0
fork
atom
overview
issues
pulls
pipelines
xmpp: Migrate from discord.py to nextcord
Alexander PapaTutuWawa
4 years ago
8aeb098b
8c643581
+24
-20
4 changed files
expand all
collapse all
unified
split
setup.py
xmpp_discord_bridge
discord.py
helpers.py
main.py
+1
-1
setup.py
···
11
11
install_requires = [
12
12
"requests>=2.26.0",
13
13
"slixmpp>=1.7.1",
14
14
-
"discord.py>=1.7.3",
14
14
+
"nextcord",
15
15
"toml>=0.10.2"
16
16
],
17
17
extra_require = {
+4
-4
xmpp_discord_bridge/discord.py
···
1
1
import logging
2
2
3
3
-
import discord
3
3
+
import nextcord
4
4
5
5
-
class DiscordClient(discord.Client):
5
5
+
class DiscordClient(nextcord.Client):
6
6
def __init__(self, xmpp, config):
7
7
-
intents = discord.Intents.default()
7
7
+
intents = nextcord.Intents.default()
8
8
intents.members = True
9
9
intents.presences = True
10
10
intents.messages = True
11
11
intents.reactions = True
12
12
13
13
-
discord.Client.__init__(self, intents=intents)
13
13
+
nextcord.Client.__init__(self, intents=intents)
14
14
15
15
self._xmpp = xmpp
16
16
self._config = config
+1
-1
xmpp_discord_bridge/helpers.py
···
1
1
-
from discord import Status
1
1
+
from nextcord import Status
2
2
3
3
def discord_status_to_xmpp_show(status):
4
4
return {
+18
-14
xmpp_discord_bridge/main.py
···
16
16
from slixmpp.exceptions import XMPPError, IqError
17
17
from slixmpp.xmlstream import register_stanza_plugin
18
18
from slixmpp.jid import JID
19
19
-
from discord import Status, Embed
19
19
+
from nextcord import Status, Embed
20
20
import requests
21
21
22
22
from xmpp_discord_bridge.slixmpp.oob import OOBData
···
124
124
channel = ch["channel"]
125
125
guild = ch["guild"]
126
126
dchannel = self._discord.get_channel(channel)
127
127
-
127
127
+
128
128
# Initialise state tracking
129
129
self._muc_map[muc] = (guild, channel)
130
130
self._virtual_muc_users[muc] = []
···
181
181
182
182
# TODO: Is this working?
183
183
# Mirror the guild's icon
184
184
-
icon = await dchannel.guild.icon_url_as(static_format="png",
185
185
-
format="png",
186
186
-
size=128).read()
187
187
-
vcard = self.plugin["xep_0054"].make_vcard()
188
188
-
vcard["PHOTO"]["TYPE"] = "image/png"
189
189
-
vcard["PHOTO"]["BINVAL"] = base64.b64encode(icon)
190
190
-
# TODO: Replace with provided API
191
191
-
self.send_raw("""
184
184
+
icon_url = dchannel.guild.icon.url
185
185
+
if icon_url:
186
186
+
req = requests.get(icon_url)
187
187
+
188
188
+
vcard = self.plugin["xep_0054"].make_vcard()
189
189
+
vcard["PHOTO"]["TYPE"] = "image/png"
190
190
+
vcard["PHOTO"]["BINVAL"] = base64.b64encode(req.content)
191
191
+
# TODO: Replace with provided API
192
192
+
self.send_raw("""
192
193
<iq type="set" from="{}" to="{}">
193
194
<vCard xmlns="vcard-temp">
194
195
{}
195
196
</vCard>
196
197
</iq>
197
197
-
""".format(self._bot_jid_full,
198
198
-
muc,
199
199
-
str(vcard)))
198
198
+
""".format(self._bot_jid_full,
199
199
+
muc,
200
200
+
str(vcard)))
200
201
201
202
# Aquire a webhook
202
203
wh = None
···
366
367
367
368
368
369
async def on_discord_channel_update(self, before, after):
369
369
-
if after.type != discord.ChannelType.text:
370
370
+
if after.type != nextcord.ChannelType.text:
370
371
return
371
372
372
373
guild = after.guild.id
···
426
427
for attachment in msg.attachments:
427
428
await self.send_oob_data(attachment.url, muc, msg.author)
428
429
430
430
+
for sticker in msg.stickers:
431
431
+
await self.send_oob_data(sticker.url, muc, msg.author)
432
432
+
429
433
if not msg.clean_content:
430
434
self._logger.debug("Message empty. Not relaying.")
431
435
return