xmpp: Migrate from discord.py to nextcord
This commit is contained in:
parent
8c64358134
commit
8aeb098b0f
2
setup.py
2
setup.py
@ -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 = {
|
||||
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
from discord import Status
|
||||
from nextcord import Status
|
||||
|
||||
def discord_status_to_xmpp_show(status):
|
||||
return {
|
||||
|
@ -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
|
||||
@ -124,7 +124,7 @@ class BridgeComponent(ComponentXMPP):
|
||||
channel = ch["channel"]
|
||||
guild = ch["guild"]
|
||||
dchannel = self._discord.get_channel(channel)
|
||||
|
||||
|
||||
# Initialise state tracking
|
||||
self._muc_map[muc] = (guild, channel)
|
||||
self._virtual_muc_users[muc] = []
|
||||
@ -181,22 +181,23 @@ 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()
|
||||
vcard = self.plugin["xep_0054"].make_vcard()
|
||||
vcard["PHOTO"]["TYPE"] = "image/png"
|
||||
vcard["PHOTO"]["BINVAL"] = base64.b64encode(icon)
|
||||
# TODO: Replace with provided API
|
||||
self.send_raw("""
|
||||
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(req.content)
|
||||
# TODO: Replace with provided API
|
||||
self.send_raw("""
|
||||
<iq type="set" from="{}" to="{}">
|
||||
<vCard xmlns="vcard-temp">
|
||||
{}
|
||||
</vCard>
|
||||
</iq>
|
||||
""".format(self._bot_jid_full,
|
||||
muc,
|
||||
str(vcard)))
|
||||
""".format(self._bot_jid_full,
|
||||
muc,
|
||||
str(vcard)))
|
||||
|
||||
# Aquire a webhook
|
||||
wh = None
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user