Ejemplo 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))
Ejemplo n.º 2
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'))
Ejemplo n.º 3
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'))
Ejemplo n.º 4
0
    async def invite(self, ctx, *args):
        settings = Settings.get_for(ctx.guild.id)
        if len(args) < 1:
            return await ctx.send(settings.get_text('missing_target'))
        user_mentions = ctx.message.mentions
        role_mentions = ctx.message.role_mentions
        player = ctx.message.author
        invitees = []
        room = None

        for invitee in user_mentions:
            if invitee.id not in invitees:
                invitees.append(invitee.id)

        for role in role_mentions:
            for member in role.members:
                if member.id not in invitees:
                    invitees.append(member.id)

        player_names = []
        for member in ctx.guild.members:
            player_names.append(member.display_name.lower())
            player_names.append(member.name.lower())

        for arg in args:
            p = discord.utils.find(lambda p: p.name.lower() == arg.lower(),
                                   ctx.guild.members)
            if p and p.id not in invitees:
                invitees.append(p.id)

        rooms = Room.find(guild=ctx.guild.id)
        room_match = None
        if rooms:
            for room_data in rooms:
                r = Room.from_query(room_data)
                if player.id in r.players:
                    room = r
        if not room:
            return await ctx.send(settings.get_text('not_in_room'))

        if not invitees:
            return await ctx.send(settings.get_text('missing_target_invitees'))

        room.update_active()
        embed = discord.Embed(color=discord.Color.blurple(),
                              timestamp=now(),
                              title=choice(
                                  settings.get_text('invite_messages')).format(
                                      player.display_name, room.activity))
        embed.add_field(inline=False,
                        name=room.activity,
                        value=room.description)
        embed.add_field(inline=False,
                        name="{} ({}/{})".format(settings.get_text('players'),
                                                 len(room.players), room.size),
                        value="<@{}>".format(">, <@".join(
                            [str(id) for id in room.players])))
        embed.add_field(
            inline=False,
            name=settings.get_text('inviter') + ": " + player.display_name,
            value=settings.get_text('server') + ": " + ctx.guild.name)
        embed.add_field(inline=True, name=ID_EMOJI, value=room.role_id)
        embed.add_field(inline=True,
                        name=LANGUAGE_EMOJI,
                        value=settings.language)
        embed.set_footer(text=settings.get_text('invite_instructions'),
                         icon_url=discord.Embed.Empty)

        result_embed = discord.Embed(color=discord.Color.blurple(),
                                     description="{}: `{}`".format(
                                         settings.get_text('room'),
                                         room.activity),
                                     timestamp=now(),
                                     title=settings.get_text('invites_sent'))
        result_embed.set_footer(text="{}: {}".format(
            settings.get_text('inviter'), player.display_name),
                                icon_url=discord.Embed.Empty)
        invitee_success = []
        invitee_fail = []
        invitee_already_joined = []
        for invitee_id in invitees:
            try:
                if invitee_id in room.players:
                    invitee_already_joined.append(invitee_id)
                    continue
                invitee = self.bot.get_user(invitee_id)
                m = await invitee.send(embed=embed)
                await m.add_reaction(ACCEPT_EMOJI)
                await m.add_reaction(DECLINE_EMOJI)
                self.invites.insert(dict(user=invitee_id, room=room.role_id))
                invitee_success.append(invitee_id)
            except discord.errors.Forbidden as e:
                invitee_fail.append(invitee_id)

        if invitee_success:
            result_embed.add_field(name=settings.get_text('invitees'),
                                   value="<@{}>".format(">, <@".join(
                                       [str(id) for id in invitee_success])))
        if invitee_fail:
            result_embed.add_field(
                name=settings.get_text('failed_invites'),
                value="{}\n<@{}>".format(
                    settings.get_text('failed_invites_description'),
                    ">, <@".join([str(id) for id in invitee_fail])))
        if invitee_already_joined:
            result_embed.add_field(name=settings.get_text('already_joined'),
                                   value="<@{}>".format(">, <@".join([
                                       str(id) for id in invitee_already_joined
                                   ])))

        return await ctx.send(embed=result_embed)