From 6883eb661522addef6db333263458410410d3c86 Mon Sep 17 00:00:00 2001 From: Schimon Jehudah Date: Sat, 27 Jan 2024 19:21:45 +0000 Subject: [PATCH] Improve listing of commands --- slixfeed/action.py | 22 ++++ slixfeed/assets/commands.toml | 211 ++++++++++++++++++++++++++++++++++ slixfeed/xmpp/process.py | 29 ++++- 3 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 slixfeed/assets/commands.toml diff --git a/slixfeed/action.py b/slixfeed/action.py index 6ef4a7a..f51e673 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -49,6 +49,7 @@ from slixfeed.url import ( trim_url ) import slixfeed.xmpp.bookmark as bookmark +import tomllib from urllib import error from urllib.parse import parse_qs, urlsplit import xml.etree.ElementTree as ET @@ -81,6 +82,27 @@ except: "Package readability was not found.\n" "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): """ diff --git a/slixfeed/assets/commands.toml b/slixfeed/assets/commands.toml new file mode 100644 index 0000000..c504637 --- /dev/null +++ b/slixfeed/assets/commands.toml @@ -0,0 +1,211 @@ +[action] +url = "" +url_info = "Add to subscription list." +add = "add TITLE" +add_info = "Add 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 " +get_info = [ + "Send an article as file. Specify and .", + "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 " +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 " +interval_info = "Set interval update to every minutes." +length = "length" +length_info = "Set maximum length of news item description. (0 for no limit)" +quantum = "quantum " +quantum_info = "Set amount of updates per interval." + +[modification] +remove = "remove " +remove_info = "Remove feed of from subscription list." +disable = "disable " +disable_info = "Disable updates for feed of ." +enable = "enable " +enable_info = "Enable updates for feed of ." +reset = "reset" +reset_info = "Mark all entries as read and remove all archived entries" +reset_url = "reset " +reset_url_info = "Mark entries of as read and remove all archived entries of ." +start = "start" +start_info = "Enable bot and send updates." +stop = "stop" +stop_info = "Disable bot and stop updates." + +[preview] +read = "read " +read_info = "Display most recent 20 titles of given ." +read_num = "read " +read_num_info = "Display specified entry number from given ." + +[search] +feeds = "feeds" +feeds_info = "List all subscriptions." +feeds_keyword = "feeds " +feeds_keyword_info = "Search subscriptions by given ." +search = "search " +search_info = "Search news items by given ." +recent = "recent " +recent_info = "List recent 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." diff --git a/slixfeed/xmpp/process.py b/slixfeed/xmpp/process.py index e898d07..e8be56c 100644 --- a/slixfeed/xmpp/process.py +++ b/slixfeed/xmpp/process.py @@ -212,6 +212,7 @@ async def message(self, message): logging.debug([str(message['from']), ':', message_text]) # 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): jid_bare = message['from'].bare jid_full = str(message['from']) @@ -239,11 +240,31 @@ async def message(self, message): # 'Type: breakpoint.' # ) # send_reply_message(self, message, response) - case 'commands': - response = manual.print_cmd() - send_reply_message(self, message, response) 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) case 'info': response = manual.print_info()