Legacy removals, code restructuring, add send_... functions and better help

This commit is contained in:
2024-08-10 01:36:54 +02:00
parent 183b8c60cd
commit 6ebc68127e
32 changed files with 512 additions and 351 deletions

View File

@ -1,23 +1,32 @@
# ================================== #
# WinDog multi-purpose chatbot #
# Licensed under AGPLv3 by OctoSpacc #
# ================================== #
# ==================================== #
# WinDog multi-purpose chatbot #
# Licensed under AGPLv3 by OctoSpacc #
# ==================================== #
# TODO: implement /help <commandname> feature
def cHelp(context:EventContext, data:InputMessageData) -> None:
text = (context.endpoint.get_string(lang=data.user.settings.language) or '').strip()
language = data.user.settings.language
for module in Modules:
summary = Modules[module].get_string("summary", language)
endpoints = Modules[module].endpoints
text += (f"\n\n{module}" + (f": {summary}" if summary else ''))
for endpoint in endpoints:
summary = Modules[module].get_string(f"endpoints.{endpoint.names[0]}.summary", language)
text += (f"\n* /{', /'.join(endpoint.names)}" + (f": {summary}" if summary else ''))
text = text.strip()
SendMessage(context, {"text_html": text})
prefix = data.command.prefix
if (endpoint := data.command.arguments.endpoint):
if endpoint[0] in CommandPrefixes:
endpoint = endpoint[1:]
if endpoint in Endpoints:
return send_message(context, {"text_html": get_help_text(endpoint, language, prefix)})
text = (context.endpoint.get_string(lang=data.user.settings.language) or '').strip()
for group in ModuleGroups:
text += f"\n\n[ {group} ]"
for module in ModuleGroups[group]:
summary = Modules[module].get_string("summary", language)
endpoints = Modules[module].endpoints
text += (f"\n\n{module}" + (f": {summary}" if summary else ''))
for endpoint in endpoints:
summary = Modules[module].get_string(f"endpoints.{endpoint.names[0]}.summary", language)
text += (f"\n* {prefix}{', {prefix}'.join(endpoint.names)}" + (f": {summary}" if summary else ''))
text = text.strip()
return send_message(context, {"text_html": text})
RegisterModule(name="Help", group="Basic", endpoints=[
SafeNamespace(names=["help"], handler=cHelp),
SafeNamespace(names=["help"], handler=cHelp, arguments={
"endpoint": False,
}),
])