예제 #1
0
    async def about(self, ctx: commands.Context):
        """
        View info of the bot
        """
        data = {
            "id": self.bot.user.id,
            "owner": "StarrFox#6312",
            "created": humanize.naturaldate(self.bot.user.created_at),
            "up since": humanize.naturaltime(self.bot.uptime),
            "guilds": len(self.bot.guilds),
            "commands": len(set(self.bot.walk_commands())),
            "dc version": dc_version,
            "d.py version": discord.__version__,
        }

        events_cog = self.bot.get_cog("events")

        if events_cog:
            data.update({
                "events seen":
                "{:,}".format(sum(events_cog.socket_events.values()))
            })

        paginator = PrologPaginator()

        paginator.recursively_add_dictonary({self.bot.user.name: data})

        source = NormalPageSource(paginator.pages)

        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #2
0
    async def memberinfo(self,
                         ctx: commands.Context,
                         member: FetchedMember = None):
        """
        Get info on a guild member
        """
        if member is None:
            member = await ctx.guild.fetch_member(ctx.author.id)

        data = {
            "id": member.id,
            "top role": member.top_role.name,
            "joined guild": humanize.naturaldate(member.joined_at),
            "joined discord": humanize.naturaldate(member.created_at),
        }

        paginator = PrologPaginator()

        paginator.recursively_add_dictonary({member.name: data})

        source = NormalPageSource(paginator.pages)

        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #3
0
    async def guildinfo(self, ctx: commands.Context):
        """
        Get info on a guild
        """
        guild = ctx.guild
        bots = len([m for m in guild.members if m.bot])
        humans = guild.member_count - bots

        data = {
            "id": guild.id,
            "owner": str(guild.owner),
            "created": humanize.naturaltime(guild.created_at),
            "# of roles": len(guild.roles),
            "members": {"humans": humans, "bots": bots, "total": guild.member_count},
            "channels": {
                "categories": len(guild.categories),
                "text": len(guild.text_channels),
                "voice": len(guild.voice_channels),
                "total": len(guild.channels),
            },
        }

        paginator = PrologPaginator()

        paginator.recursively_add_dictonary({guild.name: data})

        source = NormalPageSource(paginator.pages)

        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #4
0
    async def show(self, ctx, *, bot: BotConverter()):
        """
        Show the ratings of a bot.
        """
        ratings = await self.get_bot_ratings(bot.id)

        if not ratings:
            return await ctx.send("No ratings for this bot.")

        title = f"Ratings for {bot}"

        average_holder = []
        entries = []

        for user_id, rating, review in ratings:
            user = ctx.bot.get_user(user_id)
            if not user:
                await self.clear_bot_rating(bot.id, user_id)
                continue

            entries.append(self.format_rating(user, rating, review))
            average_holder.append(rating)

        average = round(sum(average_holder) / len(average_holder), 2)

        description = f"Average: {average}"

        source = EmbedFieldsPageSource(
            entries, per_page=3, title=title, description=description
        )

        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #5
0
    async def send_raw(ctx: commands.Context, data: dict):

        paginator = PartitionPaginator(prefix="```json", max_size=1985)
        to_send = json.dumps(data, indent=4)
        paginator.add_line(to_send)
        source = NormalPageSource(paginator.pages)
        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #6
0
    async def jsk_python(self, ctx: SubContext, *,
                         argument: codeblock_converter):
        arg_dict = get_var_dict_from_ctx(ctx, SCOPE_PREFIX)
        arg_dict["_"] = self.last_result

        scope = self.scope

        try:
            async with ReplResponseReactor(ctx.message):
                with self.submit(ctx):
                    executor = AsyncCodeExecutor(argument.content,
                                                 scope,
                                                 arg_dict=arg_dict)
                    async for send, result in AsyncSender(executor):
                        if result is None:
                            continue

                        self.last_result = result

                        if isinstance(result, discord.File):
                            send(await ctx.send(file=result))
                        elif isinstance(result, discord.Embed):
                            send(await ctx.send(embed=result))
                        elif isinstance(result, PaginatorInterface):
                            send(await result.send_to(ctx))
                        elif isinstance(result, DCMenuPages):
                            send(await result.start(ctx))
                        else:
                            if not isinstance(result, str):
                                # repr all non-strings
                                result = repr(result)

                            result = result.replace(self.bot.http.token,
                                                    "[token omitted]")
                            if result.strip() == "":
                                result = "[empty string]"

                            if len(result) > 2000:
                                paginator = PartitionPaginator(prefix="```py")

                                paginator.add_line(result)

                                source = NormalPageSource(paginator.pages)

                                menu = DCMenuPages(source)

                                send(await menu.start(ctx))

                            else:
                                send(await ctx.send(f"```py\n{result}```"))

        finally:
            scope.clear_intersection(arg_dict)
예제 #7
0
    async def socketstats(self, ctx: commands.Context):
        """
        View soketstats of the bot
        """
        events_cog = self.bot.get_cog("events")
        socket_events = events_cog.socket_events
        total = sum(socket_events.values())
        paginator = PrologPaginator(align_places=20)
        paginator.recursively_add_dictonary(
            {f"{total:,} total": socket_events})
        source = NormalPageSource(paginator.pages)
        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #8
