Пример #1
0
    async def get_command_embeds(self, ctx: naff.PrefixedContext,
                                 command: naff.PrefixedCommand):
        if not command.parent and not await self._custom_can_run(ctx, command):
            return []

        command_name_fmt = ""
        if command.parent:
            command_name_fmt = f"{command.parent.qualified_name.replace('_', '-')} "

        if command.aliases:
            aliases = "|".join(a.replace("_", "-") for a in command.aliases)
            fmt = f"[{command.name.replace('_', '-')}|{aliases}]"
        else:
            fmt = f"{command.name.replace('_', '-')}"

        command_name_fmt += fmt
        signature = f"{command_name_fmt} {command.signature}"

        if command.is_subcommand:
            return await self.get_multi_command_embeds(
                ctx, list(command.all_subcommands), signature, command.help)
        else:
            return [
                naff.Embed(title=signature,
                           description=command.help,
                           color=ctx.bot.color)
            ]
Пример #2
0
async def callback(ctx: naff.ComponentContext):
    """Shows how to use the bot"""

    embed = naff.Embed(color=ctx.bot.color)

    embed.title = "Using this command"
    embed.description = "Hello! Welcome to the help page."

    entries = (
        ("<argument>", "This means the argument is __**required**__."),
        ("[argument]", "This means the argument is __**optional**__."),
        ("[A|B]", "This means that it can be __**either A or B**__."),
        (
            "[argument...]",
            "This means you can have multiple arguments.\n"
            "Now that you know the basics, it should be noted that...\n"
            "__**You do not type in the brackets!**__",
        ),
    )

    embed.add_field(
        name="How do I use this bot?",
        value="Reading the bot signature is pretty simple.",
    )

    for name, value in entries:
        embed.add_field(name=name, value=value, inline=False)

    await ctx.send(embed=embed, ephemeral=True)
Пример #3
0
    async def get_multi_command_embeds(
        self,
        ctx: naff.PrefixedContext,
        commands: list[naff.PrefixedCommand],
        name: str,
        description: typing.Optional[str],
    ):
        embeds: list[naff.Embed] = []

        command_name_set = {c.name for c in commands}
        commands = [
            c for c in commands
            if getattr(c.parent, "name", None) not in command_name_set
            and await self._custom_can_run(ctx, c)
        ]
        if not commands:
            return []

        chunks = [commands[x:x + 9] for x in range(0, len(commands), 9)]
        multiple_embeds = len(chunks) > 1

        for index, chunk in enumerate(chunks):
            embed = naff.Embed(description=description, color=ctx.bot.color)

            embed.add_field(
                name="Support",
                value=("For more help, join the official support server:"
                       " https://discord.gg/NSdetwGjpK"),
                inline=False,
            )
            embed.set_footer(
                text=
                f'Use "{ctx.prefix}help command" for more info on a command.')

            embed.title = f"{name} - Page {index + 1}" if multiple_embeds else name
            for cmd in chunk:
                signature = f"{cmd.qualified_name.replace('_', '-')} {cmd.signature}"
                embed.add_field(name=signature,
                                value=cmd.brief or "No help given.",
                                inline=False)

            embeds.append(embed)

        return embeds
Пример #4
0
    async def view_guild(
        self,
        ctx: utils.RealmContext,
        guild_id: str,
    ):
        guild = self.bot.get_guild(int(guild_id))
        guild_config = await GuildConfig.get(guild_id=int(guild_id))

        prefixes = tuple(f"`{p}`" for p in guild_config.prefixes)

        embed = naff.Embed(color=self.bot.color,
                           title=f"Server Config for {guild.name}:")
        playerlist_channel = (
            f"<#{guild_config.playerlist_chan}> ({guild_config.playerlist_chan})"
            if guild_config.playerlist_chan else "None")
        embed.description = (
            f"Club ID: {guild_config.club_id}\n" +
            f"Playerlist Channel: {playerlist_channel}\nOnline Command Enabled?"
            f" {guild_config.online_cmd}\nPrefixes: {', '.join(prefixes)}")

        await ctx.send(embed=embed)
