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 = [
|
install_requires = [
|
||||||
"requests>=2.26.0",
|
"requests>=2.26.0",
|
||||||
"slixmpp>=1.7.1",
|
"slixmpp>=1.7.1",
|
||||||
"discord.py>=1.7.3",
|
"nextcord",
|
||||||
"toml>=0.10.2"
|
"toml>=0.10.2"
|
||||||
],
|
],
|
||||||
extra_require = {
|
extra_require = {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import discord
|
import nextcord
|
||||||
|
|
||||||
class DiscordClient(discord.Client):
|
class DiscordClient(nextcord.Client):
|
||||||
def __init__(self, xmpp, config):
|
def __init__(self, xmpp, config):
|
||||||
intents = discord.Intents.default()
|
intents = nextcord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
intents.presences = True
|
intents.presences = True
|
||||||
intents.messages = True
|
intents.messages = True
|
||||||
intents.reactions = True
|
intents.reactions = True
|
||||||
|
|
||||||
discord.Client.__init__(self, intents=intents)
|
nextcord.Client.__init__(self, intents=intents)
|
||||||
|
|
||||||
self._xmpp = xmpp
|
self._xmpp = xmpp
|
||||||
self._config = config
|
self._config = config
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from discord import Status
|
from nextcord import Status
|
||||||
|
|
||||||
def discord_status_to_xmpp_show(status):
|
def discord_status_to_xmpp_show(status):
|
||||||
return {
|
return {
|
||||||
|
@ -16,7 +16,7 @@ from slixmpp.componentxmpp import ComponentXMPP
|
|||||||
from slixmpp.exceptions import XMPPError, IqError
|
from slixmpp.exceptions import XMPPError, IqError
|
||||||
from slixmpp.xmlstream import register_stanza_plugin
|
from slixmpp.xmlstream import register_stanza_plugin
|
||||||
from slixmpp.jid import JID
|
from slixmpp.jid import JID
|
||||||
from discord import Status, Embed
|
from nextcord import Status, Embed
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from xmpp_discord_bridge.slixmpp.oob import OOBData
|
from xmpp_discord_bridge.slixmpp.oob import OOBData
|
||||||
@ -181,12 +181,13 @@ class BridgeComponent(ComponentXMPP):
|
|||||||
|
|
||||||
# TODO: Is this working?
|
# TODO: Is this working?
|
||||||
# Mirror the guild's icon
|
# Mirror the guild's icon
|
||||||
icon = await dchannel.guild.icon_url_as(static_format="png",
|
icon_url = dchannel.guild.icon.url
|
||||||
format="png",
|
if icon_url:
|
||||||
size=128).read()
|
req = requests.get(icon_url)
|
||||||
|
|
||||||
vcard = self.plugin["xep_0054"].make_vcard()
|
vcard = self.plugin["xep_0054"].make_vcard()
|
||||||
vcard["PHOTO"]["TYPE"] = "image/png"
|
vcard["PHOTO"]["TYPE"] = "image/png"
|
||||||
vcard["PHOTO"]["BINVAL"] = base64.b64encode(icon)
|
vcard["PHOTO"]["BINVAL"] = base64.b64encode(req.content)
|
||||||
# TODO: Replace with provided API
|
# TODO: Replace with provided API
|
||||||
self.send_raw("""
|
self.send_raw("""
|
||||||
<iq type="set" from="{}" to="{}">
|
<iq type="set" from="{}" to="{}">
|
||||||
@ -366,7 +367,7 @@ class BridgeComponent(ComponentXMPP):
|
|||||||
|
|
||||||
|
|
||||||
async def on_discord_channel_update(self, before, after):
|
async def on_discord_channel_update(self, before, after):
|
||||||
if after.type != discord.ChannelType.text:
|
if after.type != nextcord.ChannelType.text:
|
||||||
return
|
return
|
||||||
|
|
||||||
guild = after.guild.id
|
guild = after.guild.id
|
||||||
@ -426,6 +427,9 @@ class BridgeComponent(ComponentXMPP):
|
|||||||
for attachment in msg.attachments:
|
for attachment in msg.attachments:
|
||||||
await self.send_oob_data(attachment.url, muc, msg.author)
|
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:
|
if not msg.clean_content:
|
||||||
self._logger.debug("Message empty. Not relaying.")
|
self._logger.debug("Message empty. Not relaying.")
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user