Improve listing of commands

This commit is contained in:
Schimon Jehudah 2024-01-27 19:21:45 +00:00
parent 4da2a28184
commit 6883eb6615
3 changed files with 258 additions and 4 deletions

View file

@ -49,6 +49,7 @@ from slixfeed.url import (
trim_url trim_url
) )
import slixfeed.xmpp.bookmark as bookmark import slixfeed.xmpp.bookmark as bookmark
import tomllib
from urllib import error from urllib import error
from urllib.parse import parse_qs, urlsplit from urllib.parse import parse_qs, urlsplit
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -81,6 +82,27 @@ except:
"Package readability was not found.\n" "Package readability was not found.\n"
"Arc90 Lab algorithm is disabled.") "Arc90 Lab algorithm is disabled.")
def commands(section=None, command=None):
config_dir = config.get_default_config_directory()
with open(config_dir + "/commands.toml", mode="rb") as commands:
cmds = tomllib.load(commands)
if command and section:
command_name = '`', cmds[section][command], '`\n'
command_info = cmds[section][command + '_info']
if isinstance(command_info, list):
command_info = '\n'.join(command_info)
cmd_list = [command_name, command_info]
elif section:
cmd_list = []
for cmd in cmds[section]:
if not '_info' in cmd:
cmd_list.extend([cmd])
else:
cmd_list = []
for cmd in cmds:
cmd_list.extend([cmd])
return cmd_list
def log_to_markdown(timestamp, filename, jid, message): def log_to_markdown(timestamp, filename, jid, message):
""" """

View file

@ -0,0 +1,211 @@
[action]
url = "<url>"
url_info = "Add <url> to subscription list."
add = "add <url> TITLE"
add_info = "Add <url> to subscription list (without validity check)."
next = "next N"
next_info = "Send N next updates."
[backup]
opml = "export opml"
opml_info = "Send an OPML file with feeds."
html = "backup news html"
html_info = "Send an HTML formatted file of your news items."
md = "backup news md"
md_info = "Send a Markdown file of your news items."
text = "backup news text"
text_info = "Send a Plain Text file of your news items."
[custom]
new = "new"
new_info = "Send only new items of newly added feeds."
old = "old"
old_info = "Send all items of newly added feeds."
[document]
get = "get <id> <type>"
get_info = [
"Send an article as file. Specify <id> and <type>.",
"Supported types are HTML, MD and PDF (default)."
]
[filter]
allow = "allow [+|-]"
allow_info = [
"Keywords to allow",
"comma-separated keywords",
"'+' appends to, '-' removes from."
]
deny = "deny [+|-]"
deny_info = [
"Keywords to block",
"comma-separated keywords",
"'+' appends to, '-' removes from."
]
clear_allow = "filter clear allow"
clear_allow_info = "Reset allow list."
clear_deny = "filter clear deny"
clear_deny_info = "Reset deny list."
[groupchat]
join = "join <muc>"
join_info = "Join specified groupchat."
[help]
commands = "commands"
commands_info = "Print list of commands."
help = "help"
help_info = "Print this help manual."
info = "info"
info_info = "Print information page."
support = "support"
support_info = "Join xmpp:slixfeed@chat.woodpeckersnest.space?join"
[info]
about = [
"Slixfeed aims to be an easy to use and fully-featured news",
"aggregator bot for XMPP. It provides a convenient access to Blogs,",
"Fediverse and News websites along with filtering functionality.",
"\n",
"Slixfeed is primarily designed for XMPP (aka Jabber).",
"Visit https://xmpp.org/software/ for more information.",
"\n",
"XMPP is the Extensible Messaging and Presence Protocol, a set",
"of open technologies for instant messaging, presence, multi-party",
"chat, voice and video calls, collaboration, lightweight",
"middleware, content syndication, and generalized routing of XML",
"data.",
"\n",
"Visit https://xmpp.org/about/ for more information on the XMPP",
"protocol.",
]
platforms = [
"Supported prootcols are IRC, Matrix, Tox and XMPP.",
"For the best experience, we recommend you to use XMPP."
]
filetypes = [
"Supported filetypes: Atom, JSON, RDF, RSS and XML."
]
protocols = [
"Supported protocols: Dat, FTP, Gemini, Gopher, HTTP and IPFS."
]
authors = [
"Laura Lapina",
"Schimon Zackary"
]
thanks = [
# consultants and testers
"Alixander Court (Utah)",
"habnabit_ from #python on irc.libera.chat",
"imattau (atomtopubsub)",
"Jaussoin Timothée (Movim, France)",
"magicfelix",
"Simone \"roughnecks\" Canaletti (WoodpeckersNest.space, Italy)",
"Strix from loqi.im",
# gajim
"Denis Fomin (Gajim, Russia)",
"Emmanuel Gil Peyrot (Poezio, France)",
"Yann Leboulanger (Gajim, France)",
# intro
"Christian Dersch (SalixOS)",
"Cyrille Pontvieux (SalixOS, France)",
"Dimitris Tzemos (SalixOS, Greece)",
"George Vlahavas (SalixOS, Greece)",
"Pierrick Le Brun (SalixOS, France)",
"Raphael Groner (Fedora, Germany)",
"Thorsten Mühlfelder (SalixOS, Germany)",
# openfire
"Guus der Kinderen from IgniteRealtime.org (Openfire, Netherlands)",
# swift
"Kevin Smith from Isode (Swift, Wales# xmpp)",
"Remko Tronçon (Swift, Germany)",
# xmpp
"Florent Le Coz (Poezio, France)",
"Maxime Buquet (slixmpp, France)",
"Mathieu Pasquet (slixmpp, France)",
]
license = [
"Slixfeed is free software; you can redistribute it and/or",
"modify it under the terms of the MIT License.",
"\n",
"Slixfeed is distributed in the hope that it will be useful,",
"but WITHOUT ANY WARRANTY; without even the implied warranty of",
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
"MIT License for more details.",
]
note = [
"You can run Slixfeed on your own computer, server, and",
"even on a Linux phone (i.e. Droidian, Kupfer, Mobian, NixOS,",
"postmarketOS). You can also use Termux.",
"\n",
"All you need is one of the above and an XMPP account to",
"connect Slixfeed to.",
]
resources = [
"Slixfeed",
"https://gitgud.io/sjehuda/slixfeed",
"Slixmpp",
"https://slixmpp.readthedocs.io/",
"feedparser",
"https://pythonhosted.org/feedparser",
]
[mastership]
demaster = "demaster NICKNAME"
demaster_info = "Remove master privilege."
mastership = "mastership NICKNAME"
mastership_info = "Add master privilege."
ownership = "ownership NICKNAME"
ownership_info = "Set new owner."
[message]
interval = "interval <num>"
interval_info = "Set interval update to every <num> minutes."
length = "length"
length_info = "Set maximum length of news item description. (0 for no limit)"
quantum = "quantum <num>"
quantum_info = "Set <num> amount of updates per interval."
[modification]
remove = "remove <id>"
remove_info = "Remove feed of <id> from subscription list."
disable = "disable <id>"
disable_info = "Disable updates for feed of <id>."
enable = "enable <id>"
enable_info = "Enable updates for feed of <id>."
reset = "reset"
reset_info = "Mark all entries as read and remove all archived entries"
reset_url = "reset <url>"
reset_url_info = "Mark entries of <url> as read and remove all archived entries of <url>."
start = "start"
start_info = "Enable bot and send updates."
stop = "stop"
stop_info = "Disable bot and stop updates."
[preview]
read = "read <url>"
read_info = "Display most recent 20 titles of given <url>."
read_num = "read <url> <n>"
read_num_info = "Display specified entry number from given <url>."
[search]
feeds = "feeds"
feeds_info = "List all subscriptions."
feeds_keyword = "feeds <text>"
feeds_keyword_info = "Search subscriptions by given <text>."
search = "search <text>"
search_info = "Search news items by given <text>."
recent = "recent <num>"
recent_info = "List recent <num> news items (up to 50 items)."
[statistics]
analyses = "analyses"
analyses_info = "Show report and statistics of feeds."
obsolete = "obsolete"
obsolete_info = "List feeds that are not available."
unread = "unread"
unread_info = "Print number of unread news items."
[token]
activate = "activate CODE"
activate_info = "Activate given token to command bot."

