This repository has been archived on 2021-03-28. You can view files and clone it, but cannot push or open issues/pull-requests.
frank/frank/modules/help.py

73 lines
1.8 KiB
Python
Raw Normal View History

2020-08-26 13:10:47 +02:00
# =====IMPORTS=====
# Future imports
from __future__ import annotations
# Third-party imports
from discord import Embed
2020-08-26 13:10:47 +02:00
# Own imports
from .. import Module, default, regex_command
2020-08-26 13:10:47 +02:00
# Typing imports
from typing import TYPE_CHECKING
2020-08-26 13:10:47 +02:00
if TYPE_CHECKING:
# Built-in imports
from typing import List
# Third-party imports
from discord.abc import User, Messageable
class HelpMod(Module):
"""
This module sends a help message in a given channel with info about all
other modules.
"""
PREFIX = "help"
NAME = "help"
HELP = "Shows help info about all modules"
2020-08-26 13:10:47 +02:00
@default(help_str="Show help about all modules.")
2020-08-26 13:10:47 +02:00
async def send_all(self, author: User, channel: Messageable, mid: int):
embed = Embed()
2020-08-26 13:10:47 +02:00
for mod in self._client._modules:
embed.add_field(name=mod.NAME, value=mod.HELP, inline=False)
await channel.send(embed=embed)
@regex_command(pattern=".+", help_str="Show help about a certain module.")
async def show_module_help(
self,
prefix: str,
cmd: List[str],
author: User,
channel: Messageable,
mid: int,
):
# Yes, this command just ignores cmd at the moment
mod_name = prefix.lower()
mod = next(
(
mod
for mod in self._client._modules
if mod.NAME.lower() == mod_name
),
None,
)
2020-08-26 13:10:47 +02:00
if mod:
embed = Embed()
2020-08-26 13:10:47 +02:00
if mod.default:
embed.add_field(
name="default", value=mod.default.help_str, inline=False
)
2020-08-26 13:10:47 +02:00
for cmd in mod._COMMANDS:
embed.add_field(name=cmd.cmd, value=mod.help_str, inline=False)
2020-08-26 13:10:47 +02:00
await channel.send(embed=embed)