xmpp: Migrate from discord.py to nextcord

This commit is contained in:
PapaTutuWawa 2021-09-16 20:12:20 +02:00
parent 8c64358134
commit 8aeb098b0f
4 changed files with 24 additions and 20 deletions

View File

@ -11,7 +11,7 @@ setup(
install_requires = [
"requests>=2.26.0",
"slixmpp>=1.7.1",
"discord.py>=1.7.3",
"nextcord",
"toml>=0.10.2"
],
extra_require = {

View File

@ -1,16 +1,16 @@
import logging
import discord
import nextcord
class DiscordClient(discord.Client):
class DiscordClient(nextcord.Client):
def __init__(self, xmpp, config):
intents = discord.Intents.default()
intents = nextcord.Intents.default()
intents.members = True
intents.presences = True
intents.messages = True
intents.reactions = True
discord.Client.__init__(self, intents=intents)
nextcord.Client.__init__(self, intents=intents)
self._xmpp = xmpp
self._config = config

View File

@ -1,4 +1,4 @@
from discord import Status
from nextcord import Status
def discord_status_to_xmpp_show(status):
return {

View File

@ -16,7 +16,7 @@ from slixmpp.componentxmpp import ComponentXMPP
from slixmpp.exceptions import XMPPError, IqError
from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.jid import JID
from discord import Status, Embed
from nextcord import Status, Embed
import requests
from xmpp_discord_bridge.slixmpp.oob import OOBData
@ -181,12 +181,13 @@ class BridgeComponent(ComponentXMPP):
# TODO: Is this working?
# Mirror the guild's icon
icon = await dchannel.guild.icon_url_as(static_format="png",
format="png",
size=128).read()
icon_url = dchannel.guild.icon.url
if icon_url:
req = requests.get(icon_url)
vcard = self.plugin["xep_0054"].make_vcard()
vcard["PHOTO"]["TYPE"] = "image/png"
vcard["PHOTO"]["BINVAL"] = base64.b64encode(icon)
vcard["PHOTO"]["BINVAL"] = base64.b64encode(req.content)
# TODO: Replace with provided API
self.send_raw("""
<iq type="set" from="{}" to="{}">
@ -366,7 +367,7 @@ class BridgeComponent(ComponentXMPP):
async def on_discord_channel_update(self, before, after):
if after.type != discord.ChannelType.text:
if after.type != nextcord.ChannelType.text:
return
guild = after.guild.id
@ -426,6 +427,9 @@ class BridgeComponent(ComponentXMPP):
for attachment in msg.attachments:
await self.send_oob_data(attachment.url, muc, msg.author)
for sticker in msg.stickers:
await self.send_oob_data(sticker.url, muc, msg.author)
if not msg.clean_content:
self._logger.debug("Message empty. Not relaying.")
return