View file

@ -212,6 +212,7 @@ async def message(self, message):
logging.debug([str(message['from']), ':', message_text]) logging.debug([str(message['from']), ':', message_text])
# Support private message via groupchat # Support private message via groupchat
# Fail. See https://codeberg.org/poezio/slixmpp/issues/3506
if message['type'] == 'chat' and message.get_plugin('muc', check=True): if message['type'] == 'chat' and message.get_plugin('muc', check=True):
jid_bare = message['from'].bare jid_bare = message['from'].bare
jid_full = str(message['from']) jid_full = str(message['from'])
@ -239,11 +240,31 @@ async def message(self, message):
# 'Type: breakpoint.' # 'Type: breakpoint.'
# ) # )
# send_reply_message(self, message, response) # send_reply_message(self, message, response)
case 'commands':
response = manual.print_cmd()
send_reply_message(self, message, response)
case 'help': case 'help':
response = manual.print_help() command_list = '`, `'.join(action.commands())
response = (
'Available command topics:\n`', command_list,
'`\nSend `help command_topic` for instructions.')
send_reply_message(self, message, response)
case _ if message_lowercase.startswith('help'):
command = message_text[5:]
command = command.split(' ')
if len(command) == 2:
command_root = command[0]
command_name = command[1]
command_list = ''.join(action.commands(
section=command_root, command=command_name))
response = (command_list)
elif len(command) == 1:
command = command[0]
command_list = '`, `'.join(action.commands(command))
response = (
'Available commands:\n`', command_list,
'`\nSend `help {} command_name` for instructions.'
.format(command))
else:
response = (
'Invalid. Enter command topic or command topic and name')
send_reply_message(self, message, response) send_reply_message(self, message, response)
case 'info': case 'info':
response = manual.print_info() response = manual.print_info()