Пример #5
0
    async def online(self, ctx: utils.RealmContext):
        """Allows you to see if anyone is online on the Realm right now."""
        # uses much of the same code as playerlist

        guild_config = await ctx.fetch_config()
        now = naff.Timestamp.utcnow()

        club_presence = await self.realm_club_get(guild_config.club_id)
        if club_presence is None:
            # this can happen
            await ctx.send(
                "Seems like the playerlist command failed somehow. Astrea "
                + "should have the info needed to see what's going on."
            )
            return
        elif club_presence == "Unauthorized":
            await utils.msg_to_owner(self.bot, ctx.guild)
            await ctx.send(
                "The bot can't seem to read your Realm! If you changed Realms, make"
                " sure to let Astrea know. Also, make sure you haven't banned the"
                " bot's Xbox account from the Realm. If you haven't done either,"
                " this is probably just internal stuff being weird, and it'll fix"
                " itself in a bit."
            )
            return

        player_list = await self.get_players_from_club_data(
            club_presence, online_only=True
        )

        if online_list := [p.display for p in player_list]:
            embed = naff.Embed(
                color=self.bot.color,
                title=f"{len(online_list)}/10 people online",
                description="\n".join(online_list),
                timestamp=now,
            )
            embed.set_footer(text="As of")
            await ctx.send(embed=embed)
Пример #6
0
def error_embed_generate(error_msg):
    return naff.Embed(color=naff.MaterialColors.RED, description=error_msg)
Пример #7
0
    async def playerlist(
        self,
        ctx: utils.RealmContext | utils.RealmPrefixedContext,
        hours_ago: str = "12",
        **kwargs,
    ):
        """Checks and makes a playerlist, a log of players who have joined and left.
        By default, the command version goes back 12 hours.
        If you wish for it to go back more, simply do `!?playerlist <# hours ago>`.
        The number provided should be in between 1-24 hours.
        The autorun version only goes back 2 hours.

        Has a cooldown of 4 minutes due to how intensive this command can be.
        May take a while to run at first.
        Requires Manage Server permissions."""

        actual_hours_ago: int = int(hours_ago)
        guild_config = await ctx.fetch_config()

        now = naff.Timestamp.utcnow()

        time_delta = datetime.timedelta(hours=actual_hours_ago)
        time_ago = now - time_delta

        club_presence = await self.realm_club_get(guild_config.club_id)
        if club_presence is None:
            # this can happen
            await ctx.send(
                "Seems like the playerlist command failed somehow. Astrea should "
                + "have the info needed to see what's going on."
            )
            return
        elif club_presence == "Unauthorized":
            await utils.msg_to_owner(self.bot, ctx.guild)
            await ctx.send(
                "The bot can't seem to read your Realm! If you changed Realms, make"
                " sure to let Astrea know. Also, make sure you haven't banned the"
                " bot's Xbox account from the Realm. If you haven't done either,"
                " this is probably just internal stuff being weird, and it'll fix"
                " itself in a bit."
            )
            return

        player_list = await self.get_players_from_club_data(
            club_presence, time_ago=time_ago
        )

        online_list = [p.display for p in player_list if p.in_game]
        offline_list = [p.display for p in player_list if not p.in_game]

        if online_list:
            embed = naff.Embed(
                color=self.bot.color,
                title="People online right now",
                description="\n".join(online_list),
                timestamp=now,
            )
            embed.set_footer(text="As of")
            await ctx.send(embed=embed)

        if offline_list:
            # gets the offline list in lines of 40
            # basically, it's like
            # [ [list of 40 strings] [list of 40 strings] etc.]
            chunks = [offline_list[x : x + 40] for x in range(0, len(offline_list), 40)]

            first_embed = naff.Embed(
                color=naff.Color.from_hex("95a5a6"),
                description="\n".join(chunks[0]),
                title=f"People on in the last {actual_hours_ago} hour(s)",
                timestamp=now,
            )
            first_embed.set_footer(text="As of")
            await ctx.send(embed=first_embed)

            for chunk in chunks[1:]:
                embed = naff.Embed(
                    color=naff.Color.from_hex("95a5a6"),
                    description="\n".join(chunk),
                    timestamp=now,
                )
                embed.set_footer(text="As of")
                await ctx.send(embed=embed)
                await asyncio.sleep(0.2)

        if not kwargs.get("no_init_mes") and not online_list and not offline_list:
            raise utils.CustomCheckFailure(
                "No one has been on the Realm for the last "
                + f"{actual_hours_ago} hour(s)."
            )