From e0864cc84e20e476b0c4dfa51b3ff6cbb7cc08a3 Mon Sep 17 00:00:00 2001 From: Schimon Jehudah Date: Mon, 12 Feb 2024 09:53:49 +0000 Subject: [PATCH] Accept only numerical value for key interval --- slixfeed/action.py | 6 ++++++ slixfeed/xmpp/client.py | 16 +--------------- slixfeed/xmpp/process.py | 19 +++++++++++++------ 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/slixfeed/action.py b/slixfeed/action.py index 8bc2f33..bcbab83 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -293,6 +293,12 @@ async def xmpp_change_interval(self, key, val, jid, jid_file, message=None, XmppMessage.send(self, jid, response, chat_type='chat') +async def reset_settings(jid_file): + db_file = config.get_pathname_to_database(jid_file) + await sqlite.delete_settings(db_file) + response = 'Default settings have been restored.' + return response + async def xmpp_start_updates(self, message, jid, jid_file): key = 'enabled' val = 1 diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index 3e44b5c..c676a22 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -3,12 +3,6 @@ """ -FIXME - -1) Function check_readiness or event "changed_status" is causing for - triple status messages and also false ones that indicate of lack - of feeds. - TODO 1) Use loop (with gather) instead of TaskGroup. @@ -29,15 +23,7 @@ Parse me! NOTE -1) Self presence - Apparently, it is possible to view self presence. - This means that there is no need to store presences in order to switch or restore presence. - check_readiness - 📂 Send a URL from a blog or a news website. - JID: self.boundjid.bare - MUC: self.alias - -2) Extracting attribute using xmltodict. +1) Extracting attribute using xmltodict. import xmltodict message = xmltodict.parse(str(message)) jid = message["message"]["x"]["@jid"] diff --git a/slixfeed/xmpp/process.py b/slixfeed/xmpp/process.py index 15cb776..7b88265 100644 --- a/slixfeed/xmpp/process.py +++ b/slixfeed/xmpp/process.py @@ -390,10 +390,11 @@ async def message(self, message): response = ('This action is restricted. ' 'Type: removing bookmarks.') XmppMessage.send_reply(self, message, response) - case 'default': - db_file = config.get_pathname_to_database(jid_file) - await sqlite.delete_settings(db_file) - response = ('Default settings have been restored.') + case 'default': # TODO Set default per key + response = action.reset_settings(jid_file) + XmppMessage.send_reply(self, message, response) + case 'defaults': + response = action.reset_settings(jid_file) XmppMessage.send_reply(self, message, response) case 'bookmarks': if jid == config.get_value('accounts', 'XMPP', 'operator'): @@ -558,8 +559,14 @@ async def message(self, message): case _ if message_lowercase.startswith('interval'): key = message_text[:8] val = message_text[9:] - await action.xmpp_change_interval( - self, key, val, jid, jid_file, message=message) + try: + val = int(val) + await action.xmpp_change_interval(self, key, val, jid, + jid_file, + message=message) + except: + response = 'Enter a numeric value only.' + XmppMessage.send_reply(self, message, response) case _ if message_lowercase.startswith('join'): muc_jid = uri.check_xmpp_uri(message_text[5:]) if muc_jid: