コード例 #1
0
    async def botinfo(self, ctx, *, bot: IsBot):
        # TODO: I said this 3 months ago to redo this, but im lazy
        titles = (("Bot Prefix", "{0.allprefixes}", BotPrefixes),
                  ("Command Usage", "{0.total_usage}", BotCommands),
                  (("Bot Invited by", "{0.author}"),
                   (("Reason", "reason"), ("Requested at",
                                           'requested_at')), BotAdded))
        embed = BaseEmbed.default(ctx, title=str(bot))
        embed.set_thumbnail(url=bot.avatar.url)
        embed.add_field(name="ID", value=f"`{bot.id}`")
        for title, attrib, converter in reversed(titles):
            with contextlib.suppress(Exception):
                if obj := await converter.convert(ctx, str(bot.id)):
                    if isinstance(attrib, tuple):
                        for t, a in attrib:
                            if dat := getattr(obj, a):
                                dat = dat if not isinstance(
                                    dat,
                                    datetime.datetime) else default_date(dat)
                                embed.add_field(name=t,
                                                value=f"`{dat}`",
                                                inline=False)

                        title, attrib = title
                    embed.add_field(name=title,
                                    value=f"{attrib.format(obj)}",
                                    inline=False)
コード例 #2
0
ファイル: helpful.py プロジェクト: FrostiiWeeb/stella_bot
 def get_command_help(self, command):
     """Returns an Embed version of the command object given."""
     embed = BaseEmbed.default(self.context)
     embed.title = self.get_command_signature(command)
     embed.description = self.get_help(command, brief=False)
     if demo := self.get_demo(command):
         embed.set_image(url=demo)
コード例 #3
0
    async def whatadd(self,
                      ctx,
                      *,
                      author: IsBot(is_bot=False, user_check=False) = None):
        author = author or ctx.author
        if author.bot:
            return await ctx.maybe_reply("That's a bot lol")
        query = "SELECT * FROM {}_bots WHERE author_id=$1"
        total_list = [
            await self.bot.pool_pg.fetch(query.format(x), author.id)
            for x in ("pending", "confirmed")
        ]
        total_list = itertools.chain.from_iterable(total_list)

        async def get_member(b_id):
            return ctx.guild.get_member(b_id) or await self.bot.fetch_user(b_id
                                                                           )

        list_bots = [
            BotAdded.from_json(await get_member(x["bot_id"]), **x)
            for x in total_list
        ]
        embed = BaseEmbed.default(ctx,
                                  title=plural(f"{author}'s bot(s)",
                                               len(list_bots)))
        for dbot in list_bots:
            bot_id = dbot.bot.id
            value = ""
            if bprefix := await try_call(BotPrefixes.convert, ctx,
                                         str(bot_id)):
                value += f"**Most Used Prefix:** `{self.clean_prefix(ctx, bprefix.prefix)}`\n"
            if buse := await try_call(BotCommands.convert, ctx, str(bot_id)):
                high_use = buse.highest_command
                value += f"**Top Command:** `{high_use}`[`{buse.get_command(high_use)}`]\n"
                value += f"**Total Usage:** `{buse.total_usage}`\n"
コード例 #4
0
    async def whatprefix(self, ctx, member: BotPrefix):
        prefix = self.clean_prefix(member.prefix)
        embed = BaseEmbed.default(ctx,
                                  title=f"{member}'s Prefix",
                                  description=f"`{prefix}`")

        await ctx.maybe_reply(embed=embed)
コード例 #5
0
ファイル: myself.py プロジェクト: infofbnr/stella_bot
    async def cogs_handler(self, ctx, method, extensions):
        def do_cog(exts):
            func = getattr(self.bot, f"{method}_extension")
            return func(f"cogs.{exts}")

        outputs = [
            call(do_cog, ext, ret=True) or f"cogs.{ext} is {method}ed"
            for ext in extensions
        ]
        await ctx.maybe_reply(embed=BaseEmbed.default(
            ctx, description="\n".join(str(x) for x in outputs)))
コード例 #6
0
        def each_page(self, menu, entries):
            number = menu.current_page * self.per_page + 1
            list_commands = "\n".join(
                f"{x}. {c}[`{bot.get_command(c)}`]"
                for x, c in enumerate(entries, start=number))
            embed = BaseEmbed.default(
                ctx,
                title=f"{bot} Commands[`{bot.total_usage}`]",
                description=list_commands)
            if owner_info and owner_info.author:
                embed.set_author(icon_url=owner_info.author.avatar.url,
                                 name=f"Owner {owner_info.author}")

            return embed.set_thumbnail(url=bot.bot.avatar.url)