0
    async def prefix(self, ctx: commands.Context):
        """
        Base prefix command,
        Lists prefixes
        """
        prefixes = [
            f"{idx}. `{prefix}`"
            for idx, prefix in enumerate(self.bot.prefixes[ctx.guild.id], 1)
        ]

        source = CodeblockPageSource(prefixes, per_page=5)

        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #9
0
    async def guildinfo(self, ctx: commands.Context):
        """
        Get info on a guild
        """
        guild = await self.bot.fetch_guild(ctx.guild.id)

        # I don't have guild.channels
        channels = await guild.fetch_channels()

        data = {
            "id": guild.id,
            "owner": str(await self.bot.fetch_user(guild.owner_id)),
            "created": humanize.naturaltime(guild.created_at),
            "# of roles": len(guild.roles),
            "members": guild.approximate_member_count,
            "channels": {
                "categories":
                len([
                    c for c in channels
                    if isinstance(c, discord.CategoryChannel)
                ]),
                "text":
                len([
                    c for c in channels if isinstance(c, discord.TextChannel)
                ]),
                "voice":
                len([
                    c for c in channels if isinstance(c, discord.VoiceChannel)
                ]),
                "total":
                len(channels),
            },
        }

        paginator = PrologPaginator()
        paginator.recursively_add_dictonary({guild.name: data})
        source = NormalPageSource(paginator.pages)
        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #10
0
    async def charinfo(self, ctx: commands.Context, *, characters):
        """
        Convert characters to name syntax, or unicode if name isn't found.
        """
        paginator = PartitionPaginator(
            prefix=None, suffix=None, max_size=300, wrap_on=("}", "\n")
        )

        final = ""
        for char in characters:
            try:
                name = unicodedata.name(char)
                final += f"\\N{{{name}}}\n"
            except ValueError:
                final += f"\\U{ord(char):0>8x}\n"

        paginator.add_line(final)

        source = NormalPageSource(paginator.pages)

        menu = DCMenuPages(source)

        await menu.start(ctx)
예제 #11
0
    async def jsk_db(self, ctx: commands.Context, *, quarry: str):
        """
        Execute a db quarry
        """
        async with db.get_database() as connection:
            try:
                cursor = await connection.execute(quarry)
            except OperationalError as e:
                return await ctx.send(str(e))

            await connection.commit()
            quarry_result = await cursor.fetchall()

            if quarry_result:
                collums = [coll[0] for coll in cursor.description]
                final = [collums]

                for data in quarry_result:
                    final.append(list(data))

                table = AsciiTable(final)

                paginator = PartitionPaginator(prefix="```sql",
                                               max_size=1000,
                                               wrap_on=("|", "\n"))

                paginator.add_line(table.table)

                source = NormalPageSource(paginator.pages)

                menu = DCMenuPages(source)

                await menu.start(ctx)

            else:
                await ctx.send("[no result]")
예제 #12
0
    async def snipe_command(self, ctx: commands.Context, **options: dict):
        """
        Snipe delete/edited messages from your server.

        Optional:
        --authors: List of members that authored the snipe
        --channel: Channel to snipe from
        --server: Snipe from the entire server instead of just a channel
        --before: Message id that snipes must be before
        --after: Message id that snipes must be after
        --list: Show all snipes found instead of one
        --mode: Mode of the snipes (edited, deleted, purged)
        --contains: String that must be in the snipes

        Positional:
        index: Index to show from returned snipes, defaults to 0

        Nsfw (if not used from one) and channels you can't view are auto filtered out.
        """
        print(options)
        if options["channel"] is None:
            channel = ctx.channel
        else:
            channel = options["channel"]

        # These are filtered out by get_snipes anyway
        if not ctx.channel.is_nsfw() and channel.is_nsfw():
            return await ctx.send(
                "You cannot snipe a nsfw channel from a non-nsfw channel.")

        if isinstance(ctx.author, discord.User):
            author = await ctx.guild.fetch_member(ctx.author.id)
        else:
            author = ctx.author

        if not channel.permissions_for(author).read_messages:
            return await ctx.send(
                "You need permission to view a channel to snipe from it.")

        # noinspection PyTypeChecker
        snipes = self.get_snipes(
            command_author=author,
            command_channel=ctx.channel,
            channel=channel,
            guild=options["guild"],
            authors=options["authors"],
            before=options["before"],
            after=options["after"],
            mode=SnipeMode[options["mode"]] if options["mode"] else None,
            contains=options["contains"],
        )

        if not snipes:
            return await ctx.send("No snipes found for this search.")

        if options["list"]:
            proxies = self.get_proxy_fields(snipes)

            # 5 * 1,024 = 5,120‬ + 500 (names) = 5,620 < 6000 (max embed size)
            source = EmbedFieldsPageSource(proxies, per_page=5)

            menu = DCMenuPages(source)

            await menu.start(ctx)

        else:
            try:
                # noinspection PyTypeChecker
                snipe = snipes[options["index"]]
            except IndexError:
                return await ctx.send("Index out of bounds.")

            e = discord.Embed(title=str(snipe), description=snipe.content)

            e.set_footer(text=f"{options['index']}/{len(snipes) - 1}")

            await ctx.send(embed=e)