Exemplo n.º 1
0
    async def purge(self, ctx, *args):
        settings = Settings.get_for(ctx.guild.id)
        player = ctx.message.author
        if not player.guild_permissions.administrator:
            return await ctx.send(settings.get_text('not_admin'))

        (flags, words) = pop_flags(args)
        if 'a' not in flags and 'b' not in flags:
            return await ctx.send(settings.get_text('purge_missing_flag'))

        if 'a' in flags:
            rooms_data = Room.find(guild=ctx.guild.id)
            count = 0
            for room_data in rooms_data:
                r = Room.from_query(room_data)
                guild = self.bot.get_guild(r.guild)
                await r.disband(guild)
                count += 1
            await ctx.send(settings.get_text('purged_a').format(count))

        if 'b' in flags:
            deleted_channels = 0
            deleted_roles = 0
            failed_channels = 0
            failed_roles = 0
            category = discord.utils.get(player.guild.categories,
                                         name=settings.category_name)
            if not category:
                return await ctx.send(settings.get_text('no_category'))
            for channel in category.channels:
                if iter_len(
                        Room.find(guild=ctx.guild.id,
                                  channel_id=channel.id)) < 1:
                    try:
                        await channel.delete()
                        deleted_channels += 1
                    except:
                        failed_channels += 1
            for role in ctx.guild.roles:
                if iter_len(Room.find(guild=ctx.guild.id,
                                      role_id=role.id)) < 1:
                    if any([
                            role.name.startswith('({})'.format(
                                get_text('room', lang=l))) for l in langs
                    ]):
                        try:
                            await role.delete()
                            deleted_roles += 1
                        except:
                            failed_roles += 1

            await ctx.send(
                settings.get_text('purged_b').format(deleted_channels,
                                                     deleted_roles))
            if failed_channels > 0 or failed_roles > 0:
                await ctx.send(
                    settings.get_text('purged_b_fail').format(
                        failed_channels, failed_roles))
Exemplo n.º 2
0
    async def try_invite_response(self, reaction, user):
        channel = reaction.message.channel
        accept = str(reaction.emoji) == ACCEPT_EMOJI
        decline = str(reaction.emoji) == DECLINE_EMOJI
        valid_invite_emoji = accept or decline
        from_dm = type(channel) is discord.channel.DMChannel
        room_id = None
        lang = langs[0]
        for field in reaction.message.embeds[0].fields:
            if field.name == ID_EMOJI:
                room_id = field.value
            elif field.name == LANGUAGE_EMOJI:
                lang = field.value
        search = self.invites.find_one(user=user.id, room=room_id)

        if not valid_invite_emoji or not search or not from_dm:
            return

        room = None
        room_data = Room.find_one(role_id=room_id)
        if room_data:
            room = Room.from_query(room_data)
        if not room:
            return await channel.send(get_text('room_not_exist', lang=lang))

        self.invites.delete(user=user.id, room=room_id)
        settings = Settings.get_for(room.guild)

        if (accept):
            room_channel = self.bot.get_channel(room.channel_id)
            guild = self.bot.get_guild(room.guild)
            member = guild.get_member(user.id)
            if not room_channel or not guild or not member:
                return await channel.send(get_text('room_not_exist',
                                                   lang=lang))
            await channel.send(get_text('invite_accepted', lang=lang))
            room.lock = False
            joined = await self.try_join(room_channel, room, member)
            if joined:
                await RoomEmbed(reaction.message, room, 'room_joined',
                                settings).send()
            else:
                await channel.send(settings.get_text('retry_error'))
        else:
            await channel.send(get_text('invite_declined', lang=lang))
Exemplo n.º 3
0
    async def force_disband(self, ctx, *args):
        settings = Settings.get_for(ctx.guild.id)
        rooms = Room.find(guild=ctx.guild.id)
        activity_filter = " ".join(args) if args else None
        role_mention_filter = ctx.message.role_mentions[
            0].id if ctx.message.role_mentions else None

        rooms = Room.find(guild=ctx.guild.id)
        if rooms:
            for room_data in rooms:
                r = Room.from_query(room_data)
                if r.activity == activity_filter or r.role_id == role_mention_filter:
                    await r.disband(ctx.guild)
                    try:
                        await ctx.send(
                            settings.get_text('disband_room').format(
                                '<@' + str(r.host) + '>', r.activity))
                    except discord.errors.NotFound as e:
                        pass
                    return
        return await ctx.send(settings.get_text('room_not_exist'))
Exemplo n.º 4
0
    async def ls(self, ctx):
        settings = Settings.get_for(ctx.guild.id)
        rooms = Room.find(guild=ctx.guild.id)
        embed = discord.Embed(color=discord.Color.blurple())
        count = 0

        for room_data in rooms:
            count += 1
            room = Room.from_query(room_data)

            description = room.description if room.description else "{}: {}".format(
                settings.get_text('players'), ', '.join(room.players))
            embed.add_field(name="{}{} ({}/{})".format(
                ":lock: " if room.lock else "", room.activity,
                len(room.players), room.size),
                            value=description,
                            inline=False)
        if count > 0:
            embed.title = "{} ({})".format(settings.get_text('rooms'), count)
            await ctx.send(embed=embed)
        else:
            await ctx.send(settings.get_text('no_rooms'))