Beispiel #1
0
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
Beispiel #2
0
 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)
Beispiel #3
0
def get_modmail_channel(bot, channel):
    return DMChannel(
        me=bot.user,
        state=bot.state,
        data={
            "id":
            int(channel.topic.replace("ModMail Channel ", "").split(" ")[1])
        },
    )
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #6
0
    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)
Beispiel #7
0
    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
Beispiel #8
0
 def add_dm_channel(self, data):
     return DMChannel(me=self.user, state=self, data=data)
Beispiel #9
0
def create_fake_channel(bot, channel_id):
    return DMChannel(me=bot.user, state=bot.state, data={"id": channel_id})