2024-01-02 12:42:41 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
1) Deprecate "add" (see above) and make it interactive.
|
|
|
|
Slixfeed: Do you still want to add this URL to subscription list?
|
|
|
|
See: case _ if message_lowercase.startswith("add"):
|
|
|
|
|
|
|
|
2) If subscription is inadequate (see state.request), send a message that says so.
|
|
|
|
|
|
|
|
elif not self.client_roster[jid]["to"]:
|
|
|
|
breakpoint()
|
|
|
|
message.reply("Share online status to activate bot.").send()
|
|
|
|
return
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2024-01-09 13:34:10 +01:00
|
|
|
import logging
|
2024-01-02 12:42:41 +01:00
|
|
|
import os
|
2024-01-04 02:16:24 +01:00
|
|
|
import slixfeed.action as action
|
2024-01-02 12:42:41 +01:00
|
|
|
from slixfeed.config import (
|
|
|
|
add_to_list,
|
2024-01-22 16:27:01 +01:00
|
|
|
get_default_cache_directory,
|
2024-01-06 23:03:08 +01:00
|
|
|
get_default_data_directory,
|
2024-01-02 12:42:41 +01:00
|
|
|
get_value,
|
|
|
|
get_pathname_to_database,
|
|
|
|
remove_from_list)
|
2024-01-18 21:57:49 +01:00
|
|
|
from slixfeed.dt import current_time, timestamp
|
2024-01-27 18:15:28 +01:00
|
|
|
import slixfeed.fetch as fetch
|
2024-01-02 12:42:41 +01:00
|
|
|
import slixfeed.sqlite as sqlite
|
|
|
|
import slixfeed.task as task
|
|
|
|
import slixfeed.url as uri
|
|
|
|
import slixfeed.xmpp.bookmark as bookmark
|
2024-01-27 18:15:28 +01:00
|
|
|
import slixfeed.xmpp.muc as groupchat
|
2024-02-04 18:08:12 +01:00
|
|
|
import slixfeed.xmpp.status as status
|
2024-01-03 11:37:33 +01:00
|
|
|
import slixfeed.xmpp.upload as upload
|
2024-01-27 18:15:28 +01:00
|
|
|
from slixfeed.xmpp.utility import get_chat_type
|
|
|
|
import time
|
2024-01-02 12:42:41 +01:00
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
async def event_component(self):
|
2024-01-24 19:11:39 +01:00
|
|
|
self.send_presence()
|
|
|
|
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
async def event(self):
|
2024-01-02 12:42:41 +01:00
|
|
|
self.send_presence()
|
|
|
|
await self.get_roster()
|
|
|
|
|
|
|
|
# for task in main_task:
|
|
|
|
# task.cancel()
|
|
|
|
|
|
|
|
# Deprecated in favour of event "presence_available"
|
|
|
|
# if not main_task:
|
|
|
|
# await select_file()
|
|
|
|
|
|
|
|
|
|
|
|
async def message(self, message):
|
|
|
|
"""
|
|
|
|
Process incoming message stanzas. Be aware that this also
|
|
|
|
includes MUC messages and error messages. It is usually
|
|
|
|
a good practice to check the messages's type before
|
|
|
|
processing or sending replies.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
message : str
|
|
|
|
The received message stanza. See the documentation
|
|
|
|
for stanza objects and the Message stanza to see
|
|
|
|
how it may be used.
|
|
|
|
"""
|
2024-01-27 18:15:28 +01:00
|
|
|
if message['type'] in ('chat', 'groupchat', 'normal'):
|
|
|
|
jid = message['from'].bare
|
|
|
|
jid_file = jid
|
|
|
|
message_text = ' '.join(message['body'].split())
|
|
|
|
command_time_start = time.time()
|
|
|
|
|
|
|
|
# if (message['type'] == 'groupchat' and
|
2024-01-24 19:11:39 +01:00
|
|
|
# message['muc']['nick'] == self.alias):
|
2024-01-23 15:37:10 +01:00
|
|
|
# return
|
|
|
|
|
|
|
|
# FIXME Code repetition. See below.
|
2024-01-26 12:34:07 +01:00
|
|
|
# TODO Check alias by nickname associated with conference
|
2024-01-27 18:15:28 +01:00
|
|
|
if message['type'] == 'groupchat':
|
2024-01-24 19:11:39 +01:00
|
|
|
if (message['muc']['nick'] == self.alias):
|
2024-01-23 15:37:10 +01:00
|
|
|
return
|
2024-01-27 18:15:28 +01:00
|
|
|
jid_full = str(message['from'])
|
2024-01-23 15:37:10 +01:00
|
|
|
role = self.plugin['xep_0045'].get_jid_property(
|
2024-02-04 18:08:12 +01:00
|
|
|
jid, jid_full[jid_full.index('/')+1:], 'role')
|
2024-01-27 18:15:28 +01:00
|
|
|
if role != 'moderator':
|
2024-01-14 13:46:38 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
# NOTE This is an exceptional case in which we treat
|
2024-01-23 15:37:10 +01:00
|
|
|
# type groupchat the same as type chat in a way that
|
|
|
|
# doesn't require an exclamation mark for actionable
|
|
|
|
# command.
|
2024-01-27 18:15:28 +01:00
|
|
|
if (message_text.lower().startswith('http') and
|
|
|
|
message_text.lower().endswith('.opml')):
|
2024-01-09 13:34:10 +01:00
|
|
|
url = message_text
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.clean_tasks_xmpp(jid, ['status'])
|
2024-01-27 18:15:28 +01:00
|
|
|
status_type = 'dnd'
|
2024-02-04 18:08:12 +01:00
|
|
|
status_message = '📥️ Procesing request to import feeds...'
|
|
|
|
status.send(
|
|
|
|
self, jid, status_message, status_type)
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-09 13:34:10 +01:00
|
|
|
count = await action.import_opml(db_file, url)
|
|
|
|
if count:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'Successfully imported {} feeds.'.format(count)
|
2024-01-09 13:34:10 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'OPML file was not imported.'
|
|
|
|
# await task.clean_tasks_xmpp(jid, ['status'])
|
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-01-09 13:34:10 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-10 21:06:56 +01:00
|
|
|
return
|
2024-01-09 13:34:10 +01:00
|
|
|
|
|
|
|
|
2024-01-27 18:15:28 +01:00
|
|
|
if message['type'] == 'groupchat':
|
|
|
|
# nick = message['from'][message['from'].index('/')+1:]
|
|
|
|
# nick = str(message['from'])
|
|
|
|
# nick = nick[nick.index('/')+1:]
|
2024-01-24 19:11:39 +01:00
|
|
|
if (message['muc']['nick'] == self.alias or
|
2024-01-27 18:15:28 +01:00
|
|
|
not message['body'].startswith('!')):
|
2024-01-02 12:42:41 +01:00
|
|
|
return
|
|
|
|
# token = await initdb(
|
|
|
|
# jid,
|
|
|
|
# get_settings_value,
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'token'
|
2024-01-02 12:42:41 +01:00
|
|
|
# )
|
2024-01-27 18:15:28 +01:00
|
|
|
# if token == 'accepted':
|
2024-01-02 12:42:41 +01:00
|
|
|
# operator = await initdb(
|
|
|
|
# jid,
|
|
|
|
# get_settings_value,
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'masters'
|
2024-01-02 12:42:41 +01:00
|
|
|
# )
|
|
|
|
# if operator:
|
|
|
|
# if nick not in operator:
|
|
|
|
# return
|
|
|
|
# approved = False
|
2024-01-27 18:15:28 +01:00
|
|
|
jid_full = str(message['from'])
|
2024-01-02 12:42:41 +01:00
|
|
|
role = self.plugin['xep_0045'].get_jid_property(
|
2024-02-04 18:08:12 +01:00
|
|
|
jid, jid_full[jid_full.index('/')+1:], 'role')
|
2024-01-27 18:15:28 +01:00
|
|
|
if role != 'moderator':
|
2024-01-02 12:42:41 +01:00
|
|
|
return
|
2024-01-27 18:15:28 +01:00
|
|
|
# if role == 'moderator':
|
2024-01-02 12:42:41 +01:00
|
|
|
# approved = True
|
|
|
|
# TODO Implement a list of temporary operators
|
|
|
|
# Once an operator is appointed, the control would last
|
|
|
|
# untile the participant has been disconnected from MUC
|
|
|
|
# An operator is a function to appoint non moderators.
|
|
|
|
# Changing nickname is fine and consist of no problem.
|
|
|
|
# if not approved:
|
|
|
|
# operator = await initdb(
|
|
|
|
# jid,
|
|
|
|
# get_settings_value,
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'masters'
|
2024-01-02 12:42:41 +01:00
|
|
|
# )
|
|
|
|
# if operator:
|
|
|
|
# if nick in operator:
|
|
|
|
# approved = True
|
|
|
|
# if not approved:
|
|
|
|
# return
|
|
|
|
|
|
|
|
# # Begin processing new JID
|
2024-01-27 18:15:28 +01:00
|
|
|
# # Deprecated in favour of event 'presence_available'
|
2024-01-06 23:03:08 +01:00
|
|
|
# db_dir = get_default_data_directory()
|
2024-01-02 12:42:41 +01:00
|
|
|
# os.chdir(db_dir)
|
2024-01-27 18:15:28 +01:00
|
|
|
# if jid + '.db' not in os.listdir():
|
2024-01-02 12:42:41 +01:00
|
|
|
# await task_jid(jid)
|
|
|
|
|
|
|
|
# await compose.message(self, jid, message)
|
|
|
|
|
2024-01-27 18:15:28 +01:00
|
|
|
if message['type'] == 'groupchat':
|
2024-01-02 12:42:41 +01:00
|
|
|
message_text = message_text[1:]
|
|
|
|
message_lowercase = message_text.lower()
|
2024-01-27 18:15:28 +01:00
|
|
|
|
|
|
|
logging.debug([str(message['from']), ':', message_text])
|
|
|
|
|
|
|
|
# Support private message via groupchat
|
2024-01-28 12:17:31 +01:00
|
|
|
# See https://codeberg.org/poezio/slixmpp/issues/3506
|
2024-01-27 18:15:28 +01:00
|
|
|
if message['type'] == 'chat' and message.get_plugin('muc', check=True):
|
|
|
|
jid_bare = message['from'].bare
|
|
|
|
jid_full = str(message['from'])
|
|
|
|
if (jid_bare == jid_full[:jid_full.index('/')]):
|
|
|
|
jid = str(message['from'])
|
|
|
|
jid_file = jid_full.replace('/', '_')
|
|
|
|
|
2024-01-09 13:34:10 +01:00
|
|
|
response = None
|
2024-01-02 12:42:41 +01:00
|
|
|
match message_lowercase:
|
2024-01-27 18:15:28 +01:00
|
|
|
# case 'breakpoint':
|
|
|
|
# if jid == get_value('accounts', 'XMPP', 'operator'):
|
2024-01-02 13:52:37 +01:00
|
|
|
# breakpoint()
|
2024-01-27 18:15:28 +01:00
|
|
|
# print('task_manager[jid]')
|
2024-01-09 13:34:10 +01:00
|
|
|
# print(task_manager[jid])
|
|
|
|
# await self.get_roster()
|
2024-01-27 18:15:28 +01:00
|
|
|
# print('roster 1')
|
2024-01-09 13:34:10 +01:00
|
|
|
# print(self.client_roster)
|
2024-01-27 18:15:28 +01:00
|
|
|
# print('roster 2')
|
2024-01-09 13:34:10 +01:00
|
|
|
# print(self.client_roster.keys())
|
2024-01-27 18:15:28 +01:00
|
|
|
# print('jid')
|
2024-01-09 13:34:10 +01:00
|
|
|
# print(jid)
|
2024-01-02 13:52:37 +01:00
|
|
|
# else:
|
|
|
|
# response = (
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'This action is restricted. '
|
|
|
|
# 'Type: breakpoint.'
|
2024-01-02 13:52:37 +01:00
|
|
|
# )
|
|
|
|
# send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'help':
|
2024-01-28 12:17:31 +01:00
|
|
|
command_list = ' '.join(action.manual('commands.toml'))
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Available command keys:\n'
|
|
|
|
'```\n{}\n```\n'
|
|
|
|
'Usage: `help <key>`'
|
|
|
|
.format(command_list))
|
|
|
|
print(response)
|
2024-01-27 20:21:45 +01:00
|
|
|
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]
|
2024-02-04 18:08:12 +01:00
|
|
|
command_list = action.manual('commands.toml',
|
|
|
|
section=command_root,
|
|
|
|
command=command_name)
|
2024-01-28 12:17:31 +01:00
|
|
|
if command_list:
|
|
|
|
command_list = ''.join(command_list)
|
|
|
|
response = (command_list)
|
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('KeyError for {} {}'
|
|
|
|
.format(command_root, command_name))
|
2024-01-27 20:21:45 +01:00
|
|
|
elif len(command) == 1:
|
|
|
|
command = command[0]
|
2024-01-28 12:17:31 +01:00
|
|
|
command_list = action.manual('commands.toml', command)
|
|
|
|
if command_list:
|
|
|
|
command_list = ' '.join(command_list)
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Available command `{}` keys:\n'
|
|
|
|
'```\n{}\n```\n'
|
|
|
|
'Usage: `help {} <command>`'
|
|
|
|
.format(command, command_list, command))
|
2024-01-28 12:17:31 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'KeyError for {}'.format(command)
|
2024-01-27 20:21:45 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Invalid. Enter command key '
|
|
|
|
'or command key & name')
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'info':
|
2024-01-28 12:17:31 +01:00
|
|
|
command_list = ' '.join(action.manual('information.toml'))
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Available command options:\n'
|
|
|
|
'```\n{}\n```\n'
|
|
|
|
'Usage: `info <option>`'
|
|
|
|
.format(command_list))
|
2024-01-28 12:17:31 +01:00
|
|
|
send_reply_message(self, message, response)
|
|
|
|
case _ if message_lowercase.startswith('info'):
|
|
|
|
command = message_text[5:]
|
2024-02-04 18:08:12 +01:00
|
|
|
command_list = action.manual('information.toml', command)
|
2024-01-28 12:17:31 +01:00
|
|
|
if command_list:
|
|
|
|
# command_list = '\n'.join(command_list)
|
|
|
|
response = (command_list)
|
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('KeyError for {}'
|
|
|
|
.format(command))
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-02-04 18:08:12 +01:00
|
|
|
case _ if message_lowercase in ['greetings', 'hallo', 'hello',
|
|
|
|
'hey', 'hi', 'hola', 'holla',
|
|
|
|
'hollo']:
|
|
|
|
response = ('Greeting! My name is {}.\n'
|
|
|
|
'I am an RSS News Bot.\n'
|
|
|
|
'Send "help" for further instructions.\n'
|
|
|
|
.format(self.alias))
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
|
|
|
|
2024-01-27 18:15:28 +01:00
|
|
|
# case _ if message_lowercase.startswith('activate'):
|
|
|
|
# if message['type'] == 'groupchat':
|
2024-01-02 12:42:41 +01:00
|
|
|
# acode = message[9:]
|
|
|
|
# token = await initdb(
|
|
|
|
# jid,
|
|
|
|
# get_settings_value,
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'token'
|
2024-01-02 12:42:41 +01:00
|
|
|
# )
|
|
|
|
# if int(acode) == token:
|
|
|
|
# await initdb(
|
|
|
|
# jid,
|
2024-01-14 13:46:38 +01:00
|
|
|
# update_settings_value,
|
2024-01-27 18:15:28 +01:00
|
|
|
# ['masters', nick]
|
2024-01-02 12:42:41 +01:00
|
|
|
# )
|
|
|
|
# await initdb(
|
|
|
|
# jid,
|
2024-01-14 13:46:38 +01:00
|
|
|
# update_settings_value,
|
2024-01-27 18:15:28 +01:00
|
|
|
# ['token', 'accepted']
|
2024-01-02 12:42:41 +01:00
|
|
|
# )
|
2024-01-27 18:15:28 +01:00
|
|
|
# response = '{}, your are in command.'.format(nick)
|
2024-01-02 12:42:41 +01:00
|
|
|
# else:
|
2024-01-27 18:15:28 +01:00
|
|
|
# response = 'Activation code is not valid.'
|
2024-01-02 12:42:41 +01:00
|
|
|
# else:
|
2024-01-27 18:15:28 +01:00
|
|
|
# response = 'This command is valid for groupchat only.'
|
|
|
|
case _ if message_lowercase.startswith('add'):
|
2024-01-04 02:16:24 +01:00
|
|
|
# Add given feed without validity check.
|
2024-01-02 12:42:41 +01:00
|
|
|
message_text = message_text[4:]
|
2024-01-27 18:15:28 +01:00
|
|
|
url = message_text.split(' ')[0]
|
|
|
|
title = ' '.join(message_text.split(' ')[1:])
|
2024-02-04 18:08:12 +01:00
|
|
|
if not title:
|
|
|
|
title = uri.get_hostname(url)
|
2024-01-27 18:15:28 +01:00
|
|
|
if url.startswith('http'):
|
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
exist = await sqlite.get_feed_id_and_name(db_file, url)
|
2024-01-04 02:16:24 +01:00
|
|
|
if not exist:
|
2024-02-04 18:08:12 +01:00
|
|
|
await sqlite.insert_feed(db_file, url, title)
|
2024-01-06 23:03:08 +01:00
|
|
|
await action.scan(db_file, url)
|
2024-02-04 19:56:19 +01:00
|
|
|
old = await config.get_setting_value(db_file, "old")
|
2024-01-04 02:16:24 +01:00
|
|
|
if old:
|
2024-02-04 18:08:12 +01:00
|
|
|
# await task.clean_tasks_xmpp(jid, ['status'])
|
2024-01-04 02:16:24 +01:00
|
|
|
# await send_status(jid)
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-01-04 02:16:24 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
feed_id = await sqlite.get_feed_id(db_file, url)
|
|
|
|
feed_id = feed_id[0]
|
|
|
|
await sqlite.mark_feed_as_read(db_file, feed_id)
|
|
|
|
response = ('> {}\n'
|
|
|
|
'News source has been '
|
|
|
|
'added to subscription list.'
|
|
|
|
.format(url))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-04 02:16:24 +01:00
|
|
|
ix = exist[0]
|
|
|
|
name = exist[1]
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('> {}\n'
|
|
|
|
'News source "{}" is already '
|
|
|
|
'listed in the subscription list at '
|
|
|
|
'index {}'
|
|
|
|
.format(url, name, ix))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing URL.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('allow +'):
|
|
|
|
key = 'filter-' + message_text[:5]
|
2024-01-02 12:42:41 +01:00
|
|
|
val = message_text[7:]
|
|
|
|
if val:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
keywords = await sqlite.get_filters_value(db_file, key)
|
|
|
|
val = await add_to_list(val, keywords)
|
2024-01-14 13:46:38 +01:00
|
|
|
if await sqlite.get_filters_value(db_file, key):
|
2024-02-04 18:08:12 +01:00
|
|
|
await sqlite.update_filters_value(db_file,
|
|
|
|
[key, val])
|
2024-01-14 13:46:38 +01:00
|
|
|
else:
|
|
|
|
await sqlite.set_filters_value(db_file, [key, val])
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Approved keywords\n'
|
|
|
|
'```\n{}\n```'
|
|
|
|
.format(val))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing keywords.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('allow -'):
|
|
|
|
key = 'filter-' + message_text[:5]
|
2024-01-02 12:42:41 +01:00
|
|
|
val = message_text[7:]
|
|
|
|
if val:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
keywords = await sqlite.get_filters_value(db_file, key)
|
|
|
|
val = await remove_from_list(val, keywords)
|
2024-01-14 13:46:38 +01:00
|
|
|
if await sqlite.get_filters_value(db_file, key):
|
2024-02-04 18:08:12 +01:00
|
|
|
await sqlite.update_filters_value(db_file,
|
|
|
|
[key, val])
|
2024-01-14 13:46:38 +01:00
|
|
|
else:
|
|
|
|
await sqlite.set_filters_value(db_file, [key, val])
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Approved keywords\n'
|
|
|
|
'```\n{}\n```'
|
|
|
|
.format(val))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing keywords.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('archive'):
|
2024-01-02 12:42:41 +01:00
|
|
|
key = message_text[:7]
|
|
|
|
val = message_text[8:]
|
|
|
|
if val:
|
|
|
|
try:
|
|
|
|
if int(val) > 500:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Value may not be greater than 500.'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
if await sqlite.get_settings_value(db_file,
|
|
|
|
[key, val]):
|
|
|
|
await sqlite.update_settings_value(db_file,
|
|
|
|
[key, val])
|
2024-01-14 13:46:38 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
await sqlite.set_settings_value(db_file,
|
|
|
|
[key, val])
|
|
|
|
response = ('Maximum archived items has '
|
|
|
|
'been set to {}.'
|
|
|
|
.format(val))
|
2024-01-02 12:42:41 +01:00
|
|
|
except:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Enter a numeric value only.'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing value.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('bookmark -'):
|
2024-02-04 18:08:12 +01:00
|
|
|
if jid == get_value('accounts', 'XMPP', 'operator'):
|
2024-01-02 12:42:41 +01:00
|
|
|
muc_jid = message_text[11:]
|
|
|
|
await bookmark.remove(self, muc_jid)
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Groupchat {} has been removed '
|
|
|
|
'from bookmarks.'
|
|
|
|
.format(muc_jid))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('This action is restricted. '
|
|
|
|
'Type: removing bookmarks.')
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'bookmarks':
|
2024-02-04 18:08:12 +01:00
|
|
|
if jid == get_value('accounts', 'XMPP', 'operator'):
|
2024-01-06 23:03:08 +01:00
|
|
|
response = await action.list_bookmarks(self)
|
2024-01-02 13:12:29 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('This action is restricted. '
|
|
|
|
'Type: viewing bookmarks.')
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('deny +'):
|
|
|
|
key = 'filter-' + message_text[:4]
|
2024-01-02 12:42:41 +01:00
|
|
|
val = message_text[6:]
|
|
|
|
if val:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
keywords = await sqlite.get_filters_value(db_file, key)
|
|
|
|
val = await add_to_list(val, keywords)
|
2024-01-14 13:46:38 +01:00
|
|
|
if await sqlite.get_filters_value(db_file, key):
|
2024-02-04 18:08:12 +01:00
|
|
|
await sqlite.update_filters_value(db_file,
|
|
|
|
[key, val])
|
2024-01-14 13:46:38 +01:00
|
|
|
else:
|
|
|
|
await sqlite.set_filters_value(db_file, [key, val])
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Rejected keywords\n'
|
|
|
|
'```\n{}\n```'
|
|
|
|
.format(val))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing keywords.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('deny -'):
|
|
|
|
key = 'filter-' + message_text[:4]
|
2024-01-02 12:42:41 +01:00
|
|
|
val = message_text[6:]
|
|
|
|
if val:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
keywords = await sqlite.get_filters_value(db_file, key)
|
|
|
|
val = await remove_from_list(val, keywords)
|
2024-01-14 13:46:38 +01:00
|
|
|
if await sqlite.get_filters_value(db_file, key):
|
2024-02-04 18:08:12 +01:00
|
|
|
await sqlite.update_filters_value(db_file,
|
|
|
|
[key, val])
|
2024-01-14 13:46:38 +01:00
|
|
|
else:
|
|
|
|
await sqlite.set_filters_value(db_file, [key, val])
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Rejected keywords\n'
|
|
|
|
'```\n{}\n```'
|
|
|
|
.format(val))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing keywords.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('export'):
|
2024-01-09 23:36:16 +01:00
|
|
|
ex = message_text[7:]
|
2024-01-27 18:15:28 +01:00
|
|
|
if ex in ('opml', 'html', 'md', 'xbel'):
|
|
|
|
status_type = 'dnd'
|
2024-02-04 18:08:12 +01:00
|
|
|
status_message = ('📤️ Procesing request to '
|
|
|
|
'export feeds into {}...'
|
|
|
|
.format(ex))
|
|
|
|
status.send(
|
|
|
|
self, jid, status_message, status_type)
|
2024-01-22 16:27:01 +01:00
|
|
|
cache_dir = get_default_cache_directory()
|
|
|
|
if not os.path.isdir(cache_dir):
|
|
|
|
os.mkdir(cache_dir)
|
|
|
|
if not os.path.isdir(cache_dir + '/' + ex):
|
|
|
|
os.mkdir(cache_dir + '/' + ex)
|
2024-01-03 13:17:39 +01:00
|
|
|
filename = os.path.join(
|
2024-01-27 18:15:28 +01:00
|
|
|
cache_dir, ex, 'slixfeed_' + timestamp() + '.' + ex)
|
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-03 13:17:39 +01:00
|
|
|
results = await sqlite.get_feeds(db_file)
|
2024-01-10 21:06:56 +01:00
|
|
|
match ex:
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'html':
|
|
|
|
response = 'Not yet implemented.'
|
|
|
|
case 'md':
|
2024-02-04 18:08:12 +01:00
|
|
|
action.export_to_markdown(jid, filename, results)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'opml':
|
2024-02-04 18:08:12 +01:00
|
|
|
action.export_to_opml(jid, filename, results)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'xbel':
|
|
|
|
response = 'Not yet implemented.'
|
2024-01-03 13:17:39 +01:00
|
|
|
url = await upload.start(self, jid, filename)
|
2024-01-09 23:36:16 +01:00
|
|
|
# response = (
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'Feeds exported successfully to {}.\n{}'
|
2024-01-10 21:06:56 +01:00
|
|
|
# ).format(ex, url)
|
2024-01-03 11:37:33 +01:00
|
|
|
# send_oob_reply_message(message, url, response)
|
2024-02-04 18:08:12 +01:00
|
|
|
await send_oob_message(self, jid, url)
|
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-01-03 13:17:39 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Unsupported filetype.\n'
|
|
|
|
'Try: html, md, opml, or xbel')
|
2024-01-06 23:03:08 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if (message_lowercase.startswith('gemini:') or
|
2024-02-04 18:08:12 +01:00
|
|
|
message_lowercase.startswith('gopher:')):
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Gemini and Gopher are not supported yet.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-09 16:53:19 +01:00
|
|
|
# TODO xHTML, HTMLZ, Markdown, MHTML, PDF, TXT
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if (message_lowercase.startswith('get')):
|
2024-01-09 16:53:19 +01:00
|
|
|
message_text = message_text[4:]
|
2024-01-27 18:15:28 +01:00
|
|
|
ix_url = message_text.split(' ')[0]
|
|
|
|
ext = ' '.join(message_text.split(' ')[1:])
|
2024-01-09 23:36:16 +01:00
|
|
|
ext = ext if ext else 'pdf'
|
2024-01-11 11:55:42 +01:00
|
|
|
url = None
|
2024-01-22 16:27:01 +01:00
|
|
|
error = None
|
2024-02-04 18:08:12 +01:00
|
|
|
if ext in ('epub', 'html', 'markdown',
|
|
|
|
'md', 'pdf', 'text', 'txt'):
|
2024-01-24 19:11:39 +01:00
|
|
|
match ext:
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'markdown':
|
|
|
|
ext = 'md'
|
|
|
|
case 'text':
|
|
|
|
ext = 'txt'
|
|
|
|
status_type = 'dnd'
|
2024-02-04 18:08:12 +01:00
|
|
|
status_message = ('📃️ Procesing request to '
|
|
|
|
'produce {} document...'
|
|
|
|
.format(ext.upper()))
|
|
|
|
status.send(self, jid, status_message, status_type)
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-22 16:27:01 +01:00
|
|
|
cache_dir = get_default_cache_directory()
|
2024-01-09 23:36:16 +01:00
|
|
|
if ix_url:
|
2024-01-22 16:27:01 +01:00
|
|
|
if not os.path.isdir(cache_dir):
|
|
|
|
os.mkdir(cache_dir)
|
|
|
|
if not os.path.isdir(cache_dir + '/readability'):
|
|
|
|
os.mkdir(cache_dir + '/readability')
|
2024-01-09 23:36:16 +01:00
|
|
|
try:
|
|
|
|
ix = int(ix_url)
|
|
|
|
try:
|
|
|
|
url = sqlite.get_entry_url(db_file, ix)
|
|
|
|
except:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'No entry with index {}'.format(ix)
|
2024-01-09 23:36:16 +01:00
|
|
|
except:
|
|
|
|
url = ix_url
|
2024-01-11 11:55:42 +01:00
|
|
|
if url:
|
2024-02-04 18:08:12 +01:00
|
|
|
logging.info('Original URL: {}'
|
|
|
|
.format(url))
|
2024-01-11 11:55:42 +01:00
|
|
|
url = uri.remove_tracking_parameters(url)
|
2024-02-04 18:08:12 +01:00
|
|
|
logging.info('Processed URL (tracker removal): {}'
|
|
|
|
.format(url))
|
2024-01-27 18:15:28 +01:00
|
|
|
url = (uri.replace_hostname(url, 'link')) or url
|
2024-02-04 18:08:12 +01:00
|
|
|
logging.info('Processed URL (replace hostname): {}'
|
|
|
|
.format(url))
|
2024-01-13 18:17:43 +01:00
|
|
|
result = await fetch.http(url)
|
|
|
|
data = result[0]
|
|
|
|
code = result[1]
|
|
|
|
if data:
|
|
|
|
title = action.get_document_title(data)
|
|
|
|
title = title.strip().lower()
|
2024-01-27 18:15:28 +01:00
|
|
|
for i in (' ', '-'):
|
|
|
|
title = title.replace(i, '_')
|
|
|
|
for i in ('?', '"', '\'', '!'):
|
|
|
|
title = title.replace(i, '')
|
2024-01-13 18:17:43 +01:00
|
|
|
filename = os.path.join(
|
2024-01-27 18:15:28 +01:00
|
|
|
cache_dir, 'readability',
|
|
|
|
title + '_' + timestamp() + '.' + ext)
|
2024-02-04 18:08:12 +01:00
|
|
|
error = action.generate_document(data, url,
|
|
|
|
ext, filename)
|
2024-01-22 16:27:01 +01:00
|
|
|
if error:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('> {}\n'
|
|
|
|
'Failed to export {}. '
|
|
|
|
'Reason: {}'
|
|
|
|
.format(url, ext.upper(),
|
|
|
|
error))
|
2024-01-22 16:01:52 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
url = await upload.start(self, jid,
|
|
|
|
filename)
|
2024-01-13 18:17:43 +01:00
|
|
|
await send_oob_message(self, jid, url)
|
2024-01-11 11:55:42 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('> {}\n'
|
|
|
|
'Failed to fetch URL. Reason: {}'
|
|
|
|
.format(url, code))
|
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-01-09 16:53:19 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing entry index number.'
|
2024-01-09 16:53:19 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Unsupported filetype.\n'
|
|
|
|
'Try: epub, html, md (markdown), '
|
|
|
|
'pdf, or txt (text)')
|
2024-01-09 16:53:19 +01:00
|
|
|
if response:
|
2024-01-27 18:15:28 +01:00
|
|
|
logging.warning('Error for URL {}: {}'.format(url, error))
|
2024-01-09 16:53:19 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
# case _ if (message_lowercase.startswith('http')) and(
|
|
|
|
# message_lowercase.endswith('.opml')):
|
2024-01-09 13:34:10 +01:00
|
|
|
# url = message_text
|
|
|
|
# await task.clean_tasks_xmpp(
|
2024-01-27 18:15:28 +01:00
|
|
|
# jid, ['status'])
|
|
|
|
# status_type = 'dnd'
|
2024-01-09 13:34:10 +01:00
|
|
|
# status_message = (
|
2024-01-27 18:15:28 +01:00
|
|
|
# '📥️ Procesing request to import feeds...'
|
2024-01-09 13:34:10 +01:00
|
|
|
# )
|
2024-02-04 18:08:12 +01:00
|
|
|
# status.send(
|
|
|
|
# self, jid, status_message, status_type)
|
2024-01-27 18:15:28 +01:00
|
|
|
# db_file = get_pathname_to_database(jid_file)
|
2024-01-09 13:34:10 +01:00
|
|
|
# count = await action.import_opml(db_file, url)
|
|
|
|
# if count:
|
|
|
|
# response = (
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'Successfully imported {} feeds.'
|
2024-01-09 13:34:10 +01:00
|
|
|
# ).format(count)
|
|
|
|
# else:
|
|
|
|
# response = (
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'OPML file was not imported.'
|
2024-01-09 13:34:10 +01:00
|
|
|
# )
|
|
|
|
# await task.clean_tasks_xmpp(
|
2024-01-27 18:15:28 +01:00
|
|
|
# jid, ['status'])
|
2024-01-09 13:34:10 +01:00
|
|
|
# await task.start_tasks_xmpp(
|
2024-01-27 18:15:28 +01:00
|
|
|
# self, jid, ['status'])
|
2024-01-09 13:34:10 +01:00
|
|
|
# send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if (message_lowercase.startswith('http') or
|
2024-02-04 18:08:12 +01:00
|
|
|
message_lowercase.startswith('feed:')):
|
2024-01-02 12:42:41 +01:00
|
|
|
url = message_text
|
2024-02-04 18:08:12 +01:00
|
|
|
# await task.clean_tasks_xmpp(jid, ['status'])
|
2024-01-27 18:15:28 +01:00
|
|
|
status_type = 'dnd'
|
2024-02-04 18:08:12 +01:00
|
|
|
status_message = ('📫️ Processing request '
|
|
|
|
'to fetch data from {}'
|
|
|
|
.format(url))
|
|
|
|
status.send(self, jid, status_message, status_type)
|
2024-01-27 18:15:28 +01:00
|
|
|
if url.startswith('feed:'):
|
2024-01-02 12:42:41 +01:00
|
|
|
url = uri.feed_to_http(url)
|
2024-01-27 18:15:28 +01:00
|
|
|
url = (uri.replace_hostname(url, 'feed')) or url
|
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-28 12:17:31 +01:00
|
|
|
# try:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = await action.add_feed(db_file, url)
|
|
|
|
# await task.clean_tasks_xmpp(jid, ['status'])
|
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-01-28 12:17:31 +01:00
|
|
|
# except:
|
|
|
|
# response = (
|
|
|
|
# '> {}\nNews source is in the process '
|
|
|
|
# 'of being added to the subscription '
|
|
|
|
# 'list.'.format(url)
|
|
|
|
# )
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('feeds'):
|
2024-01-02 12:42:41 +01:00
|
|
|
query = message_text[6:]
|
|
|
|
if query:
|
|
|
|
if len(query) > 3:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
result = await sqlite.search_feeds(db_file, query)
|
|
|
|
response = action.list_feeds_by_query(query, result)
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'Enter at least 4 characters to search'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-02 12:42:41 +01:00
|
|
|
result = await sqlite.get_feeds(db_file)
|
2024-01-06 23:03:08 +01:00
|
|
|
response = action.list_feeds(result)
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'goodbye':
|
|
|
|
if message['type'] == 'groupchat':
|
2024-01-02 12:42:41 +01:00
|
|
|
await groupchat.leave(self, jid)
|
2024-02-04 18:08:12 +01:00
|
|
|
await bookmark.remove(self, muc_jid)
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'This command is valid in groupchat only.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('interval'):
|
2024-01-02 12:42:41 +01:00
|
|
|
# FIXME
|
|
|
|
# The following error occurs only upon first attempt to set interval.
|
|
|
|
# /usr/lib/python3.11/asyncio/events.py:73: RuntimeWarning: coroutine 'Slixfeed.send_update' was never awaited
|
|
|
|
# self._args = None
|
|
|
|
# RuntimeWarning: Enable tracemalloc to get the object allocation traceback
|
|
|
|
key = message_text[:8]
|
|
|
|
val = message_text[9:]
|
|
|
|
if val:
|
|
|
|
# response = (
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'Updates will be sent every {} minutes.'
|
2024-01-02 12:42:41 +01:00
|
|
|
# ).format(response)
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-14 13:46:38 +01:00
|
|
|
if await sqlite.get_settings_value(db_file, key):
|
|
|
|
await sqlite.update_settings_value(db_file, [key, val])
|
|
|
|
else:
|
|
|
|
await sqlite.set_settings_value(db_file, [key, val])
|
2024-01-02 12:42:41 +01:00
|
|
|
# NOTE Perhaps this should be replaced
|
|
|
|
# by functions clean and start
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.refresh_task(self, jid, task.send_update,
|
|
|
|
key, val)
|
|
|
|
response = ('Updates will be sent every {} minutes.'
|
|
|
|
.format(val))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing value.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('join'):
|
2024-01-02 12:42:41 +01:00
|
|
|
muc_jid = uri.check_xmpp_uri(message_text[5:])
|
|
|
|
if muc_jid:
|
|
|
|
# TODO probe JID and confirm it's a groupchat
|
|
|
|
await groupchat.join(self, jid, muc_jid)
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Joined groupchat {}'
|
|
|
|
.format(message_text))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('> {}\n'
|
|
|
|
'XMPP URI is not valid.'
|
|
|
|
.format(message_text))
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('length'):
|
2024-01-02 12:42:41 +01:00
|
|
|
key = message_text[:6]
|
|
|
|
val = message_text[7:]
|
|
|
|
if val:
|
|
|
|
try:
|
|
|
|
val = int(val)
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
if await sqlite.get_settings_value(db_file,
|
|
|
|
[key, val]):
|
|
|
|
await sqlite.update_settings_value(db_file,
|
|
|
|
[key, val])
|
2024-01-14 13:46:38 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
await sqlite.set_settings_value(db_file,
|
|
|
|
[key, val])
|
2024-01-04 14:58:06 +01:00
|
|
|
if val == 0: # if not val:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'Summary length limit is disabled.'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Summary maximum length '
|
|
|
|
'is set to {} characters.'
|
|
|
|
.format(val))
|
2024-01-02 12:42:41 +01:00
|
|
|
except:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Enter a numeric value only.'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing value.'
|
|
|
|
# case _ if message_lowercase.startswith('mastership'):
|
2024-01-02 12:42:41 +01:00
|
|
|
# key = message_text[:7]
|
|
|
|
# val = message_text[11:]
|
|
|
|
# if val:
|
|
|
|
# names = await initdb(
|
|
|
|
# jid,
|
|
|
|
# get_settings_value,
|
|
|
|
# key
|
|
|
|
# )
|
|
|
|
# val = await add_to_list(
|
|
|
|
# val,
|
|
|
|
# names
|
|
|
|
# )
|
|
|
|
# await initdb(
|
|
|
|
# jid,
|
2024-01-14 13:46:38 +01:00
|
|
|
# update_settings_valuevv,
|
2024-01-02 12:42:41 +01:00
|
|
|
# [key, val]
|
|
|
|
# )
|
|
|
|
# response = (
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'Operators\n'
|
|
|
|
# '```\n{}\n```'
|
2024-01-02 12:42:41 +01:00
|
|
|
# ).format(val)
|
|
|
|
# else:
|
2024-01-27 18:15:28 +01:00
|
|
|
# response = 'Missing value.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'new':
|
|
|
|
db_file = get_pathname_to_database(jid_file)
|
|
|
|
key = 'old'
|
2024-01-14 13:46:38 +01:00
|
|
|
val = 0
|
|
|
|
if await sqlite.get_settings_value(db_file, key):
|
|
|
|
await sqlite.update_settings_value(db_file, [key, val])
|
|
|
|
else:
|
|
|
|
await sqlite.set_settings_value(db_file, [key, val])
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'Only new items of newly added feeds will be sent.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
|
|
|
# TODO Will you add support for number of messages?
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'next':
|
2024-01-02 12:42:41 +01:00
|
|
|
# num = message_text[5:]
|
2024-01-26 12:34:07 +01:00
|
|
|
# await task.send_update(self, jid, num)
|
|
|
|
|
|
|
|
await task.send_update(self, jid)
|
|
|
|
|
|
|
|
# await task.clean_tasks_xmpp(
|
2024-01-27 18:15:28 +01:00
|
|
|
# jid, ['interval', 'status'])
|
2024-01-26 12:34:07 +01:00
|
|
|
# await task.start_tasks_xmpp(
|
2024-01-27 18:15:28 +01:00
|
|
|
# self, jid, ['interval', 'status'])
|
2024-01-26 12:34:07 +01:00
|
|
|
|
2024-01-02 12:42:41 +01:00
|
|
|
# await refresh_task(
|
|
|
|
# self,
|
|
|
|
# jid,
|
|
|
|
# send_update,
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'interval',
|
2024-01-02 12:42:41 +01:00
|
|
|
# num
|
|
|
|
# )
|
|
|
|
# await refresh_task(
|
|
|
|
# self,
|
|
|
|
# jid,
|
|
|
|
# send_status,
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'status',
|
2024-01-02 12:42:41 +01:00
|
|
|
# 20
|
|
|
|
# )
|
|
|
|
# await refresh_task(jid, key, val)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'old':
|
|
|
|
db_file = get_pathname_to_database(jid_file)
|
|
|
|
key = 'old'
|
2024-01-14 13:46:38 +01:00
|
|
|
val = 1
|
|
|
|
if await sqlite.get_settings_value(db_file, key):
|
|
|
|
await sqlite.update_settings_value(db_file, [key, val])
|
|
|
|
else:
|
|
|
|
await sqlite.set_settings_value(db_file, [key, val])
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'All items of newly added feeds will be sent.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('quantum'):
|
2024-01-02 12:42:41 +01:00
|
|
|
key = message_text[:7]
|
|
|
|
val = message_text[8:]
|
|
|
|
if val:
|
|
|
|
try:
|
|
|
|
val = int(val)
|
|
|
|
# response = (
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'Every update will contain {} news items.'
|
2024-01-02 12:42:41 +01:00
|
|
|
# ).format(response)
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
if await sqlite.get_settings_value(db_file, key):
|
|
|
|
await sqlite.update_settings_value(db_file, [key, val])
|
2024-01-14 13:46:38 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
await sqlite.set_settings_value(db_file, [key, val])
|
|
|
|
response = ('Next update will contain {} news items.'
|
|
|
|
.format(val))
|
2024-01-02 12:42:41 +01:00
|
|
|
except:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Enter a numeric value only.'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing value.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'random':
|
2024-01-02 12:42:41 +01:00
|
|
|
# TODO /questions/2279706/select-random-row-from-a-sqlite-table
|
|
|
|
# NOTE sqlitehandler.get_entry_unread
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Updates will be sent by random order.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('read'):
|
2024-01-02 12:42:41 +01:00
|
|
|
data = message_text[5:]
|
|
|
|
data = data.split()
|
|
|
|
url = data[0]
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.clean_tasks_xmpp(jid, ['status'])
|
2024-01-27 18:15:28 +01:00
|
|
|
status_type = 'dnd'
|
2024-02-04 18:08:12 +01:00
|
|
|
status_message = ('📫️ Processing request to fetch data from {}'
|
|
|
|
.format(url))
|
|
|
|
status.send(
|
|
|
|
self, jid, status_message, status_type)
|
2024-01-27 18:15:28 +01:00
|
|
|
if url.startswith('feed:'):
|
2024-01-02 12:42:41 +01:00
|
|
|
url = uri.feed_to_http(url)
|
2024-01-27 18:15:28 +01:00
|
|
|
url = (uri.replace_hostname(url, 'feed')) or url
|
2024-01-02 12:42:41 +01:00
|
|
|
match len(data):
|
|
|
|
case 1:
|
2024-01-27 18:15:28 +01:00
|
|
|
if url.startswith('http'):
|
2024-01-04 02:16:24 +01:00
|
|
|
response = await action.view_feed(url)
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing URL.'
|
2024-01-02 12:42:41 +01:00
|
|
|
case 2:
|
|
|
|
num = data[1]
|
2024-01-27 18:15:28 +01:00
|
|
|
if url.startswith('http'):
|
2024-01-04 02:16:24 +01:00
|
|
|
response = await action.view_entry(url, num)
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing URL.'
|
2024-01-02 12:42:41 +01:00
|
|
|
case _:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Enter command as follows:\n'
|
|
|
|
'`read <url>` or `read <url> <number>`\n'
|
|
|
|
'URL must not contain white space.')
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('recent'):
|
2024-01-02 12:42:41 +01:00
|
|
|
num = message_text[7:]
|
|
|
|
if num:
|
|
|
|
try:
|
|
|
|
num = int(num)
|
|
|
|
if num < 1 or num > 50:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Value must be ranged from 1 to 50.'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-02 12:42:41 +01:00
|
|
|
result = await sqlite.last_entries(db_file, num)
|
2024-01-06 23:03:08 +01:00
|
|
|
response = action.list_last_entries(result, num)
|
2024-01-02 12:42:41 +01:00
|
|
|
except:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Enter a numeric value only.'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing value.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('remove'):
|
2024-01-06 23:03:08 +01:00
|
|
|
ix_url = message_text[7:]
|
|
|
|
if ix_url:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-03 16:04:01 +01:00
|
|
|
try:
|
2024-01-06 23:03:08 +01:00
|
|
|
ix = int(ix_url)
|
2024-02-04 18:08:12 +01:00
|
|
|
url = sqlite.get_feed_url(db_file, ix)
|
|
|
|
if url:
|
|
|
|
url = url[0]
|
|
|
|
name = sqlite.get_feed_title(db_file, ix)
|
|
|
|
name = name[0]
|
|
|
|
await sqlite.remove_feed_by_index(db_file, ix)
|
|
|
|
response = ('> {}\n'
|
|
|
|
'News source "{}" has been '
|
|
|
|
'removed from subscription list.'
|
|
|
|
.format(url, name))
|
|
|
|
else:
|
|
|
|
response = ('No news source with index {}.'
|
|
|
|
.format(ix))
|
2024-01-03 16:04:01 +01:00
|
|
|
except:
|
2024-01-06 23:03:08 +01:00
|
|
|
url = ix_url
|
2024-02-04 18:08:12 +01:00
|
|
|
feed_id = await sqlite.get_feed_id(db_file, url)
|
|
|
|
if feed_id:
|
|
|
|
feed_id = feed_id[0]
|
|
|
|
await sqlite.remove_feed_by_url(db_file, url)
|
|
|
|
response = ('> {}\n'
|
|
|
|
'News source has been removed '
|
|
|
|
'from subscription list.'
|
|
|
|
.format(url))
|
|
|
|
else:
|
|
|
|
response = ('> {}\n'
|
|
|
|
'News source does not exist. '
|
|
|
|
'No action has been made.'
|
|
|
|
.format(url))
|
2024-01-06 23:03:08 +01:00
|
|
|
# await refresh_task(
|
|
|
|
# self,
|
|
|
|
# jid,
|
|
|
|
# send_status,
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'status',
|
2024-01-06 23:03:08 +01:00
|
|
|
# 20
|
|
|
|
# )
|
2024-02-04 18:08:12 +01:00
|
|
|
# await task.clean_tasks_xmpp(jid, ['status'])
|
2024-01-27 18:15:28 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'Missing feed URL or index number.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('reset'):
|
2024-02-04 18:08:12 +01:00
|
|
|
# TODO Reset also by ID
|
|
|
|
ix_url = message_text[6:]
|
2024-01-27 18:15:28 +01:00
|
|
|
await task.clean_tasks_xmpp(jid, ['status'])
|
|
|
|
status_type = 'dnd'
|
|
|
|
status_message = '📫️ Marking entries as read...'
|
2024-02-04 18:08:12 +01:00
|
|
|
status.send(self, jid, status_message, status_type)
|
|
|
|
db_file = get_pathname_to_database(jid_file)
|
|
|
|
if ix_url:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
try:
|
|
|
|
ix = int(ix_url)
|
|
|
|
url = sqlite.get_feed_url(db_file, ix)
|
|
|
|
if url:
|
|
|
|
url = url[0]
|
|
|
|
name = sqlite.get_feed_title(db_file, ix)
|
|
|
|
name = name[0]
|
|
|
|
await sqlite.mark_feed_as_read(db_file, ix)
|
|
|
|
response = ('> {}\n'
|
|
|
|
'All entries of source "{}" have been '
|
|
|
|
'marked as read.'
|
|
|
|
.format(url, name))
|
|
|
|
else:
|
|
|
|
response = ('No news source with index {}.'
|
|
|
|
.format(ix))
|
|
|
|
except:
|
|
|
|
url = ix_url
|
|
|
|
feed_id = await sqlite.get_feed_id(db_file, url)
|
|
|
|
if feed_id:
|
|
|
|
feed_id = feed_id[0]
|
|
|
|
name = sqlite.get_feed_title(db_file, feed_id)
|
|
|
|
name = name[0]
|
|
|
|
await sqlite.mark_feed_as_read(db_file, feed_id)
|
|
|
|
response = ('> {}\n'
|
|
|
|
'All entries of source "{}" have been '
|
|
|
|
'marked as read.'
|
|
|
|
.format(url, name))
|
|
|
|
else:
|
|
|
|
response = ('> {}\n'
|
|
|
|
'News source does not exist. '
|
|
|
|
'No action has been made.'
|
|
|
|
.format(url))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
|
|
|
await sqlite.mark_all_as_read(db_file)
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'All entries have been marked as read.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('search'):
|
2024-01-02 12:42:41 +01:00
|
|
|
query = message_text[7:]
|
|
|
|
if query:
|
|
|
|
if len(query) > 1:
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-02-04 18:08:12 +01:00
|
|
|
results = await sqlite.search_entries(db_file, query)
|
|
|
|
response = action.list_search_results(query, results)
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'Enter at least 2 characters to search'
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Missing search query.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'start':
|
|
|
|
# response = 'Updates are enabled.'
|
|
|
|
key = 'enabled'
|
2024-01-02 12:42:41 +01:00
|
|
|
val = 1
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-14 13:46:38 +01:00
|
|
|
if await sqlite.get_settings_value(db_file, key):
|
|
|
|
await sqlite.update_settings_value(db_file, [key, val])
|
|
|
|
else:
|
|
|
|
await sqlite.set_settings_value(db_file, [key, val])
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid)
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Updates are enabled.'
|
|
|
|
# print(current_time(), 'task_manager[jid]')
|
2024-01-02 12:42:41 +01:00
|
|
|
# print(task_manager[jid])
|
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'stats':
|
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-14 19:05:12 +01:00
|
|
|
response = await action.list_statistics(db_file)
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('disable '):
|
2024-01-03 16:04:01 +01:00
|
|
|
ix = message_text[8:]
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-03 16:04:01 +01:00
|
|
|
try:
|
|
|
|
await sqlite.set_enabled_status(db_file, ix, 0)
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Updates are now disabled for news source {}.'
|
|
|
|
.format(ix))
|
2024-01-03 16:04:01 +01:00
|
|
|
except:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'No news source with index {}.'.format(ix)
|
2024-01-03 16:04:01 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('enable'):
|
2024-01-02 12:42:41 +01:00
|
|
|
ix = message_text[7:]
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-03 16:04:01 +01:00
|
|
|
try:
|
|
|
|
await sqlite.set_enabled_status(db_file, ix, 1)
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Updates are now enabled for news source {}.'
|
|
|
|
.format(ix))
|
2024-01-03 16:04:01 +01:00
|
|
|
except:
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'No news source with index {}.'.format(ix)
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'stop':
|
2024-01-02 12:42:41 +01:00
|
|
|
# FIXME
|
|
|
|
# The following error occurs only upon first attempt to stop.
|
|
|
|
# /usr/lib/python3.11/asyncio/events.py:73: RuntimeWarning: coroutine 'Slixfeed.send_update' was never awaited
|
|
|
|
# self._args = None
|
|
|
|
# RuntimeWarning: Enable tracemalloc to get the object allocation traceback
|
2024-01-27 18:15:28 +01:00
|
|
|
# response = 'Updates are disabled.'
|
2024-01-02 12:42:41 +01:00
|
|
|
# try:
|
2024-01-27 18:15:28 +01:00
|
|
|
# # task_manager[jid]['check'].cancel()
|
|
|
|
# # task_manager[jid]['status'].cancel()
|
|
|
|
# task_manager[jid]['interval'].cancel()
|
|
|
|
# key = 'enabled'
|
2024-01-02 12:42:41 +01:00
|
|
|
# val = 0
|
|
|
|
# response = await initdb(
|
|
|
|
# jid,
|
2024-01-14 13:46:38 +01:00
|
|
|
# update_settings_value,
|
2024-01-02 12:42:41 +01:00
|
|
|
# [key, val]
|
|
|
|
# )
|
|
|
|
# except:
|
2024-01-27 18:15:28 +01:00
|
|
|
# response = 'Updates are already disabled.'
|
|
|
|
# # print('Updates are already disabled. Nothing to do.')
|
2024-01-02 12:42:41 +01:00
|
|
|
# # await send_status(jid)
|
2024-01-27 18:15:28 +01:00
|
|
|
key = 'enabled'
|
2024-01-02 12:42:41 +01:00
|
|
|
val = 0
|
2024-01-27 18:15:28 +01:00
|
|
|
db_file = get_pathname_to_database(jid_file)
|
2024-01-14 13:46:38 +01:00
|
|
|
if await sqlite.get_settings_value(db_file, key):
|
|
|
|
await sqlite.update_settings_value(db_file, [key, val])
|
|
|
|
else:
|
|
|
|
await sqlite.set_settings_value(db_file, [key, val])
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.clean_tasks_xmpp(jid, ['interval', 'status'])
|
2024-01-27 18:15:28 +01:00
|
|
|
response = 'Updates are disabled.'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
status_type = 'xa'
|
2024-02-04 18:08:12 +01:00
|
|
|
status_message = '💡️ Send "Start" to receive Jabber updates'
|
|
|
|
status.send(self, jid, status_message, status_type)
|
2024-01-27 18:15:28 +01:00
|
|
|
case 'support':
|
2024-01-02 12:42:41 +01:00
|
|
|
# TODO Send an invitation.
|
2024-02-04 18:08:12 +01:00
|
|
|
response = 'Join xmpp:slixfeed@chat.woodpeckersnest.space?join'
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
case _ if message_lowercase.startswith('xmpp:'):
|
2024-01-02 12:42:41 +01:00
|
|
|
muc_jid = uri.check_xmpp_uri(message_text)
|
|
|
|
if muc_jid:
|
|
|
|
# TODO probe JID and confirm it's a groupchat
|
|
|
|
await groupchat.join(self, jid, muc_jid)
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Joined groupchat {}'
|
|
|
|
.format(message_text))
|
2024-01-02 12:42:41 +01:00
|
|
|
else:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('> {}\n'
|
|
|
|
'XMPP URI is not valid.'
|
|
|
|
.format(message_text))
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
|
|
|
case _:
|
2024-02-04 18:08:12 +01:00
|
|
|
response = ('Unknown command. '
|
|
|
|
'Press "help" for list of commands')
|
2024-01-02 12:42:41 +01:00
|
|
|
send_reply_message(self, message, response)
|
|
|
|
# TODO Use message correction here
|
|
|
|
# NOTE This might not be a good idea if
|
|
|
|
# commands are sent one close to the next
|
|
|
|
# if response: message.reply(response).send()
|
|
|
|
|
2024-01-27 18:15:28 +01:00
|
|
|
command_time_finish = time.time()
|
|
|
|
command_time_total = command_time_finish - command_time_start
|
2024-02-04 18:08:12 +01:00
|
|
|
command_time_total = round(command_time_total, 3)
|
|
|
|
response = 'Finished. Total time: {}s'.format(command_time_total)
|
|
|
|
send_reply_message(self, message, response)
|
2024-01-27 18:15:28 +01:00
|
|
|
|
|
|
|
if not response: response = 'EMPTY MESSAGE - ACTION ONLY'
|
2024-01-06 23:03:08 +01:00
|
|
|
data_dir = get_default_data_directory()
|
2024-01-03 11:37:33 +01:00
|
|
|
if not os.path.isdir(data_dir):
|
|
|
|
os.mkdir(data_dir)
|
2024-01-03 13:30:52 +01:00
|
|
|
if not os.path.isdir(data_dir + '/logs/'):
|
|
|
|
os.mkdir(data_dir + '/logs/')
|
2024-01-06 23:03:08 +01:00
|
|
|
action.log_to_markdown(
|
2024-01-27 18:15:28 +01:00
|
|
|
current_time(), os.path.join(data_dir, 'logs', jid_file),
|
2024-01-02 12:42:41 +01:00
|
|
|
jid, message_text)
|
2024-01-06 23:03:08 +01:00
|
|
|
action.log_to_markdown(
|
2024-01-27 18:15:28 +01:00
|
|
|
current_time(), os.path.join(data_dir, 'logs', jid_file),
|
2024-01-02 12:42:41 +01:00
|
|
|
self.boundjid.bare, response)
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
print(
|
|
|
|
'Message : {}\n'
|
|
|
|
'JID : {}\n'
|
|
|
|
'File : {}\n'
|
|
|
|
'{}\n'
|
|
|
|
.format(message_text, jid, jid_file, response)
|
|
|
|
)
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
def send_reply_message(self, message, response):
|
|
|
|
message.reply(response).send()
|
|
|
|
|
|
|
|
|
2024-01-04 14:58:06 +01:00
|
|
|
# TODO Solve this function
|
2024-01-03 11:37:33 +01:00
|
|
|
def send_oob_reply_message(message, url, response):
|
|
|
|
reply = message.reply(response)
|
|
|
|
reply['oob']['url'] = url
|
|
|
|
reply.send()
|
|
|
|
|
|
|
|
|
2024-01-03 13:17:39 +01:00
|
|
|
async def send_oob_message(self, jid, url):
|
2024-01-27 18:15:28 +01:00
|
|
|
chat_type = await get_chat_type(self, jid)
|
2024-01-03 11:37:33 +01:00
|
|
|
html = (
|
|
|
|
f'<body xmlns="http://www.w3.org/1999/xhtml">'
|
|
|
|
f'<a href="{url}">{url}</a></body>')
|
2024-01-04 14:58:06 +01:00
|
|
|
message = self.make_message(
|
|
|
|
mto=jid,
|
2024-01-24 19:11:39 +01:00
|
|
|
mfrom=self.boundjid.bare,
|
2024-01-04 14:58:06 +01:00
|
|
|
mbody=url,
|
|
|
|
mhtml=html,
|
|
|
|
mtype=chat_type
|
|
|
|
)
|
2024-01-03 11:37:33 +01:00
|
|
|
message['oob']['url'] = url
|
|
|
|
message.send()
|
|
|
|
|
|
|
|
|
2024-01-27 18:15:28 +01:00
|
|
|
# def greet(self, jid, chat_type='chat'):
|
2024-01-02 12:42:41 +01:00
|
|
|
# messages = [
|
2024-01-27 18:15:28 +01:00
|
|
|
# 'Greetings!',
|
|
|
|
# 'I'm {}, the news anchor.'.format(self.nick),
|
|
|
|
# 'My job is to bring you the latest news '
|
|
|
|
# 'from sources you provide me with.',
|
|
|
|
# 'You may always reach me via '
|
|
|
|
# 'xmpp:{}?message'.format(self.boundjid.bare)
|
2024-01-02 12:42:41 +01:00
|
|
|
# ]
|
|
|
|
# for message in messages:
|
|
|
|
# self.send_message(
|
|
|
|
# mto=jid,
|
2024-01-24 19:11:39 +01:00
|
|
|
# mfrom=self.boundjid.bare,
|
2024-01-02 12:42:41 +01:00
|
|
|
# mbody=message,
|
|
|
|
# mtype=chat_type
|
|
|
|
# )
|
|
|
|
|
|
|
|
|
2024-01-27 18:15:28 +01:00
|
|
|
def greet(self, jid, chat_type='chat'):
|
2024-01-02 12:42:41 +01:00
|
|
|
message = (
|
2024-01-27 18:15:28 +01:00
|
|
|
'Greetings!\n'
|
|
|
|
'I am {}, the news anchor.\n'
|
|
|
|
'My job is to bring you the latest '
|
|
|
|
'news from sources you provide me with.\n'
|
|
|
|
'You may always reach me via xmpp:{}?message').format(
|
2024-01-24 19:11:39 +01:00
|
|
|
self.alias,
|
2024-01-02 12:42:41 +01:00
|
|
|
self.boundjid.bare
|
|
|
|
)
|
|
|
|
self.send_message(
|
|
|
|
mto=jid,
|
2024-01-24 19:11:39 +01:00
|
|
|
mfrom=self.boundjid.bare,
|
2024-01-02 12:42:41 +01:00
|
|
|
mbody=message,
|
|
|
|
mtype=chat_type
|
|
|
|
)
|
|
|
|
|