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

xmpp: Migrate from discord.py to nextcord

+24 -20
+1 -1
setup.py
··· 11 11 install_requires = [ 12 12 "requests>=2.26.0", 13 13 "slixmpp>=1.7.1", 14 - "discord.py>=1.7.3", 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 - import discord 3 + import nextcord 4 4 5 - class DiscordClient(discord.Client): 5 + class DiscordClient(nextcord.Client): 6 6 def __init__(self, xmpp, config): 7 - intents = discord.Intents.default() 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 - discord.Client.__init__(self, intents=intents) 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 - from discord import Status 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 - from discord import Status, Embed 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 + 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 - icon = await dchannel.guild.icon_url_as(static_format="png", 185 - format="png", 186 - size=128).read() 187 - vcard = self.plugin["xep_0054"].make_vcard() 188 - vcard["PHOTO"]["TYPE"] = "image/png" 189 - vcard["PHOTO"]["BINVAL"] = base64.b64encode(icon) 190 - # TODO: Replace with provided API 191 - self.send_raw(""" 184 + icon_url = dchannel.guild.icon.url 185 + if icon_url: 186 + req = requests.get(icon_url) 187 + 188 + vcard = self.plugin["xep_0054"].make_vcard() 189 + vcard["PHOTO"]["TYPE"] = "image/png" 190 + vcard["PHOTO"]["BINVAL"] = base64.b64encode(req.content) 191 + # TODO: Replace with provided API 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 - """.format(self._bot_jid_full, 198 - muc, 199 - str(vcard))) 198 + """.format(self._bot_jid_full, 199 + muc, 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 - if after.type != discord.ChannelType.text: 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 + for sticker in msg.stickers: 431 + await self.send_oob_data(sticker.url, muc, msg.author) 432 + 429 433 if not msg.clean_content: 430 434 self._logger.debug("Message empty. Not relaying.") 431 435 return