示例#1
0
    def __init__(self, bot: LightningBot, record: dict):
        self.id = record['id']

        self.guild = bot.get_guild(record['guild_id']) or record['guild_id']
        self.user = bot.get_user(record['user_id']) or record['user_id']
        self.moderator = bot.get_user(
            record['moderator_id']) or record['user_id']

        self.action = ActionType(record['action'])
        self.reason = record['reason']
        self.created_at = record['created_at']
        self.active = record['active']
        self.extra = record['extra']
示例#2
0
 def __init__(self, bot: LightningBot):
     self.bot = bot
     self.original_help_command = bot.help_command
     bot.help_command = PaginatedHelpCommand()
     bot.help_command.cog = self
     self.unavailable_guilds = []
     self.process = psutil.Process()
示例#3
0
def build_command_docs():
    """Builds documentation for commands and stores them in the build directory"""
    bot = LightningBot()
    for command in bot.walk_commands():
        description = command.description or command.help
        flag_fmt = ""
        signature = command.signature or command.usage
        subcmd_fmt = ""

        if hasattr(command.callback, "__lightning_argparser__"):
            flags = command.callback.__lightning_argparser__.get_all_unique_flags(
            )
            flag_fmt = flag_page.format(flags=format_command_flags(flags))

        # This is a group
        if hasattr(command, "commands"):
            subcmd_fmt = subcmds_page.format(
                subcmds=format_subcommands(command.commands))

        fmt = command_page.format(
            name=command.qualified_name,
            signature=signature.strip() or "",
            description=description.replace("\n", "<br>")
            if description else "",
            aliases=format_command_aliases(command.aliases),
            params=format_command_params(command.clean_params),
            flags=flag_fmt,
            subcmds=subcmd_fmt)

        fname = command.qualified_name.replace(" ", "_")

        if command.cog:
            cog = command.cog.qualified_name.lower()
        else:
            cog = "not_categorized"

        path = pathlib.Path(f"build/docs/commands/{cog}/")
        path.mkdir(parents=True, exist_ok=True)
        path = path / pathlib.Path(f"{fname}.md")
        with path.open("w", encoding="utf-8") as fp:
            fp.write(fmt)

        typer.echo(f"Built {command.qualified_name} page ({str(path)})")

    typer.echo("Built all command pages!")
示例#4
0
def build_cog_docs():
    """Builds documentation pages for cogs and stores them in the build directory"""
    bot = LightningBot()
    cogs = sorted(bot.cogs.values(), key=lambda c: c.qualified_name)
    for cog in cogs:
        cmds = []

        for command in sorted(cog.walk_commands(),
                              key=lambda c: c.qualified_name):
            aliases = ' '.join("`{}`".format(r)
                               for r in command.aliases) or "None"
            signature = command.signature or command.usage
            usage = f".{command.qualified_name}"
            if signature:
                usage += f" {signature}"

            if command.cog:
                cog_name = command.cog.qualified_name.lower()
            else:
                cog_name = "not_categorized"

            description = command.help.replace(
                '\n', '<br>') if command.help else None

            link = f'https://lightning-bot.gitlab.io/commands/{cog_name}/'\
                   f'{command.qualified_name.lower().replace(" ", "_")}'

            cmds.append((f"[{command.qualified_name}]({link})", aliases,
                         description, f"`{usage}`"))

        path = pathlib.Path(
            f"build/docs/commands/{cog.qualified_name.lower()}")
        path.mkdir(parents=True, exist_ok=True)
        path = path / pathlib.Path(
            "index.md")  # There should never be a command called "index"

        desc = (cog.qualified_name, cog.description,
                tabulate(cmds,
                         headers=("Name", "Aliases", "Description", "Usage"),
                         tablefmt="github"))
        fmt = "# {}\n{}\n\n{}\n\n".format(desc[0], desc[1], desc[2])
        with path.open("w", encoding="utf-8") as fp:
            fp.write(fmt)

        typer.echo(f"Built {cog.qualified_name} page ({str(path)})")

    typer.echo("Built all cog pages!")
示例#5
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Switchy(bot))
示例#6
0
def setup(bot: LightningBot):
    bot.add_cog(Meta(bot))
    # Remove support command if not in config
    if bot.config['bot'].get("support_server_invite", None) is None:
        bot.remove_command("support")
示例#7
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Configuration(bot))

    if "beta_prefix" in bot.config['bot']:
        bot.remove_command("config prefix")
示例#8
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Homebrew(bot))
示例#9
0
def setup(bot: LightningBot):
    bot.add_cog(Roles(bot))
示例#10
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Git(bot))
示例#11
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Infractions(bot))
示例#12
0
def setup(bot: LightningBot):
    bot.add_cog(Misc(bot))
示例#13
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Emoji(bot))
示例#14
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(ListenerEvents(bot))
示例#15
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(ModLog(bot))
示例#16
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Memes(bot))
示例#17
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Activities(bot))
示例#18
0
def setup(bot: LightningBot):
    bot.add_cog(API(bot))
示例#19
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Stats(bot))
示例#20
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(Owner(bot=bot))
示例#21
0
def setup(bot: LightningBot) -> None:
    bot.add_cog(FeaturesListeners(bot))