add new module: help (allows to get manual pages for commands)

This commit is contained in:
dymik739 2023-11-04 13:48:40 +02:00
parent 2a9bd28d65
commit e830bae282
7 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Usage: !hardsub [event_name]
Permanently subscribes to [event_name]. If blank, uses "default".
To unsubscribe, use !hardunsub
For one-time subscriptions, use !sub

View File

@ -0,0 +1,5 @@
Usage: !hardunsub [event_name]
Remove permanent subscription to [event_name]. If blank, uses "default".
To remove one-time subscription, use !unsub
To add permanent subscription, use !hardsub

View File

@ -0,0 +1,5 @@
Usage:
!schedule-ctl list - see all settings
!schedule-ctl get <setting> - see specific personal setting
!schedule-ctl set <setting> <value> - change <setting> to <value>
!schedule-ctl clear <setting> - restore <setting> to default value

7
modules/help/db/sub.txt Normal file
View File

@ -0,0 +1,7 @@
Usage: !sub [event_name]
Soft-subscribes to [event_name]. If black, uses "default".
If you want to remove soft substription, use !unsub
Soft subscription is automatically removed after the event is triggered once.
If you want to subscribe permanently, use !hardsub

View File

@ -0,0 +1,5 @@
Usage: !unsub [event_name]
Removes one-time subscription to [event_name]. If blank, uses "default".
Does not affect hard subscriptions. To remove hard subscription, use !hardunsub
To add one-time supscription, use !sub

54
modules/help/index.py Normal file
View File

@ -0,0 +1,54 @@
import json
import os
module_path = ""
def readfile(filename):
if os.path.exists(module_path + filename):
return open(module_path + filename).read()
else:
return False
def list_entries(search_query):
files = []
for p, d, f in os.walk(module_path + "db/"):
for i in f:
entry_name = f"{p.split('/', 3)[3]}/{i}"
if search_query in entry_name:
files.append(f"{p.split('/', 3)[3]}/{i}".rsplit(".", 1)[0].replace("/", ".").lstrip("."))
files.sort()
return files
def process(message, path):
if message.text[:5] != "!help":
return None, None
global module_path
module_path = path
cmd = message.text[1:].split()
if len(cmd) == 1:
return "Usage:\n```\n!help show <entry> - displays specified manual entry\n!help list [query] - lists out available entries (optionally, filtered by [query])```", "Markdown"
elif cmd[1] == "list":
if len(cmd) == 2:
return "Available entries:\n" + "\n".join(list_entries("")), None
else:
return f"Found entries for {cmd[2]}:\n" + "\n".join(list_entries(cmd[2])), None
elif cmd[1] == "show":
if len(cmd) >= 3:
result = ""
for entry_name in cmd[2:]:
data = readfile("db/" + entry_name.replace(".", "/") + ".txt")
if data:
result += f"Manual page for {entry_name}:\n```\n{data}```\n"
else:
result += f"No manual found for {entry_name}\n\n"
return result, "Markdown"
else:
return "Usage: !help show <entry> - displays specified manual entry", None

6
modules/help/meta.json Normal file
View File

@ -0,0 +1,6 @@
{
"start_on_boot": true,
"alias": "help",
"version": 2,
"index_file": "index.py"
}