Exemple #1
0
    def permissions(self, obb: '_typing.Union[dt_member.Member, dt_role.Role]') -> \
            'dt_permissions.Overwrite':
        """
        Gets the permission overwrites for the specified object.
        """
        if not self.guild:
            allow = dt_permissions.Permissions(515136)
            overwrite = dt_permissions.Overwrite(allow=allow,
                                                 deny=0,
                                                 obb=obb,
                                                 channel_id=self.id)
            overwrite._immutable = True
            return overwrite

        overwrite = self._overwrites.get(obb.id)
        if not overwrite:
            everyone_overwrite = self._overwrites.get(
                self.guild.default_role.id)
            if everyone_overwrite is None:
                everyone_perms = self.guild.default_role.permissions
                everyone_overwrite = dt_permissions.Overwrite(
                    allow=everyone_perms,
                    deny=dt_permissions.Permissions(0),
                    obb=obb)
                everyone_overwrite.channel_id = self.id
                overwrite = everyone_overwrite
            else:
                overwrite = dt_permissions.Overwrite(everyone_overwrite.allow,
                                                     everyone_overwrite.deny,
                                                     obb)

            overwrite.channel_id = self.id
            overwrite._immutable = True

        return overwrite
Exemple #2
0
    def _update_overwrites(self, overwrites: _typing.List[dict]):
        """
        Updates the overwrites for this channel.

        :param overwrites: A list of overwrite dicts.
        """
        if not self.guild_id:
            raise CuriousError(
                "A channel without a guild cannot have overwrites")

        self._overwrites = {}

        for overwrite in overwrites:
            id_ = int(overwrite["id"])
            type_ = overwrite["type"]

            if type_ == "member":
                obb = self.guild._members.get(id_)
            else:
                obb = self.guild._roles.get(id_)

            self._overwrites[id_] = dt_permissions.Overwrite(
                allow=overwrite["allow"],
                deny=overwrite["deny"],
                obb=obb,
                channel_id=self.id)
            self._overwrites[id_]._immutable = True
Exemple #3
0
    def permissions(self, obb: '_typing.Union[dt_member.Member, dt_role.Role]') -> \
            'dt_permissions.Overwrite':
        """
        Gets the permission overwrites for the specified object.
        """
        overwrite = self._overwrites.get(obb.id)
        if not overwrite:
            return dt_permissions.Overwrite(0, 0, obb, channel=self)

        return overwrite
Exemple #4
0
    def _update_overwrites(self, overwrites: list, guild=None):
        self._overwrites = {}

        guild = self.guild or guild

        for overwrite in overwrites:
            id = int(overwrite["id"])
            type_ = overwrite["type"]

            if type_ == "member":
                obb = guild._members.get(id)
            else:
                obb = guild._members.get(id)

            self._overwrites[id] = dt_permissions.Overwrite(
                allow=overwrite["allow"],
                deny=overwrite["deny"],
                obb=obb,
                channel=self)