Add a handler to handle pending tasks.
This commit is contained in:
parent
926c0341c6
commit
aed43f34dd
6 changed files with 82 additions and 25 deletions
|
@ -153,25 +153,30 @@ async def xmpp_send_status(self, jid):
|
||||||
status_mode = 'xa'
|
status_mode = 'xa'
|
||||||
status_text = '📪️ Send "Start" to receive updates'
|
status_text = '📪️ Send "Start" to receive updates'
|
||||||
else:
|
else:
|
||||||
feeds = sqlite.get_number_of_items(db_file, 'feeds')
|
jid_task = self.pending_tasks[jid]
|
||||||
# print(await current_time(), jid, "has", feeds, "feeds")
|
if len(jid_task):
|
||||||
if not feeds:
|
status_mode = 'dnd'
|
||||||
status_mode = 'available'
|
status_text = jid_task[list(jid_task.keys())[0]]
|
||||||
status_text = '📪️ Send a URL from a blog or a news website'
|
|
||||||
else:
|
else:
|
||||||
unread = sqlite.get_number_of_entries_unread(db_file)
|
feeds = sqlite.get_number_of_items(db_file, 'feeds')
|
||||||
if unread:
|
# print(await current_time(), jid, "has", feeds, "feeds")
|
||||||
status_mode = 'chat'
|
if not feeds:
|
||||||
status_text = '📬️ There are {} news items'.format(str(unread))
|
|
||||||
# status_text = (
|
|
||||||
# "📰 News items: {}"
|
|
||||||
# ).format(str(unread))
|
|
||||||
# status_text = (
|
|
||||||
# "📰 You have {} news items"
|
|
||||||
# ).format(str(unread))
|
|
||||||
else:
|
|
||||||
status_mode = 'available'
|
status_mode = 'available'
|
||||||
status_text = '📭️ No news'
|
status_text = '📪️ Send a URL from a blog or a news website'
|
||||||
|
else:
|
||||||
|
unread = sqlite.get_number_of_entries_unread(db_file)
|
||||||
|
if unread:
|
||||||
|
status_mode = 'chat'
|
||||||
|
status_text = '📬️ There are {} news items'.format(str(unread))
|
||||||
|
# status_text = (
|
||||||
|
# "📰 News items: {}"
|
||||||
|
# ).format(str(unread))
|
||||||
|
# status_text = (
|
||||||
|
# "📰 You have {} news items"
|
||||||
|
# ).format(str(unread))
|
||||||
|
else:
|
||||||
|
status_mode = 'available'
|
||||||
|
status_text = '📭️ No news'
|
||||||
|
|
||||||
# breakpoint()
|
# breakpoint()
|
||||||
# print(await current_time(), status_text, "for", jid)
|
# print(await current_time(), status_text, "for", jid)
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__version__ = '0.1.45'
|
__version__ = '0.1.46'
|
||||||
__version_info__ = (0, 1, 45)
|
__version_info__ = (0, 1, 46)
|
||||||
|
|
|
@ -120,6 +120,9 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# Handler for tasks
|
# Handler for tasks
|
||||||
self.task_manager = {}
|
self.task_manager = {}
|
||||||
|
|
||||||
|
# Handler for task messages
|
||||||
|
self.pending_tasks = {}
|
||||||
|
|
||||||
# Handler for ping
|
# Handler for ping
|
||||||
self.task_ping_instance = {}
|
self.task_ping_instance = {}
|
||||||
|
|
||||||
|
@ -349,6 +352,11 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# message_body = 'Share online status to receive updates.'
|
# message_body = 'Share online status to receive updates.'
|
||||||
# XmppMessage.send_headline(self, jid_bare, message_subject,
|
# XmppMessage.send_headline(self, jid_bare, message_subject,
|
||||||
# message_body, 'chat')
|
# message_body, 'chat')
|
||||||
|
|
||||||
|
if jid_bare not in self.pending_tasks:
|
||||||
|
self.pending_tasks[jid_bare] = {}
|
||||||
|
# if jid_full not in self.pending_tasks:
|
||||||
|
# self.pending_tasks[jid_full] = {}
|
||||||
await process.message(self, message)
|
await process.message(self, message)
|
||||||
# chat_type = message["type"]
|
# chat_type = message["type"]
|
||||||
# message_body = message["body"]
|
# message_body = message["body"]
|
||||||
|
@ -2749,7 +2757,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
if jid_bare not in self.settings:
|
if jid_bare not in self.settings:
|
||||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
||||||
form = self['xep_0004'].make_form('form', 'Settings')
|
form = self['xep_0004'].make_form('form', 'Settings')
|
||||||
form['instructions'] = 'Editing settings'
|
form['instructions'] = 'Editing settings of {}'.format(jid_bare)
|
||||||
value = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
value = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
|
|
|
@ -111,6 +111,9 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
# Handler for tasks
|
# Handler for tasks
|
||||||
self.task_manager = {}
|
self.task_manager = {}
|
||||||
|
|
||||||
|
# Handler for task messages
|
||||||
|
self.pending_tasks = {}
|
||||||
|
|
||||||
# Handler for ping
|
# Handler for ping
|
||||||
self.task_ping_instance = {}
|
self.task_ping_instance = {}
|
||||||
|
|
||||||
|
@ -308,6 +311,10 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
# self.send_raw(str(presence_probe))
|
# self.send_raw(str(presence_probe))
|
||||||
# presence_probe.send()
|
# presence_probe.send()
|
||||||
|
|
||||||
|
if jid_bare not in self.pending_tasks:
|
||||||
|
self.pending_tasks[jid_bare] = {}
|
||||||
|
# if jid_full not in self.pending_tasks:
|
||||||
|
# self.pending_tasks[jid_full] = {}
|
||||||
await process.message(self, message)
|
await process.message(self, message)
|
||||||
# chat_type = message["type"]
|
# chat_type = message["type"]
|
||||||
# message_body = message["body"]
|
# message_body = message["body"]
|
||||||
|
@ -2709,7 +2716,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
if jid_bare not in self.settings:
|
if jid_bare not in self.settings:
|
||||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
||||||
form = self['xep_0004'].make_form('form', 'Settings')
|
form = self['xep_0004'].make_form('form', 'Settings')
|
||||||
form['instructions'] = 'Editing settings'
|
form['instructions'] = 'Editing settings of {}'.format(jid_bare)
|
||||||
value = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
value = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
|
|
|
@ -14,7 +14,6 @@ TODO
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from slixfeed.config import get_value
|
|
||||||
from slixfeed.dt import current_time
|
from slixfeed.dt import current_time
|
||||||
from slixmpp.exceptions import IqTimeout, IqError
|
from slixmpp.exceptions import IqTimeout, IqError
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
@ -36,7 +35,6 @@ class XmppConnect:
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
None.
|
None.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
jid_from = str(self.boundjid) if self.is_component else None
|
jid_from = str(self.boundjid) if self.is_component else None
|
||||||
if not jid:
|
if not jid:
|
||||||
|
|
|
@ -46,6 +46,8 @@ from slixfeed.xmpp.upload import XmppUpload
|
||||||
from slixfeed.xmpp.utility import get_chat_type, is_moderator, is_operator
|
from slixfeed.xmpp.utility import get_chat_type, is_moderator, is_operator
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from random import randrange
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import tomllib
|
import tomllib
|
||||||
except:
|
except:
|
||||||
|
@ -104,6 +106,9 @@ async def message(self, message):
|
||||||
task.clean_tasks_xmpp(self, jid_bare, key_list)
|
task.clean_tasks_xmpp(self, jid_bare, key_list)
|
||||||
status_type = 'dnd'
|
status_type = 'dnd'
|
||||||
status_message = '📥️ Procesing request to import feeds...'
|
status_message = '📥️ Procesing request to import feeds...'
|
||||||
|
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||||
|
pending_tasks_num = randrange(10000, 99999)
|
||||||
|
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
|
@ -112,6 +117,7 @@ async def message(self, message):
|
||||||
response = 'Successfully imported {} feeds.'.format(count)
|
response = 'Successfully imported {} feeds.'.format(count)
|
||||||
else:
|
else:
|
||||||
response = 'OPML file was not imported.'
|
response = 'OPML file was not imported.'
|
||||||
|
del self.pending_tasks[jid_bare][pending_tasks_num]
|
||||||
key_list = ['status']
|
key_list = ['status']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
|
@ -280,6 +286,13 @@ async def message(self, message):
|
||||||
'Send "help" for further instructions.\n'
|
'Send "help" for further instructions.\n'
|
||||||
.format(self.alias))
|
.format(self.alias))
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
|
|
||||||
|
title = message_lowercase
|
||||||
|
summary = message_text
|
||||||
|
# from random import randrange
|
||||||
|
node = str(randrange(10000, 99999))
|
||||||
|
iq = XmppPubsub.create(self, title, summary, node)
|
||||||
|
await XmppIQ.send(self, iq)
|
||||||
|
|
||||||
# case _ if message_lowercase.startswith('activate'):
|
# case _ if message_lowercase.startswith('activate'):
|
||||||
# if message['type'] == 'groupchat':
|
# if message['type'] == 'groupchat':
|
||||||
|
@ -513,6 +526,9 @@ async def message(self, message):
|
||||||
status_message = ('📤️ Procesing request to '
|
status_message = ('📤️ Procesing request to '
|
||||||
'export feeds into {}...'
|
'export feeds into {}...'
|
||||||
.format(ext.upper()))
|
.format(ext.upper()))
|
||||||
|
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||||
|
pending_tasks_num = randrange(10000, 99999)
|
||||||
|
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
filename = await action.export_feeds(self, jid_bare,
|
filename = await action.export_feeds(self, jid_bare,
|
||||||
|
@ -524,6 +540,7 @@ async def message(self, message):
|
||||||
# XmppMessage.send_oob_reply_message(message, url, response)
|
# XmppMessage.send_oob_reply_message(message, url, response)
|
||||||
chat_type = await get_chat_type(self, jid_bare)
|
chat_type = await get_chat_type(self, jid_bare)
|
||||||
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
||||||
|
del self.pending_tasks[jid_bare][pending_tasks_num]
|
||||||
key_list = ['status']
|
key_list = ['status']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
else:
|
else:
|
||||||
|
@ -559,6 +576,9 @@ async def message(self, message):
|
||||||
status_type = 'dnd'
|
status_type = 'dnd'
|
||||||
status_message = ('📃️ Procesing request to produce {} '
|
status_message = ('📃️ Procesing request to produce {} '
|
||||||
'document...'.format(ext.upper()))
|
'document...'.format(ext.upper()))
|
||||||
|
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||||
|
pending_tasks_num = randrange(10000, 99999)
|
||||||
|
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
|
@ -612,8 +632,6 @@ async def message(self, message):
|
||||||
response = ('> {}\n'
|
response = ('> {}\n'
|
||||||
'Failed to fetch URL. Reason: {}'
|
'Failed to fetch URL. Reason: {}'
|
||||||
.format(url, code))
|
.format(url, code))
|
||||||
key_list = ['status']
|
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
|
||||||
else:
|
else:
|
||||||
response = ('No action has been taken.'
|
response = ('No action has been taken.'
|
||||||
'\n'
|
'\n'
|
||||||
|
@ -623,6 +641,9 @@ async def message(self, message):
|
||||||
response = ('Unsupported filetype.\n'
|
response = ('Unsupported filetype.\n'
|
||||||
'Try: epub, html, md (markdown), '
|
'Try: epub, html, md (markdown), '
|
||||||
'pdf, or txt (text)')
|
'pdf, or txt (text)')
|
||||||
|
del self.pending_tasks[jid_bare][pending_tasks_num]
|
||||||
|
key_list = ['status']
|
||||||
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
if response:
|
if response:
|
||||||
logging.warning('Error for URL {}: {}'.format(url, error))
|
logging.warning('Error for URL {}: {}'.format(url, error))
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
|
@ -633,6 +654,9 @@ async def message(self, message):
|
||||||
task.clean_tasks_xmpp(self, jid_bare, key_list)
|
task.clean_tasks_xmpp(self, jid_bare, key_list)
|
||||||
status_type = 'dnd'
|
status_type = 'dnd'
|
||||||
status_message = '📥️ Procesing request to import feeds...'
|
status_message = '📥️ Procesing request to import feeds...'
|
||||||
|
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||||
|
pending_tasks_num = randrange(10000, 99999)
|
||||||
|
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
|
@ -642,6 +666,7 @@ async def message(self, message):
|
||||||
.format(count))
|
.format(count))
|
||||||
else:
|
else:
|
||||||
response = 'OPML file was not imported.'
|
response = 'OPML file was not imported.'
|
||||||
|
del self.pending_tasks[jid_bare][pending_tasks_num]
|
||||||
key_list = ['status']
|
key_list = ['status']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
|
@ -652,6 +677,10 @@ async def message(self, message):
|
||||||
status_type = 'dnd'
|
status_type = 'dnd'
|
||||||
status_message = ('📫️ Processing request to fetch data from {}'
|
status_message = ('📫️ Processing request to fetch data from {}'
|
||||||
.format(url))
|
.format(url))
|
||||||
|
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||||
|
pending_tasks_num = randrange(10000, 99999)
|
||||||
|
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||||
|
print(self.pending_tasks)
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
if url.startswith('feed:'):
|
if url.startswith('feed:'):
|
||||||
|
@ -687,6 +716,9 @@ async def message(self, message):
|
||||||
'added to subscription list.'
|
'added to subscription list.'
|
||||||
.format(result['link'], result['name']))
|
.format(result['link'], result['name']))
|
||||||
# task.clean_tasks_xmpp(self, jid_bare, ['status'])
|
# task.clean_tasks_xmpp(self, jid_bare, ['status'])
|
||||||
|
print(self.pending_tasks)
|
||||||
|
del self.pending_tasks[jid_bare][pending_tasks_num]
|
||||||
|
print(self.pending_tasks)
|
||||||
key_list = ['status']
|
key_list = ['status']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
# except:
|
# except:
|
||||||
|
@ -897,6 +929,8 @@ async def message(self, message):
|
||||||
status_type = 'dnd'
|
status_type = 'dnd'
|
||||||
status_message = ('📫️ Processing request to fetch data '
|
status_message = ('📫️ Processing request to fetch data '
|
||||||
'from {}'.format(url))
|
'from {}'.format(url))
|
||||||
|
|
||||||
|
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
if url.startswith('feed:'):
|
if url.startswith('feed:'):
|
||||||
|
@ -927,6 +961,7 @@ async def message(self, message):
|
||||||
'\n'
|
'\n'
|
||||||
'Missing URL.')
|
'Missing URL.')
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
|
del self.pending_tasks[jid_bare][pending_tasks_num]
|
||||||
key_list = ['status']
|
key_list = ['status']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
case _ if message_lowercase.startswith('recent '):
|
case _ if message_lowercase.startswith('recent '):
|
||||||
|
@ -1003,6 +1038,9 @@ async def message(self, message):
|
||||||
task.clean_tasks_xmpp(self, jid_bare, key_list)
|
task.clean_tasks_xmpp(self, jid_bare, key_list)
|
||||||
status_type = 'dnd'
|
status_type = 'dnd'
|
||||||
status_message = '📫️ Marking entries as read...'
|
status_message = '📫️ Marking entries as read...'
|
||||||
|
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||||
|
pending_tasks_num = randrange(10000, 99999)
|
||||||
|
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
|
@ -1044,6 +1082,7 @@ async def message(self, message):
|
||||||
await sqlite.mark_all_as_read(db_file)
|
await sqlite.mark_all_as_read(db_file)
|
||||||
response = 'All entries have been marked as read.'
|
response = 'All entries have been marked as read.'
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
|
del self.pending_tasks[jid_bare][pending_tasks_num]
|
||||||
key_list = ['status']
|
key_list = ['status']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
case _ if message_lowercase.startswith('search '):
|
case _ if message_lowercase.startswith('search '):
|
||||||
|
|
Loading…
Reference in a new issue