Ejemplo n.º 1
0
    def get_permissions(self, user):
        """
        Get the permissions a user has in this guild.

        Returns
        -------
        :class:`disco.types.permissions.PermissionValue`
            Computed permission value for the user.
        """
        if self.owner_id == user.id:
            return PermissionValue(Permissions.ADMINISTRATOR)

        member = self.get_member(user)
        value = PermissionValue(self.roles.get(self.id).permissions)

        for role in map(self.roles.get, member.roles):
            value += role.permissions

        return value
Ejemplo n.º 2
0
def filter_perms(member_value, target_value):

    perm_dict = PermissionValue(target_value).to_dict()
    member_perms = PermissionValue(member_value)
    response = ""


    # Ensure we aren't checking against no permissions so that
    #  the response isn't absolutely disgusting
    if target_value != 0:


        # Cycling through permissions dict
        for perm, can in perm_dict.items():

            # Check if permissions is valid
            if can:

                try:
                    # Ensure user uses permissions
                    if member_perms.can():
                        response = response + "\n+ " + perm.upper()

                    else:
                        response = response + "\n- " + perm.upper()
                except KeyError:
                    continue

        return response
Ejemplo n.º 3
0
    def get_permissions(self, member):
        """
        Get the permissions a user has in this guild.

        Returns
        -------
        :class:`disco.types.permissions.PermissionValue`
            Computed permission value for the user.
        """
        if not isinstance(member, GuildMember):
            member = self.get_member(member)

        # Owner has all permissions
        if self.owner_id == member.id:
            return PermissionValue(Permissions.ADMINISTRATOR)

        value = PermissionValue(self.roles.get(self.id).permissions)

        # Iterate over all roles the user has (plus the @everyone role)
        for role in map(self.roles.get, member.roles + [self.id]):
            value += role.permissions

        return value
Ejemplo n.º 4
0
    def process_message(self, event, message=None):
        if message is None:
            message = event.message
        for key, value in message.attachments.iteritems():
            # Get the info from the image
            try:
                image = cv2utils.urlToImage(value.url)
                raidInfo = self.ocr.scanExRaidImage(
                    image,
                    self.topleft,
                    self.bottom,
                    useCity=self.config.include_city_in_channel_names)
                try:
                    if raidInfo.city not in self.config.allowed_cities and len(
                            self.config.allowed_cities) > 0:
                        self.atReply(
                            message, self.config.messages['city_not_allowed'] +
                            ', '.join(self.config.allowed_cities))
                        continue
                except AttributeError:
                    # We'll assume no city is okay
                    pass
                if self.dateDiff(raidInfo.month + '-' + raidInfo.day + ' ' +
                                 raidInfo.begin).days < 0:
                    self.atReply(message, self.config.messages['date_in_past'])
                    continue
                cname = pokediscord.generateChannelName(
                    raidInfo, self.config.include_city_in_channel_names)
                try:
                    catname = self.config.channel_category
                except AttributeError:
                    catname = pokediscord.generateCategoryName(raidInfo)
            except pokeocr.MatchNotCenteredException:
                traceback.print_exc()
                self.atReply(message,
                             self.config.messages['match_not_centered'])
                continue
            except pokeocr.TooFewLinesException:
                traceback.print_exc()
                self.atReply(message, self.config.messages['too_few_lines'])
                continue
            except pokeocr.InvalidCityException:
                traceback.print_exc()
                self.atReply(message, self.config.messages['invalid_city'])
                continue
            except Exception:
                traceback.print_exc()
                self.atReply(message, self.config.messages['could_not_parse'])
                continue

            # Create the category if it doesn't exist
            category = self.getChannelByName(catname, event.guild.channels)
            if not category:
                category = event.guild.create_category(catname)

            # Create the channel if it doesn't exist
            channel = self.getChannelByName(cname, event.guild.channels)
            if not channel:
                try:
                    overwrites = []
                    for rname in self.config.roles_for_new_channels:
                        role = self.getRoleByName(rname, event.guild)
                        if role is None:
                            print 'Warning: role ' + rname + ' does not exist'
                            continue
                        overwrites.append(
                            PermissionOverwrite(
                                id=role.id,
                                type=PermissionOverwriteType.ROLE,
                                allow=PermissionValue(
                                    Permissions.READ_MESSAGES)))

                    everyone = self.getEveryoneRole(event.guild)
                    overwrites.append(
                        PermissionOverwrite(id=everyone.id,
                                            type=PermissionOverwriteType.ROLE,
                                            deny=PermissionValue(
                                                Permissions.READ_MESSAGES)))
                    channel = category.create_text_channel(
                        cname, permission_overwrites=overwrites)
                except Exception:
                    traceback.print_exc()
                    self.atReply(message,
                                 self.config.messages['channel_create_error'])
                    continue

                # Post a sticky message to track who's in the channel
                uic_message = channel.send_message(
                    self.config.messages['users_in_channel_message'])
                uic_message.pin()

                self.alphabetizeChannels(category, event.guild.channels)

            # Is the user already in the channel?
            if self.userInChannel(message.author, channel):
                self.atReply(
                    message, self.config.messages['user_already_in_channel'] +
                    ' <#' + str(channel.id) + '>')
                continue

            # Add the user to the channel
            try:
                channel.create_overwrite(message.author,
                                         allow=PermissionValue(
                                             Permissions.READ_MESSAGES))
                self.atReply(
                    message, self.config.messages['added_success'] + ' <#' +
                    str(channel.id) + '>')
                channel.send_message(self.config.messages['post_add_message'] +
                                     ' <@' + str(message.author.id) + '>')
            except Exception:
                traceback.print_exc()
                self.atReply(message,
                             self.config.messages['channel_add_error'])
                continue

            # Add them to the pinned message
            for pin in channel.get_pins():
                if pin.content.startswith(
                        self.config.messages['users_in_channel_message']):
                    pin.edit(pin.content + ' <@' + str(message.author.id) +
                             '>')

            # Purge old channels
            self.purgeOldChannels(event.guild.channels)
Ejemplo n.º 5
0
 def compiled(self):
     value = PermissionValue()
     value -= self.deny
     value += self.allow
     return value
Ejemplo n.º 6
0
 def set_permission(self, perm):
     self.perms = PermissionValue(perm)
Ejemplo n.º 7
0
 def __init__(self, id=345):
     self.id = id
     self.perms = PermissionValue(Permissions.ADMINISTRATOR)