xmpp-discord-bridge/xmpp_discord_bridge/discord.py

54 lines
1.8 KiB
Python
Raw Permalink Normal View History

2021-09-15 20:33:59 +00:00
import logging
import nextcord
2021-09-15 20:33:59 +00:00
class DiscordClient(nextcord.Client):
2021-09-15 20:33:59 +00:00
def __init__(self, xmpp, config):
intents = nextcord.Intents.default()
2021-09-15 20:33:59 +00:00
intents.members = True
intents.presences = True
intents.messages = True
intents.reactions = True
nextcord.Client.__init__(self, intents=intents)
2021-09-15 20:33:59 +00:00
self._xmpp = xmpp
self._config = config
self._logger = logging.getLogger("discord.client")
async def on_ready(self):
await self._xmpp.on_discord_ready()
async def on_message(self, message):
await self._xmpp.on_discord_message(message)
async def on_member_update(self, before, after):
await self._xmpp.on_discord_member_update(before, after)
async def on_member_join(self, member):
await self._xmpp.on_discord_member_join(member)
async def on_member_leave(self, member):
await self._xmpp.on_discord_member_leave(member)
async def on_guild_channel_update(self, before, after):
await self._xmpp.on_discord_channel_update(before, after)
async def on_reaction(self, payload):
message = await (self.get_guild(payload.guild_id)
.get_channel(payload.channel_id)
.fetch_message(payload.message_id))
await self._xmpp.on_discord_reaction(payload.guild_id,
payload.channel_id,
payload.emoji.name,
message,
payload.user_id,
payload.event_type)
async def on_raw_reaction_add(self, payload):
await self.on_reaction(payload)
async def on_raw_reaction_remove(self, payload):
await self.on_reaction(payload)