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

66 lines
1.8 KiB
Python

# =====IMPORTS=====
# Future imports
from __future__ import annotations
# Third-party imports
import discord
# Own imports
from suzybot.frank import Module, default, command
# Typing imports
from typing import TYPE_CHECKING
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'
def pre_start(self):
self.theme = discord.Color.dark_green()
@default(help_str='Show help about all modules.')
async def send_all(self, author: User, channel: Messageable, mid: int):
embed = discord.Embed(colour=self.theme)
embed.set_author(name='Suzy')
for mod in self._client._modules:
embed.add_field(name=mod.NAME, value=mod.HELP, inline=False)
await channel.send(embed=embed)
@command(cmd='.+', help_str='Show help about a certain module.')
async def show_module_help(self, cmd: List[str], author: User,
channel: Messageable, mid: int):
# Exit if no arguments are given
if not cmd:
return
mod_name = cmd[0].lower()
mod = next((mod for mod in self._client._modules
if mod.NAME.lower() == mod_name), None)
if mod:
embed = discord.Embed(colour=self.theme)
if mod._DEFAULT:
embed.add_field(name='default', value=mod._help, inline=False)
for cmd in mod._COMMANDS:
embed.add_field(name=cmd._command, value=mod._help,
inline=False)
await channel.send(embed=embed)