Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Fix help.py, and try to get docs working on gh pages
Browse files Browse the repository at this point in the history
  • Loading branch information
showierdata9978 committed Nov 6, 2023
1 parent 9bfc63a commit 726bbb7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
53 changes: 28 additions & 25 deletions MeowerBot/ext/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
from MeowerBot import cbids
import inspect

def _get_index_or(l, i, d):

def _get_index_or(lst: list, i, d):
try:
r = l[i]
r = lst[i]
if str(r) == str(inspect._empty):
return d
return r.__name__
except IndexError:
return d


class Help(Cog):
def __init__(self, bot, *args, **kwargs):
self.bot = bot
self.page = ""
self.pages = []
Cog.__init__(self)



def generate_help(self):
if self.bot.prefix == f"@{self.bot.username}":
Expand All @@ -30,74 +32,75 @@ def generate_help(self):
page_size = 0
for name, cog in self.bot.cogs.items():

self.page+= f"-- [ {name} ] -- \n "
self.page += f"-- [ {name} ] -- \n "
page_size = len(self.page)

for command in cog.commands.values():
self.handle_command(command.name, command)
for cmd in cog.commands.values():
self.handle_command(cmd.name, cmd)

if page_size >= 500:
self.pages.append(self.page)
self.page = f"-- [ {name} ] -- \n "
page_size = len(self.page)

self.page += "-- [ Unsorted ] -- \n "
page_size = len(self.page)



for name, comamnd in self.bot.commands.items():
if comamnd.connected is not None: continue #skip cog based commands
if comamnd.connected is not None:
continue # skip cog based commands

self.handle_command(name, comamnd)

if page_size >= 500:
self.pages.append(self.page)
self.page = f"-- [ Unsorted ] -- \n "
self.page = "-- [ Unsorted ] -- \n "
page_size = len(self.page)

self.pages.append(self.page)

if self.bot.prefix == f"@{self.bot.username} ":
self.bot.prefix = f"@{self.bot.username}"


def handle_command(self, name, cmd: AppCommand):
self.page += (f"{self.bot.prefix}{name} ")

for arg in cmd.args:
self.page += f"<{arg[0]}: {str(_get_index_or(arg, 1, 'any'))}> "


for arg in cmd.optional_args:
self.page += f"[{arg[0]}: {str(_get_index_or(arg, 1, 'any'))}: optional ] "

if cmd.func.__doc__ is not None:
self.page += f"\n\t{cmd.func.__doc__}"



self.page += " \n "

for subcommand_name, command in cmd.subcommands.items():
self.page += f" \t "
self.handle_command(f"{name} {subcommand_name}", command)
for subcommand_name, cmd in cmd.subcommands.items():
self.page += " \t "
self.handle_command(f"{name} {subcommand_name}", cmd)
self.page += " \n "

self.page += " \n "

@command(name="help")
async def help(self, ctx, page: int=0):
async def help(self, ctx, page: int = 0):

if page >= len(self.pages):
page = len(self.pages) - 1

await ctx.send_msg(self.pages[page])


@callback(cbids.login)
@staticmethod
async def _login(token):
self = Help.__instence__
self.bot.logger.info("Generating Help")
self.generate_help() #generate help on login, bugfix for default prefix and people being dumb
self.generate_help() # generate help on login, bugfix for default prefix and people being dumb
2 changes: 1 addition & 1 deletion docs/source/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sphinx_rtd_theme
sphinx
sphinx=7.2.6

0 comments on commit 726bbb7

Please sign in to comment.