Exemplo n.º 1
0
    def update_role(self, role, **kwargs):
        if 'permissions' in kwargs and isinstance(kwargs['permissions'],
                                                  PermissionValue):
            kwargs['permissions'] = kwargs['permissions'].value

        return self.client.api.guilds_roles_modify(self.id, to_snowflake(role),
                                                   **kwargs)
Exemplo n.º 2
0
    def _get_roster_by_raid_and_guild(self, raid, guild: Guild):
        roster = {}

        for member in guild.members.values():
            if self._is_raider(member):
                roster[member.id] = {
                    "name": member.name,
                    "class": self._get_class(member),
                    "role": self._get_role(member),
                    "reaction": ReactionEnum.nothing
                }

        reactions = self._get_all_reactions_by_raid_id(raid.id)
        for reaction in reactions:
            member = guild.members.get(to_snowflake(reaction.user_id))
            if member is None:
                continue
            raider = roster.setdefault(
                member.id, {
                    "name": member.name,
                    "class": self._get_class(member),
                    "role": self._get_role(member)
                })
            raider["reaction"] = ReactionEnum(reaction.reaction)
            raider["reaction_time"] = str(reaction.at)
            raider["reason"] = reaction.reason

        return roster
Exemplo n.º 3
0
 def is_mentioned(self, entity):
     """
     Returns
     -------
     bool
         Whether the give entity was mentioned.
     """
     entity = to_snowflake(entity)
     return entity in self.mentions or entity in self.mention_roles
Exemplo n.º 4
0
 def set_parent(self, parent, reason=None):
     """
     Sets the channels parent.
     """
     assert (self.is_guild)
     return self.client.api.channels_modify(
         self.id,
         parent_id=to_snowflake(parent) if parent else parent,
         reason=reason)
Exemplo n.º 5
0
    def delete_reaction(self, emoji, user=None):
        if isinstance(emoji, Emoji):
            emoji = emoji.to_string()

        if user:
            user = to_snowflake(user)

        self.client.api.channels_messages_reactions_delete(
            self.channel_id, self.id, emoji, user)
Exemplo n.º 6
0
    def delete_pin(self, message):
        """
        Unpins the given message from the channel.

        Params
        ------
        message : `Message`|snowflake
            The message or message ID to pin.
        """
        self.client.api.channels_pins_delete(self.id, to_snowflake(message))
Exemplo n.º 7
0
    def create_pin(self, message):
        """
        Pins the given message to the channel.

        Params
        ------
        message : `Message`|snowflake
            The message or message ID to pin.
        """
        self.client.api.channels_pins_create(self.id, to_snowflake(message))
Exemplo n.º 8
0
    def delete_message(self, message):
        """
        Deletes a single message from this channel.

        Args
        ----
        message : snowflake|`Message`
            The message to delete.
        """
        self.client.api.channels_messages_delete(self.id, to_snowflake(message))
Exemplo n.º 9
0
    def __init__(self, bot, config):
        super().__init__(bot, config)

        if self.config.locale:
            import locale
            locale.setlocale(locale.LC_TIME, self.config.locale)

        self.timezone = dateutil.tz.gettz(self.config.timezone)

        self.renderer = Renderer(self.timezone)
        self.bot_channel_id = to_snowflake(self.config.bot_channel_id)
        self.raid_channel_id = to_snowflake(self.config.raid_channel_id)
        self.bot_channel = None
        self.calendar_channel = None
        self.calendar = None

        engine = create_engine(self.config.db_connect_str)
        session_maker = sessionmaker()
        session_maker.configure(bind=engine)
        self.session = session_maker()
Exemplo n.º 10
0
    def get_message(self, message):
        """
        Attempts to fetch and return a `Message` from the message object
        or id.

        Returns
        -------
        `Message`
            The fetched message
        """
        return self.client.api.channels_messages_get(self.id, to_snowflake(message))
Exemplo n.º 11
0
    def get_voice_state(self, user):
        """
        Attempt to get a voice state for a given user (who should be a member of
        this guild).

        Returns
        -------
        :class:`disco.types.voice.VoiceState`
            The voice state for the user in this guild.
        """
        user = to_snowflake(user)

        for state in six.itervalues(self.voice_states):
            if state.user_id == user:
                return state
Exemplo n.º 12
0
    def get_member(self, user):
        """
        Attempt to get a member from a given user.

        Returns
        -------
        :class:`GuildMember`
            The guild member object for the given user.
        """
        user = to_snowflake(user)

        if user not in self.members:
            try:
                self.members[user] = self.client.api.guilds_members_get(self.id, user)
            except APIException:
                return

        return self.members.get(user)
Exemplo n.º 13
0
 def delete_role(self, role):
     """
     Delete a role.
     """
     self.client.api.guilds_roles_delete(self.id, to_snowflake(role))
Exemplo n.º 14
0
 def delete_ban(self, user):
     self.client.api.guilds_bans_delete(self.id, to_snowflake(user))
Exemplo n.º 15
0
 def remove_role(self, role):
     self.client.api.guilds_members_roles_remove(self.guild.id,
                                                 self.user.id,
                                                 to_snowflake(role))
Exemplo n.º 16
0
 def add_role(self, role):
     self.client.api.guilds_members_roles_add(self.guild.id, self.user.id,
                                              to_snowflake(role))
Exemplo n.º 17
0
 def delete_pin(self, message):
     self.client.api.channels_pins_delete(self.id, to_snowflake(message))
Exemplo n.º 18
0
 def create_ban(self, user, *args, **kwargs):
     self.client.api.guilds_bans_create(self.id, to_snowflake(user), *args,
                                        **kwargs)
Exemplo n.º 19
0
 def create_ban(self, user, delete_message_days=0):
     self.client.api.guilds_bans_create(self.id, to_snowflake(user),
                                        delete_message_days)
Exemplo n.º 20
0
 def get_message(self, message):
     return self.client.api.channels_messages_get(self.id,
                                                  to_snowflake(message))