Finalized new help, added cog description.

This commit is contained in:
Adriene Hutchins 2020-03-02 01:12:16 -05:00
parent d74e285764
commit d110c194cc
5 changed files with 124 additions and 7 deletions

2
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Bot Related # Bot Related
config.json config.json
extensions/__pycache__/
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
@ -52,3 +53,4 @@ coverage.xml
# Sphinx documentation # Sphinx documentation
docs/_build/ docs/_build/
extensions/__pycache__/core.cpython-38.pyc extensions/__pycache__/core.cpython-38.pyc
extensions/__pycache__/core.cpython-38.pyc

View file

@ -13,6 +13,8 @@ import dbl
class BotList(commands.Cog, name='Bot List'): class BotList(commands.Cog, name='Bot List'):
"""Provides various utilities for handling BotList stuff."""
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.request = bot.request self.request = bot.request
@ -78,6 +80,7 @@ class BotList(commands.Cog, name='Bot List'):
# Finishing up # Finishing up
return responses return responses
# TODO Move to Core, hide behind check for any existing token
@commands.command(aliases=['review']) @commands.command(aliases=['review'])
async def vote(self, ctx): async def vote(self, ctx):
"""Review and vote for us on various botlists!""" """Review and vote for us on various botlists!"""

View file

@ -1,3 +1,10 @@
# -*- coding: utf-8 -*-
# tacibot core
# Handles all important main features of any bot.
'''Core File'''
import discord import discord
import os import os
from discord.ext import commands from discord.ext import commands
@ -11,6 +18,7 @@ import itertools
class Core(commands.Cog): class Core(commands.Cog):
"""Provides all core features of a bot."""
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -18,7 +26,6 @@ class Core(commands.Cog):
'extensions': [] 'extensions': []
} }
#
self._original_help_command = bot.help_command self._original_help_command = bot.help_command
if bot.config['CUSTOM_HELP']: if bot.config['CUSTOM_HELP']:
bot.help_command = HelpCommand() bot.help_command = HelpCommand()
@ -181,24 +188,71 @@ Number of extensions present: {len(ctx.bot.cogs)}
class HelpCommand(commands.MinimalHelpCommand): class HelpCommand(commands.MinimalHelpCommand):
def __init__(self, **options): def __init__(self, **options):
super().__init__(**options) super().__init__(**options)
self.command_attrs['help'] = "Find more assistance on this bot."
self.subcommands_heading = "Subcommands"
def get_opening_note(self):
bot = self.context.bot
return f"__**{bot.user.name}**__ - _{bot.description}_"
def get_ending_note(self):
command_name = self.invoked_with
return (
"_For more info, see "
f"`{self.clean_prefix}{command_name} [category/command/subcommand]`._"
)
def get_command_signature(self, command):
return f"**`{self.clean_prefix}{command.qualified_name} {command.signature}`**"
def add_aliases_formatting(self, aliases):
self.paginator.add_line(
f"_{self.aliases_heading} {','.join(f'`{a}`' for a in aliases)}_"
)
def add_command_formatting(self, command):
if command.description:
self.paginator.add_line(command.description, empty=True)
signature = self.get_command_signature(command)
if command.aliases:
self.paginator.add_line(signature)
self.add_aliases_formatting(command.aliases)
else:
self.paginator.add_line(signature, empty=True)
if command.help:
try:
self.paginator.add_line(command.help, empty=True)
except RuntimeError:
for line in command.help.splitlines():
self.paginator.add_line(line)
self.paginator.add_line()
def add_subcommand_formatting(self, command):
if command.short_doc:
line = f"`{command.qualified_name}` - {command.short_doc}"
else:
line = f"`{command.qualified_name}`"
self.paginator.add_line(line)
def add_bot_commands_formatting(self, commands, heading): def add_bot_commands_formatting(self, commands, heading):
if commands: if commands:
self.paginator.add_line(f"**{heading}**") self.paginator.add_line(f"**{heading}**")
if heading == 'Main': self.paginator.add_line()
# TODO Make the Main Dynamic
if heading == 'Core/Bot List':
self.paginator.add_line(", ".join(f"`{c.name}`" for c in commands)) self.paginator.add_line(", ".join(f"`{c.name}`" for c in commands))
else: else:
for c in commands: for c in commands:
self.paginator.add_line(f'`{c.name}` - _{c.short_doc}_') self.paginator.add_line(f'`{c.name}` - {c.short_doc}')
self.paginator.add_line() self.paginator.add_line()
async def send_bot_help(self, mapping): async def send_bot_help(self, mapping):
ctx = self.context ctx = self.context
bot = ctx.bot bot = ctx.bot
if bot.description:
self.paginator.add_line(bot.description, empty=True)
note = self.get_opening_note() note = self.get_opening_note()
if note: if note:
self.paginator.add_line(note, empty=True) self.paginator.add_line(note, empty=True)
@ -221,10 +275,31 @@ class HelpCommand(commands.MinimalHelpCommand):
else: else:
other_cmds[category] = commands other_cmds[category] = commands
self.add_bot_commands_formatting(main_cmds, 'Main') self.add_bot_commands_formatting(main_cmds, 'Core/Bot List')
for category, commands in other_cmds.items(): for category, commands in other_cmds.items():
self.add_bot_commands_formatting(commands, category) self.add_bot_commands_formatting(commands, category)
note = self.get_ending_note()
if note:
self.paginator.add_line(note)
await self.send_pages()
async def send_cog_help(self, cog):
note = self.get_opening_note()
if note:
self.paginator.add_line(note, empty=True)
self.paginator.add_line(f"**{cog.qualified_name}**")
if cog.description:
self.paginator.add_line(f"_{cog.description}_", empty=True)
filtered = await self.filter_commands(cog.get_commands(), sort=self.sort_commands)
if filtered:
for command in filtered:
self.add_subcommand_formatting(command)
note = self.get_ending_note() note = self.get_ending_note()
if note: if note:
self.paginator.add_line() self.paginator.add_line()
@ -232,6 +307,39 @@ class HelpCommand(commands.MinimalHelpCommand):
await self.send_pages() await self.send_pages()
async def send_group_help(self, group):
note = self.get_opening_note()
if note:
self.paginator.add_line(note, empty=True)
self.add_command_formatting(group)
filtered = await self.filter_commands(group.commands, sort=self.sort_commands)
if filtered:
self.paginator.add_line('**%s**' % self.subcommands_heading, empty=True)
for command in filtered:
self.add_subcommand_formatting(command)
note = self.get_ending_note()
if note:
self.paginator.add_line()
self.paginator.add_line(note)
await self.send_pages()
async def send_command_help(self, command):
note = self.get_opening_note()
if note:
self.paginator.add_line(note, empty=True)
self.add_command_formatting(command)
note = self.get_ending_note()
if note:
self.paginator.add_line(note)
self.paginator.close_page()
await self.send_pages()
def setup(bot): def setup(bot):

View file

@ -22,6 +22,8 @@ import subprocess
class Developer(commands.Cog): class Developer(commands.Cog):
"""Provides various resources for developers."""
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.request = bot.request self.request = bot.request

View file

@ -13,6 +13,8 @@ import sys
class Search(commands.Cog): class Search(commands.Cog):
"""Searches the web for a variety of different resources."""
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.request = bot.request self.request = bot.request