Ejemplo n.º 1
0
    async def _create_anonc_chat_channel(self, guild, member) -> AnoncChannel:
        overwrites = {
            guild.default_role:
            PermissionOverwrite.from_pair(
                Permissions.none(),  # allow
                Permissions.all()  # deny
            ),
            member:
            PermissionOverwrite(send_messages=True,
                                read_messages=True,
                                manage_messages=True,
                                attach_files=True,
                                read_message_history=True)
        }

        anonc_id = random_string(4)
        while self.get_anonc_chat_channel_from_anonc_id(anonc_id):
            anonc_id = random_string(4)

        anonc_id_role = None
        if self.use_role:
            anonc_id_role = await guild.create_role(name=anonc_id,
                                                    mentionable=True)

        channel = await guild.create_text_channel('anon chat',
                                                  overwrites=overwrites,
                                                  topic=anonc_id,
                                                  nsfw=self.nsfw)
        webhook = await channel.create_webhook(name=str(member.id))

        return AnoncChannel(channel, webhook, member, anonc_id_role)
Ejemplo n.º 2
0
async def untrap(member, guild, prev_roles, exclude):
    for channel in filterfalse(exclude.__contains__, guild.voice_channels):
        try:
            special_perms = PermissionOverwrite.from_pair(*prev_roles[channel]) if channel in prev_roles \
                else PermissionOverwrite()
            # noinspection PyUnresolvedReferences
            await channel.set_permissions(member, overwrite=special_perms)
            logger.debug(
                "changing {0.name} from guild {1.id} roles in channel {2.name} "
                "to allow={3}, deny={4}".format(member, guild, channel,
                                                special_perms.pair()[0].value,
                                                special_perms.pair()[1].value))
        except discord.errors.Forbidden:
            pass