コード例 #7
0
ファイル: helpful.py プロジェクト: Taraxiah/stella_bot
 async def on_information_show(self, payload):
     ctx = self.ctx
     exists = [str(emoji) for emoji in super().buttons]
     embed = BaseEmbed.default(ctx,
                               title="Information",
                               description="This shows each commands in this bot. Each page is a category that shows "
                                           "what commands that the category have.")
     curr = self.current_page + 1 if (p := self.current_page > -1) else "cover page"
     pa = "page" if p else "the"
     embed.set_author(icon_url=ctx.bot.user.avatar.url,
                      name=f"You were on {pa} {curr}")
     nav = '\n'.join(f"{self.dict_emoji[e].emoji} {self.dict_emoji[e].explain}" for e in exists)
     embed.add_field(name="Navigation:", value=nav)
     await self.message.edit(embed=embed, allowed_mentions=discord.AllowedMentions(replied_user=False))
コード例 #8
0
    async def replycount(self, ctx, message: discord.Message):
        def count_reply(m, replies=0):
            if isinstance(m, discord.MessageReference):
                return count_reply(m.cached_message, replies)
            if isinstance(m, discord.Message):
                if not m.reference:
                    return m, replies
                replies += 1
                return count_reply(m.reference, replies)

        msg, count = count_reply(message)
        embed_dict = {
            "title": "Reply Count",
            "description": f"**Original:** `{msg.author}`\n"
                           f"**Message:** `{msg.content}`\n"
                           f"**Replies:** `{count}`\n"
                           f"**Origin:** [`jump`]({msg.jump_url})"
        }
        await ctx.reply(embed=BaseEmbed.default(ctx, **embed_dict), mention_author=False)
コード例 #9
0
 async def recentbotadd(self, ctx):
     def predicate(m):
         return m.bot and m.joined_at > ctx.message.created_at - datetime.timedelta(days=1)
     members = {m.id: m for m in filter(predicate, ctx.guild.members)}
     if not members:
         member = max(filter(lambda x: x.bot, ctx.guild.members), key=lambda x: x.joined_at)
         time_add = humanize.precisedelta(member.joined_at, minimum_unit="minutes")
         await ctx.maybe_reply(
             embed=BaseEmbed.default(
                 ctx,
                 title="Bots added today",
                 description="Looks like there are no bots added in the span of 24 hours.\n"
                             f"The last time a bot was added was `{time_add}` for `{member}`"))
         return
     db_data = await self.bot.pool_pg.fetch("SELECT * FROM confirmed_bots WHERE bot_id=ANY($1::BIGINT[])", list(members))
     member_data = [BotAdded.from_json(bot=members[data["bot_id"]], **data) for data in db_data]
     member_data.sort(key=lambda x: x.joined_at)
     menu = MenuBase(source=BotAddedList(member_data), delete_message_after=True)
     await menu.start(ctx)
コード例 #10
0
    async def whatadd(self, ctx, author: discord.Member = None):
        if not author:
            author = ctx.author
        if author.bot:
            return await ctx.maybe_reply("That's a bot lol")
        query = "SELECT * FROM {}_bots WHERE author_id=$1"
        total_list = [await self.bot.pool_pg.fetch(query.format(x), author.id) for x in ("pending", "confirmed")]
        total_list = itertools.chain.from_iterable(total_list)

        async def get_member(b_id):
            return ctx.guild.get_member(b_id) or await self.bot.fetch_user(b_id)
        list_bots = [BotAdded.from_json(await get_member(x["bot_id"]), **x) for x in total_list]
        embed = BaseEmbed.default(ctx, title=plural(f"{author}'s bot(s)", len(list_bots)))
        for dbot in list_bots:
            bot_id = dbot.bot.id
            value = ""
            if buse := await try_call(BotUsage.convert, ctx, str(bot_id)):
                value += f"**Usage:** `{buse.count}`\n"
            if bprefix := await try_call(BotPrefix.convert, ctx, str(bot_id)):
                value += f"**Prefix:** `{self.clean_prefix(bprefix.prefix)}`\n"
