Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfde28ad4b | ||
|
|
f23cd71647 | ||
|
|
75fdef6388 |
@@ -0,0 +1,26 @@
|
|||||||
|
"""
|
||||||
|
Help command
|
||||||
|
"""
|
||||||
|
|
||||||
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
from .help_command import NewHelpCommand
|
||||||
|
|
||||||
|
|
||||||
|
class HelpCog(commands.Cog):
|
||||||
|
"""Help Command"""
|
||||||
|
|
||||||
|
def __init__(self, bot: commands.Bot):
|
||||||
|
self.bot = bot
|
||||||
|
self._original_help_command = bot.help_command
|
||||||
|
bot.help_command = NewHelpCommand()
|
||||||
|
bot.help_command.cog = self
|
||||||
|
|
||||||
|
def cog_unload(self):
|
||||||
|
self.bot.help_command = self._original_help_command
|
||||||
|
|
||||||
|
|
||||||
|
# setup functions for bot
|
||||||
|
def setup(bot: commands.Bot):
|
||||||
|
"""Adds functon to bot"""
|
||||||
|
bot.add_cog(HelpCog(bot))
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
"""
|
||||||
|
Help command. Copied from discord-bot-template.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord.embeds import EmptyEmbed
|
||||||
|
from nextcord.ext import commands
|
||||||
|
import config # pylint: disable=import-error
|
||||||
|
|
||||||
|
|
||||||
|
class NewHelpCommand(commands.MinimalHelpCommand):
|
||||||
|
"""Custom help command override using embeds"""
|
||||||
|
|
||||||
|
COLOUR = nextcord.Colour.blurple()
|
||||||
|
|
||||||
|
def get_ending_note(self):
|
||||||
|
"""Returns note to display at the bottom"""
|
||||||
|
invoked_with = self.invoked_with
|
||||||
|
return f"Use {config.BOT_PREFIX}{invoked_with} [command] for more info on a command."
|
||||||
|
|
||||||
|
def get_command_signature(self, command: commands.core.Command):
|
||||||
|
"""Retrieves the signature portion of the help page."""
|
||||||
|
return f"{command.qualified_name} {command.signature}"
|
||||||
|
|
||||||
|
async def send_bot_help(self, mapping: dict):
|
||||||
|
"""implements bot command help page"""
|
||||||
|
embed = nextcord.Embed(title="Bot Commands", colour=self.COLOUR)
|
||||||
|
avatar = self.context.bot.user.avatar
|
||||||
|
avatar_url = avatar.url if avatar else EmptyEmbed
|
||||||
|
embed.set_author(name=self.context.bot.user.name, icon_url=avatar_url)
|
||||||
|
description = self.context.bot.description
|
||||||
|
if description:
|
||||||
|
embed.description = description
|
||||||
|
|
||||||
|
for cog, commands in mapping.items(): # pylint: disable=redefined-outer-name
|
||||||
|
name = "No Category" if cog is None else cog.qualified_name
|
||||||
|
filtered = await self.filter_commands(commands, sort=True)
|
||||||
|
if filtered:
|
||||||
|
# \u2002 = middle dot
|
||||||
|
value = "\u2002".join(f"{config.BOT_PREFIX}{c.name}" for c in filtered)
|
||||||
|
if cog and cog.description:
|
||||||
|
value = f"{cog.description}\n{value}"
|
||||||
|
embed.add_field(name=name, value=value)
|
||||||
|
|
||||||
|
embed.set_footer(text=self.get_ending_note())
|
||||||
|
await self.get_destination().send(embed=embed)
|
||||||
|
|
||||||
|
async def send_cog_help(self, cog: commands.Cog):
|
||||||
|
"""implements cog help page"""
|
||||||
|
embed = nextcord.Embed(title=f"{cog.qualified_name} Commands", colour=self.COLOUR)
|
||||||
|
if cog.description:
|
||||||
|
embed.description = cog.description
|
||||||
|
|
||||||
|
filtered = await self.filter_commands(cog.get_commands(), sort=True)
|
||||||
|
for command in filtered:
|
||||||
|
embed.add_field(
|
||||||
|
name=self.get_command_signature(command),
|
||||||
|
value=command.short_doc or "...",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.set_footer(text=self.get_ending_note())
|
||||||
|
await self.get_destination().send(embed=embed)
|
||||||
|
|
||||||
|
async def send_group_help(self, group: commands.Group):
|
||||||
|
"""implements group help page and command help page"""
|
||||||
|
embed = nextcord.Embed(title=group.qualified_name, colour=self.COLOUR)
|
||||||
|
if group.help:
|
||||||
|
embed.description = group.help
|
||||||
|
|
||||||
|
if isinstance(group, commands.Group):
|
||||||
|
filtered = await self.filter_commands(group.commands, sort=True)
|
||||||
|
for command in filtered:
|
||||||
|
embed.add_field(
|
||||||
|
name=self.get_command_signature(command),
|
||||||
|
value=command.short_doc or "...",
|
||||||
|
inline=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
embed.set_footer(text=self.get_ending_note())
|
||||||
|
await self.get_destination().send(embed=embed)
|
||||||
|
|
||||||
|
# Use the same function as group help for command help
|
||||||
|
send_command_help = send_group_help # type: ignore
|
||||||
@@ -10,7 +10,7 @@ from utils import highscore_message # pylint: disable=import-error
|
|||||||
|
|
||||||
|
|
||||||
class PostHighscores(commands.Cog, name="Post Highscores"):
|
class PostHighscores(commands.Cog, name="Post Highscores"):
|
||||||
"""Actions of bot command"""
|
"""Posts Highscores."""
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
@@ -18,8 +18,8 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
@commands.command(name="post-scores")
|
@commands.command(name="post-scores")
|
||||||
async def post_highscores(self, ctx: commands.Context):
|
async def post_highscores(self, ctx: commands.Context):
|
||||||
"""
|
"""
|
||||||
A command which posts the highscore in the designated channel. Sends warning if no channel
|
A command which posts the highscore in the designated channel.
|
||||||
has been registered.
|
Sends warning if no channel has been registered.
|
||||||
Usage:
|
Usage:
|
||||||
```
|
```
|
||||||
?post-scores
|
?post-scores
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ from utils import data_storage # pylint: disable=import-error
|
|||||||
|
|
||||||
|
|
||||||
class RegisterHighscoreChannel(commands.Cog, name="Register HighScore Channel"):
|
class RegisterHighscoreChannel(commands.Cog, name="Register HighScore Channel"):
|
||||||
"""Actions of bot command"""
|
"""Registers Highscore channel"""
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(name="register")
|
@commands.command(name="register")
|
||||||
async def register_highscores(self, ctx: commands.Context):
|
async def register_highscores(self, ctx: commands.Context):
|
||||||
"""A command which registers the channel command is sent in as channel to post highscores in
|
"""A command which registers current channel as channel to post highscores in.
|
||||||
Usage:
|
Usage:
|
||||||
```
|
```
|
||||||
?register (in channel to post highscores in)
|
?register (in channel to post highscores in)
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ from utils import highscore_manage # pylint: disable=import-error
|
|||||||
|
|
||||||
|
|
||||||
class RegisterHighscoreChannel(commands.Cog, name="Score"):
|
class RegisterHighscoreChannel(commands.Cog, name="Score"):
|
||||||
"""Actions of bot command"""
|
"""Submits a score."""
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(name="score")
|
@commands.command(name="score")
|
||||||
async def score(self, ctx: commands.Context, boss_name: str, category: str, score: str):
|
async def score(self, ctx: commands.Context, boss_name: str, category: str, score: str):
|
||||||
"""A command which calls a function to submit the score to highscores. Gathers required
|
"""A command which calls a function to submit the score to highscores.
|
||||||
information from command and passes on.
|
Gathers required information from command and passes on.
|
||||||
Usage:
|
Usage:
|
||||||
```
|
```
|
||||||
?score "Boss Name" "Category" "score"
|
?score "Boss Name" "Category" "score"
|
||||||
|
|||||||
Reference in New Issue
Block a user