Added help module
parent
46d8d4322e
commit
491bb74768
|
@ -1 +1,6 @@
|
|||
from .test import TestMod
|
||||
from .help import HelpMod
|
||||
|
||||
|
||||
__all__ = [
|
||||
'HelpMod',
|
||||
]
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
# =====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)
|
|
@ -1,12 +0,0 @@
|
|||
from typing import List
|
||||
from .. import Module
|
||||
|
||||
|
||||
class TestMod(Module):
|
||||
PREFIX = "test"
|
||||
NAME = "test"
|
||||
|
||||
async def command(self, cmd: List[str]):
|
||||
if cmd[0] == "test":
|
||||
channel = self._client.get_channel(self._config["channel_id"])
|
||||
await channel.send("psycho frank is in the house")
|
Reference in New Issue