async def get_reaction_menu(bot, payload, kind): for menu in await bot.state.smembers("reaction_menus"): if menu["channel"] == payload.channel_id and menu[ "message"] == payload.message_id and menu["kind"] == kind: channel = DMChannel(me=bot.user, state=bot.state, data={"id": menu["channel"]}) message = channel.get_partial_message(menu["message"]) return menu, channel, message return None, None, None
async def parse_channel_update(self, data, old): channel_type = try_enum(ChannelType, data.get("type")) if old and channel_type is ChannelType.private: channel = DMChannel(me=self.user, state=self, data=data) old_channel = DMChannel(me=self.user, state=self, data=old) self.dispatch("private_channel_update", old_channel, channel) elif old: guild = await self._get_guild( utils._get_as_snowflake(data, "guild_id")) if guild: factory, _ = _channel_factory(data["type"]) channel = factory(guild=guild, state=self, data=data) old_factory, _ = _channel_factory(old["type"]) old_channel = old_factory(guild=guild, state=self, data=old) self.dispatch("guild_channel_update", old_channel, channel)
def get_modmail_channel(bot, channel): return DMChannel( me=bot.user, state=bot.state, data={ "id": int(channel.topic.replace("ModMail Channel ", "").split(" ")[1]) }, )
async def parse_channel_create(self, data, old): factory, ch_type = _channel_factory(data["type"]) if ch_type is ChannelType.private: channel = DMChannel(me=self.user, data=data, state=self) self.dispatch("private_channel_create", channel) else: guild = await self._get_guild( utils._get_as_snowflake(data, "guild_id")) if guild: channel = factory(guild=guild, state=self, data=data) self.dispatch("guild_channel_create", channel)
async def parse_channel_delete(self, data, old): if old and old["guild_id"]: guild = await self._get_guild( utils._get_as_snowflake(data, "guild_id")) if guild: factory, _ = _channel_factory(old["type"]) channel = factory(guild=guild, state=self, data=old) self.dispatch("guild_channel_delete", channel) elif old: channel = DMChannel(me=self.user, state=self, data=old) self.dispatch("private_channel_delete", channel)
async def parse_message_create(self, data, old): channel = await self.get_channel(int(data["channel_id"])) if not channel and not data.get("guild_id"): channel = DMChannel(me=await self.user(), state=self, data={"id": data["channel_id"]}) if channel: message = self.create_message(channel=channel, data=data) self.dispatch("message", message)
async def _get_channel(self, channel_id): result = await self.get(f"channel:{channel_id}") if result: if result.get("guild_id"): factory, _ = _channel_factory(result["type"]) guild = await self._get_guild(result["guild_id"]) if guild: return factory(guild=guild, state=self, data=result) else: return DMChannel(me=self.user, state=self, data=result) return None
def add_dm_channel(self, data): return DMChannel(me=self.user, state=self, data=data)
def create_fake_channel(bot, channel_id): return DMChannel(me=bot.user, state=bot.state, data={"id": channel_id})