コード例 #11
0
ファイル: error_handler.py プロジェクト: infofbnr/stella_bot
            else:
                await send_del(embed=BaseEmbed.to_error(description=f"{error}")
                               )
                traceback_error = print_exception(
                    f'Ignoring exception in command {ctx.command}:', error)
                if not self.bot.tester:
                    error_message = f"**Command:** {ctx.message.content}\n" \
                                    f"**Message ID:** `{ctx.message.id}`\n" \
                                    f"**Author:** `{ctx.author}`\n" \
                                    f"**Guild:** `{ctx.guild}`\n" \
                                    f"**Channel:** `{ctx.channel}`\n" \
                                    f"**Jump:** [`jump`]({ctx.message.jump_url})```py\n" \
                                    f"{traceback_error}\n" \
                                    f"```"
                    await self.bot.error_channel.send(
                        embed=BaseEmbed.default(ctx, description=error_message)
                    )

    async def generate_signature_error(self, ctx, error):
        command = ctx.command
        argument = ""
        found = False

        def check_converter(_error):
            if isinstance(_error, commands.BadArgument):
                frames = [*traceback.walk_tb(_error.__traceback__)]
                last_trace = frames[-1]
                frame = last_trace[0]
                converter = frame.f_locals["self"]
                return getattr(
                    discord,
コード例 #12
0
    async def botuse(self, ctx, bot: BotUsage):
        embed = BaseEmbed.default(ctx,
                                  title=f"{bot}'s Usage",
                                  description=plural(f"`{bot.count}` command(s) has been called for **{bot}**.", bot.count))

        await ctx.maybe_reply(embed=embed)
コード例 #13
0
 async def prefixbot(self, ctx, prefix):
     instance_bot = await self.get_all_prefix(ctx.guild, prefix)
     list_bot = "\n".join(f"`{no + 1}. {x}`" for no, x in enumerate(instance_bot)) or "`Not a single bot have it.`"
     prefix = self.clean_prefix(prefix)
     desk = f"Bot(s) with `{prefix}` as prefix\n{list_bot}"
     await ctx.maybe_reply(embed=BaseEmbed.default(ctx, description=plural(desk, len(list_bot))))
コード例 #14
0
 async def prefixuse(self, ctx, prefix):
     instance_bot = await self.get_all_prefix(ctx.guild, prefix)
     prefix = self.clean_prefix(prefix)
     desk = plural(f"There (is/are) `{len(instance_bot)}` bot(s) that use `{prefix}` as prefix", len(instance_bot))
     await ctx.maybe_reply(embed=BaseEmbed.default(ctx, description=desk))
コード例 #15
0
                           "Useful for finding out who's the annoying person that uses common prefix help command.")
    async def recenthelptrigger(self, ctx):
        if message := self.help_trigger.get(ctx.channel.id):
            embed_dict = {
                "title": "Recent Help Trigger",
                "description": f"**Author:** `{message.author}`\n"
                               f"**Message ID:** `{message.id}`\n"
                               f"**Command:** `{message.content}`\n"
                               f"**Message Link:** [`jump`]({message.jump_url})",
            }
        else:
            embed_dict = {
                "title": "Recent Help Trigger",
                "description": "There is no help command triggered recently."
            }
        await ctx.maybe_reply(embed=BaseEmbed.default(ctx, **embed_dict))

    @commands.command(aliases=["br", "brrrr", "botranks", "botpos", "botposition", "botpositions"],
                      help="Shows all bot's command usage in the server on a sorted list.")
    async def botrank(self, ctx, bot: BotUsage = None):
        bots = {x.id: x for x in ctx.guild.members if x.bot}
        query = "SELECT * FROM bot_usage_count WHERE bot_id=ANY($1::BIGINT[])"
        record = await self.bot.pool_pg.fetch(query, list(bots))
        bot_data = [BotUsage(bots[r["bot_id"]], r["count"]) for r in record]
        bot_data.sort(key=lambda x: x.count, reverse=True)
        if not bot:
            menu = MenuBase(source=AllBotCount(bot_data), delete_message_after=True)
            await menu.start(ctx)
        else:
            key = "(\u200b|\u200b)"
            idx = [*map(int, bot_data)].index(bot.bot.id)
コード例 #16
0
 def each_page(self, menu, entries):
     number = menu.current_page * self.per_page + 1
     list_commands = "\n".join(f"{x}. {c}" for x, c in enumerate(entries, start=number))
     embed = BaseEmbed.default(ctx, title=f"{bot} Commands", description=list_commands)
     return embed.set_thumbnail(url=bot.bot.avatar_url)