Fix check for filters and settings keys
This commit is contained in:
parent
288e5157fa
commit
10762a69e4
9 changed files with 218 additions and 163 deletions
|
@ -242,7 +242,7 @@ async def xmpp_send_update(self, jid, num=None):
|
||||||
|
|
||||||
# interval = await initdb(
|
# interval = await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# sqlite.get_settings_value,
|
# sqlite.is_setting_key,
|
||||||
# "interval"
|
# "interval"
|
||||||
# )
|
# )
|
||||||
# self.task_manager[jid]["interval"] = loop.call_at(
|
# self.task_manager[jid]["interval"] = loop.call_at(
|
||||||
|
@ -296,10 +296,10 @@ async def xmpp_change_interval(self, key, val, jid, jid_file, message=None):
|
||||||
# 'Updates will be sent every {} minutes.'
|
# 'Updates will be sent every {} minutes.'
|
||||||
# ).format(response)
|
# ).format(response)
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
# NOTE Perhaps this should be replaced
|
# NOTE Perhaps this should be replaced
|
||||||
# by functions clean and start
|
# by functions clean and start
|
||||||
await task.refresh_task(self, jid, task.task_send, key, val)
|
await task.refresh_task(self, jid, task.task_send, key, val)
|
||||||
|
@ -311,20 +311,14 @@ async def xmpp_change_interval(self, key, val, jid, jid_file, message=None):
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
|
|
||||||
|
|
||||||
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):
|
async def xmpp_start_updates(self, message, jid, jid_file):
|
||||||
key = 'enabled'
|
key = 'enabled'
|
||||||
val = 1
|
val = 1
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
status_type = 'available'
|
status_type = 'available'
|
||||||
status_message = '📫️ Welcome back!'
|
status_message = '📫️ Welcome back!'
|
||||||
XmppPresence.send(self, jid, status_message, status_type=status_type)
|
XmppPresence.send(self, jid, status_message, status_type=status_type)
|
||||||
|
@ -338,10 +332,10 @@ async def xmpp_stop_updates(self, message, jid, jid_file):
|
||||||
key = 'enabled'
|
key = 'enabled'
|
||||||
val = 0
|
val = 0
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
task.clean_tasks_xmpp(self, jid, ['interval', 'status'])
|
task.clean_tasks_xmpp(self, jid, ['interval', 'status'])
|
||||||
message_body = 'Updates are disabled.'
|
message_body = 'Updates are disabled.'
|
||||||
XmppMessage.send_reply(self, message, message_body)
|
XmppMessage.send_reply(self, message, message_body)
|
||||||
|
@ -468,10 +462,10 @@ def list_unread_entries(result, feed_title):
|
||||||
# TODO Do this when entry is added to list and mark it as read
|
# TODO Do this when entry is added to list and mark it as read
|
||||||
# DONE!
|
# DONE!
|
||||||
# results = []
|
# results = []
|
||||||
# if get_settings_value(db_file, "filter-deny"):
|
# if sqlite.is_setting_key(db_file, "deny"):
|
||||||
# while len(results) < num:
|
# while len(results) < num:
|
||||||
# result = cur.execute(sql).fetchone()
|
# result = cur.execute(sql).fetchone()
|
||||||
# blacklist = await get_settings_value(db_file, "filter-deny").split(",")
|
# blacklist = sqlite.get_setting_value(db_file, "deny").split(",")
|
||||||
# for i in blacklist:
|
# for i in blacklist:
|
||||||
# if i in result[1]:
|
# if i in result[1]:
|
||||||
# continue
|
# continue
|
||||||
|
@ -496,7 +490,7 @@ def list_unread_entries(result, feed_title):
|
||||||
# breakpoint()
|
# breakpoint()
|
||||||
# # TODO Limit text length
|
# # TODO Limit text length
|
||||||
# summary = summary.replace("\n\n\n", "\n\n")
|
# summary = summary.replace("\n\n\n", "\n\n")
|
||||||
# length = await get_settings_value(db_file, "length")
|
# length = sqlite.get_setting_value(db_file, "length")
|
||||||
# summary = summary[:length] + " […]"
|
# summary = summary[:length] + " […]"
|
||||||
# summary = summary.strip().split('\n')
|
# summary = summary.strip().split('\n')
|
||||||
# summary = ["> " + line for line in summary]
|
# summary = ["> " + line for line in summary]
|
||||||
|
|
|
@ -63,7 +63,7 @@ Send an article as file. Specify <id> or <url> and <type>.
|
||||||
Supported types are ePUB, HTML, MD and PDF (default).
|
Supported types are ePUB, HTML, MD and PDF (default).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[filter]
|
[filters]
|
||||||
allow = """
|
allow = """
|
||||||
allow [+|-] <keyword>
|
allow [+|-] <keyword>
|
||||||
Keywords to allow
|
Keywords to allow
|
||||||
|
@ -77,11 +77,11 @@ comma-separated keywords
|
||||||
'+' appends to, '-' removes from.
|
'+' appends to, '-' removes from.
|
||||||
"""
|
"""
|
||||||
clear_allow = """
|
clear_allow = """
|
||||||
filter clear allow
|
clear allow
|
||||||
Reset allow list.
|
Reset allow list.
|
||||||
"""
|
"""
|
||||||
clear_deny = """
|
clear_deny = """
|
||||||
filter clear deny
|
clear deny
|
||||||
Reset deny list.
|
Reset deny list.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,8 @@ import tomli_w
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
||||||
def get_setting_value(db_file, key):
|
def get_setting_value(db_file, key):
|
||||||
value = (
|
value = (sqlite.get_setting_value(db_file, key)[0] or
|
||||||
sqlite.get_settings_value(db_file, key) or
|
get_value("settings", "Settings", key))
|
||||||
get_value("settings", "Settings", key)
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
value = int(value)
|
value = int(value)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
@ -470,7 +468,7 @@ async def is_include_keyword(db_file, key, string):
|
||||||
"""
|
"""
|
||||||
# async def reject(db_file, string):
|
# async def reject(db_file, string):
|
||||||
# async def is_blacklisted(db_file, string):
|
# async def is_blacklisted(db_file, string):
|
||||||
keywords = (await sqlite.get_filters_value(db_file, key)) or ''
|
keywords = sqlite.get_filters_value(db_file, key) or ''
|
||||||
keywords = keywords.split(",")
|
keywords = keywords.split(",")
|
||||||
keywords = keywords + (open_config_file("lists.toml")[key])
|
keywords = keywords + (open_config_file("lists.toml")[key])
|
||||||
for keyword in keywords:
|
for keyword in keywords:
|
||||||
|
@ -486,9 +484,9 @@ async def is_include_keyword(db_file, key, string):
|
||||||
This code was tested at module datahandler
|
This code was tested at module datahandler
|
||||||
|
|
||||||
reject = 0
|
reject = 0
|
||||||
blacklist = await get_settings_value(
|
blacklist = sqlite.get_setting_value(
|
||||||
db_file,
|
db_file,
|
||||||
"filter-deny"
|
"deny"
|
||||||
)
|
)
|
||||||
# print(">>> blacklist:")
|
# print(">>> blacklist:")
|
||||||
# print(blacklist)
|
# print(blacklist)
|
||||||
|
|
|
@ -1752,9 +1752,9 @@ async def check_entry_exist(
|
||||||
return exist
|
return exist
|
||||||
|
|
||||||
|
|
||||||
async def set_settings_value(db_file, key_value):
|
async def set_setting_value(db_file, key_value):
|
||||||
"""
|
"""
|
||||||
Set settings value.
|
Set setting value.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -1795,9 +1795,9 @@ async def set_settings_value(db_file, key_value):
|
||||||
cur.execute(sql, par)
|
cur.execute(sql, par)
|
||||||
|
|
||||||
|
|
||||||
async def update_settings_value(db_file, key_value):
|
async def update_setting_value(db_file, key_value):
|
||||||
"""
|
"""
|
||||||
Update settings value.
|
Update setting value.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -1841,6 +1841,36 @@ async def update_settings_value(db_file, key_value):
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
|
||||||
|
async def delete_filter(db_file, key):
|
||||||
|
async with DBLOCK:
|
||||||
|
with create_connection(db_file) as conn:
|
||||||
|
cur = conn.cursor()
|
||||||
|
sql = (
|
||||||
|
"""
|
||||||
|
DELETE
|
||||||
|
FROM filters
|
||||||
|
WHERE key = ?
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
par = (key,)
|
||||||
|
cur.execute(sql, par)
|
||||||
|
|
||||||
|
|
||||||
|
async def delete_setting(db_file, key):
|
||||||
|
async with DBLOCK:
|
||||||
|
with create_connection(db_file) as conn:
|
||||||
|
cur = conn.cursor()
|
||||||
|
sql = (
|
||||||
|
"""
|
||||||
|
DELETE
|
||||||
|
FROM settings
|
||||||
|
WHERE key = ?
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
par = (key,)
|
||||||
|
cur.execute(sql, par)
|
||||||
|
|
||||||
|
|
||||||
async def delete_settings(db_file):
|
async def delete_settings(db_file):
|
||||||
async with DBLOCK:
|
async with DBLOCK:
|
||||||
with create_connection(db_file) as conn:
|
with create_connection(db_file) as conn:
|
||||||
|
@ -1853,7 +1883,8 @@ async def delete_settings(db_file):
|
||||||
)
|
)
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
|
|
||||||
def get_settings_value(db_file, key):
|
|
||||||
|
def get_setting_value(db_file, key):
|
||||||
"""
|
"""
|
||||||
Get settings value.
|
Get settings value.
|
||||||
|
|
||||||
|
@ -1872,26 +1903,49 @@ def get_settings_value(db_file, key):
|
||||||
"""
|
"""
|
||||||
with create_connection(db_file) as conn:
|
with create_connection(db_file) as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
try:
|
sql = (
|
||||||
sql = (
|
"""
|
||||||
"""
|
SELECT value
|
||||||
SELECT value
|
FROM settings
|
||||||
FROM settings
|
WHERE key = ?
|
||||||
WHERE key = ?
|
"""
|
||||||
"""
|
)
|
||||||
)
|
par = (key,)
|
||||||
par = (key,)
|
value = cur.execute(sql, par).fetchone()
|
||||||
value = cur.execute(sql, par).fetchone()[0]
|
return value
|
||||||
value = str(value)
|
|
||||||
except:
|
|
||||||
value = None
|
|
||||||
logging.debug(
|
|
||||||
"No specific value set for key {}.".format(key)
|
|
||||||
)
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
async def set_filters_value(db_file, key_value):
|
def is_setting_key(db_file, key):
|
||||||
|
"""
|
||||||
|
Check whether setting key exist.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
db_file : str
|
||||||
|
Path to database file.
|
||||||
|
key : str
|
||||||
|
Key: allow, deny.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
key : str
|
||||||
|
Key.
|
||||||
|
"""
|
||||||
|
with create_connection(db_file) as conn:
|
||||||
|
cur = conn.cursor()
|
||||||
|
sql = (
|
||||||
|
"""
|
||||||
|
SELECT key
|
||||||
|
FROM settings
|
||||||
|
WHERE key = ?
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
par = (key,)
|
||||||
|
key = cur.execute(sql, par).fetchone()
|
||||||
|
return key
|
||||||
|
|
||||||
|
|
||||||
|
async def set_filter_value(db_file, key_value):
|
||||||
"""
|
"""
|
||||||
Set settings value.
|
Set settings value.
|
||||||
|
|
||||||
|
@ -1901,7 +1955,7 @@ async def set_filters_value(db_file, key_value):
|
||||||
Path to database file.
|
Path to database file.
|
||||||
key_value : list
|
key_value : list
|
||||||
key : str
|
key : str
|
||||||
filter-allow, filter-deny, filter-replace.
|
allow, deny, replace.
|
||||||
value : int
|
value : int
|
||||||
Numeric value.
|
Numeric value.
|
||||||
"""
|
"""
|
||||||
|
@ -1926,7 +1980,7 @@ async def set_filters_value(db_file, key_value):
|
||||||
cur.execute(sql, par)
|
cur.execute(sql, par)
|
||||||
|
|
||||||
|
|
||||||
async def update_filters_value(db_file, key_value):
|
async def update_filter_value(db_file, key_value):
|
||||||
"""
|
"""
|
||||||
Update settings value.
|
Update settings value.
|
||||||
|
|
||||||
|
@ -1936,7 +1990,7 @@ async def update_filters_value(db_file, key_value):
|
||||||
Path to database file.
|
Path to database file.
|
||||||
key_value : list
|
key_value : list
|
||||||
key : str
|
key : str
|
||||||
filter-allow, filter-deny, filter-replace.
|
allow, deny, replace.
|
||||||
value : int
|
value : int
|
||||||
Numeric value.
|
Numeric value.
|
||||||
"""
|
"""
|
||||||
|
@ -1968,9 +2022,9 @@ async def update_filters_value(db_file, key_value):
|
||||||
cur.execute(sql, par)
|
cur.execute(sql, par)
|
||||||
|
|
||||||
|
|
||||||
async def is_filter_key(db_file, key):
|
def is_filter_key(db_file, key):
|
||||||
"""
|
"""
|
||||||
Get filters key.
|
Check whether filter key exist.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -1986,26 +2040,21 @@ async def is_filter_key(db_file, key):
|
||||||
"""
|
"""
|
||||||
with create_connection(db_file) as conn:
|
with create_connection(db_file) as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
try:
|
sql = (
|
||||||
sql = (
|
"""
|
||||||
"""
|
SELECT key
|
||||||
SELECT key
|
FROM filters
|
||||||
FROM filters
|
WHERE key = ?
|
||||||
WHERE key = ?
|
"""
|
||||||
"""
|
)
|
||||||
)
|
par = (key,)
|
||||||
par = (key,)
|
key = cur.execute(sql, par).fetchone()
|
||||||
key = cur.execute(sql, par)
|
return key
|
||||||
key = True
|
|
||||||
except:
|
|
||||||
key = False
|
|
||||||
logging.debug("No key {}.".format(key))
|
|
||||||
return key
|
|
||||||
|
|
||||||
|
|
||||||
async def get_filters_value(db_file, key):
|
def get_filter_value(db_file, key):
|
||||||
"""
|
"""
|
||||||
Get filters value.
|
Get filter value.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -2021,20 +2070,16 @@ async def get_filters_value(db_file, key):
|
||||||
"""
|
"""
|
||||||
with create_connection(db_file) as conn:
|
with create_connection(db_file) as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
try:
|
sql = (
|
||||||
sql = (
|
"""
|
||||||
"""
|
SELECT value
|
||||||
SELECT value
|
FROM filters
|
||||||
FROM filters
|
WHERE key = ?
|
||||||
WHERE key = ?
|
"""
|
||||||
"""
|
)
|
||||||
)
|
par = (key,)
|
||||||
par = (key,)
|
value = cur.execute(sql, par).fetchone()[0]
|
||||||
value = cur.execute(sql, par).fetchone()[0]
|
value = str(value)
|
||||||
value = str(value)
|
|
||||||
except:
|
|
||||||
value = None
|
|
||||||
logging.debug("No specific value set for key {}.".format(key))
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__version__ = '0.1.7'
|
__version__ = '0.1.8'
|
||||||
__version_info__ = (0, 1, 7)
|
__version_info__ = (0, 1, 8)
|
||||||
|
|
|
@ -50,6 +50,7 @@ import slixfeed.action as action
|
||||||
import slixfeed.config as config
|
import slixfeed.config as config
|
||||||
from slixfeed.dt import timestamp
|
from slixfeed.dt import timestamp
|
||||||
import slixfeed.sqlite as sqlite
|
import slixfeed.sqlite as sqlite
|
||||||
|
from slixfeed.version import __version__
|
||||||
from slixfeed.xmpp.bookmark import XmppBookmark
|
from slixfeed.xmpp.bookmark import XmppBookmark
|
||||||
from slixfeed.xmpp.connect import XmppConnect
|
from slixfeed.xmpp.connect import XmppConnect
|
||||||
from slixfeed.xmpp.muc import XmppGroupchat
|
from slixfeed.xmpp.muc import XmppGroupchat
|
||||||
|
@ -213,10 +214,10 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
task.task_ping(self)
|
task.task_ping(self)
|
||||||
bookmarks = await self.plugin['xep_0048'].get_bookmarks()
|
bookmarks = await self.plugin['xep_0048'].get_bookmarks()
|
||||||
XmppGroupchat.autojoin(self, bookmarks)
|
XmppGroupchat.autojoin(self, bookmarks)
|
||||||
|
if config.get_value('accounts', 'XMPP', 'operator'):
|
||||||
# Service.commands(self)
|
jid_op = config.get_value('accounts', 'XMPP', 'operator')
|
||||||
# Service.reactions(self)
|
message_body = 'Slixfeed version {}'.format(__version__)
|
||||||
|
XmppMessage.send(self, jid_op, message_body, 'chat')
|
||||||
|
|
||||||
|
|
||||||
def on_session_resumed(self, event):
|
def on_session_resumed(self, event):
|
||||||
|
@ -549,13 +550,13 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
form = self['xep_0004'].make_form('form', 'Filters')
|
form = self['xep_0004'].make_form('form', 'Filters')
|
||||||
form['instructions'] = '🛡️ Manage filters' # 🪄️
|
form['instructions'] = '🛡️ Manage filters' # 🪄️
|
||||||
value = await sqlite.get_filters_value(db_file, 'allow')
|
value = sqlite.get_filter_value(db_file, 'allow')
|
||||||
form.add_field(var='allow',
|
form.add_field(var='allow',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
label='Allow list',
|
label='Allow list',
|
||||||
value=value,
|
value=value,
|
||||||
desc=('Keywords to allow (comma-separated keywords).'))
|
desc=('Keywords to allow (comma-separated keywords).'))
|
||||||
value = await sqlite.get_filters_value(db_file, 'deny')
|
value = sqlite.get_filter_value(db_file, 'deny')
|
||||||
form.add_field(var='deny',
|
form.add_field(var='deny',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
label='Deny list',
|
label='Deny list',
|
||||||
|
@ -596,13 +597,13 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
val = values[value]
|
val = values[value]
|
||||||
# NOTE We might want to add new keywords from
|
# NOTE We might want to add new keywords from
|
||||||
# an empty form instead of editing a form.
|
# an empty form instead of editing a form.
|
||||||
# keywords = await sqlite.get_filters_value(db_file, key)
|
# keywords = sqlite.get_filter_value(db_file, key)
|
||||||
keywords = ''
|
keywords = ''
|
||||||
val = await config.add_to_list(val, keywords)
|
val = await config.add_to_list(val, keywords)
|
||||||
if await sqlite.is_filter_key(db_file, key):
|
if sqlite.is_filter_key(db_file, key):
|
||||||
await sqlite.update_filters_value(db_file, [key, val])
|
await sqlite.update_filter_value(db_file, [key, val])
|
||||||
elif val:
|
elif val:
|
||||||
await sqlite.set_filters_value(db_file, [key, val])
|
await sqlite.set_filter_value(db_file, [key, val])
|
||||||
form.add_field(var=key.capitalize() + ' list',
|
form.add_field(var=key.capitalize() + ' list',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=val)
|
value=val)
|
||||||
|
@ -664,7 +665,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# 'in the subscription list at index '
|
# 'in the subscription list at index '
|
||||||
# '{}.\n{}'.format(result['name'], result['index'],
|
# '{}.\n{}'.format(result['name'], result['index'],
|
||||||
# result['url']))
|
# result['url']))
|
||||||
# session['notes'] = [['warning', response]] # Not supported by Gajim
|
# session['notes'] = [['warn', response]] # Not supported by Gajim
|
||||||
# session['notes'] = [['info', response]]
|
# session['notes'] = [['info', response]]
|
||||||
form = self['xep_0004'].make_form('result', 'Subscriptions')
|
form = self['xep_0004'].make_form('result', 'Subscriptions')
|
||||||
form['instructions'] = ('⚠️ Feed "{}" already exist as index {}'
|
form['instructions'] = ('⚠️ Feed "{}" already exist as index {}'
|
||||||
|
@ -964,7 +965,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# text = '💡️ About Slixfeed, slixmpp and XMPP\n\n'
|
# text = '💡️ About Slixfeed, slixmpp and XMPP\n\n'
|
||||||
# text += '\n\n'
|
# text += '\n\n'
|
||||||
# form = self['xep_0004'].make_form('result', 'About')
|
# form = self['xep_0004'].make_form('result', 'About')
|
||||||
text = 'Slixfeed\n\n'
|
text = 'Slixfeed {}\n\n'.format(__version__)
|
||||||
text += ''.join(action.manual('information.toml', 'about'))
|
text += ''.join(action.manual('information.toml', 'about'))
|
||||||
text += '\n\n'
|
text += '\n\n'
|
||||||
text += 'Slixmpp\n\n'
|
text += 'Slixmpp\n\n'
|
||||||
|
@ -1109,7 +1110,11 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
form = self['xep_0004'].make_form('result', 'Credits')
|
form = self['xep_0004'].make_form('result', 'Credits')
|
||||||
form['instructions'] = "We are XMPP"
|
form['instructions'] = "We are XMPP"
|
||||||
form.add_field(ftype="text-multi", value=action.manual('information.toml', 'thanks'))
|
form.add_field(ftype="text-multi", value=action.manual('information.toml', 'thanks'))
|
||||||
form['instructions'] = 'YOU!\n🫵️\n- Join us -'
|
|
||||||
|
# Gajim displays all form['instructions'] on top
|
||||||
|
# Psi ignore the latter form['instructions']
|
||||||
|
# form['instructions'] = 'YOU!\n🫵️\n- Join us -'
|
||||||
|
|
||||||
session['payload'] = form
|
session['payload'] = form
|
||||||
return session
|
return session
|
||||||
|
|
||||||
|
@ -1174,7 +1179,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
' Jabber ID: {}\n'
|
' Jabber ID: {}\n'
|
||||||
' Timestamp: {}\n'
|
' Timestamp: {}\n'
|
||||||
.format(jid, timestamp()))
|
.format(jid, timestamp()))
|
||||||
session['notes'] = [['error', 'You are not allowed to access this resource.']]
|
session['notes'] = [['warn', 'You are not allowed to access this resource.']]
|
||||||
return session
|
return session
|
||||||
|
|
||||||
|
|
||||||
|
@ -1410,12 +1415,13 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
if val < 1: val = 1
|
if val < 1: val = 1
|
||||||
val = val * 60
|
val = val * 60
|
||||||
|
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
|
|
||||||
val = sqlite.get_settings_value(db_file, key)
|
val = sqlite.get_setting_value(db_file, key)
|
||||||
|
val = val[0]
|
||||||
if key in ('enabled', 'media', 'old'):
|
if key in ('enabled', 'media', 'old'):
|
||||||
if val == '1':
|
if val == '1':
|
||||||
val = 'Yes'
|
val = 'Yes'
|
||||||
|
|
|
@ -625,10 +625,10 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
for value in values:
|
for value in values:
|
||||||
key = value
|
key = value
|
||||||
val = values[value]
|
val = values[value]
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
match value:
|
match value:
|
||||||
case 'enabled':
|
case 'enabled':
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -62,14 +62,14 @@ class XmppGroupchat:
|
||||||
def join(self, inviter, jid):
|
def join(self, inviter, jid):
|
||||||
# token = await initdb(
|
# token = await initdb(
|
||||||
# muc_jid,
|
# muc_jid,
|
||||||
# get_settings_value,
|
# sqlite.get_setting_value,
|
||||||
# "token"
|
# "token"
|
||||||
# )
|
# )
|
||||||
# if token != "accepted":
|
# if token != "accepted":
|
||||||
# token = randrange(10000, 99999)
|
# token = randrange(10000, 99999)
|
||||||
# await initdb(
|
# await initdb(
|
||||||
# muc_jid,
|
# muc_jid,
|
||||||
# update_settings_value,
|
# sqlite.update_setting_value,
|
||||||
# ["token", token]
|
# ["token", token]
|
||||||
# )
|
# )
|
||||||
# self.send_message(
|
# self.send_message(
|
||||||
|
|
|
@ -116,13 +116,13 @@ async def message(self, message):
|
||||||
return
|
return
|
||||||
# token = await initdb(
|
# token = await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# get_settings_value,
|
# sqlite.get_setting_value,
|
||||||
# 'token'
|
# 'token'
|
||||||
# )
|
# )
|
||||||
# if token == 'accepted':
|
# if token == 'accepted':
|
||||||
# operator = await initdb(
|
# operator = await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# get_settings_value,
|
# sqlite.get_setting_value,
|
||||||
# 'masters'
|
# 'masters'
|
||||||
# )
|
# )
|
||||||
# if operator:
|
# if operator:
|
||||||
|
@ -144,7 +144,7 @@ async def message(self, message):
|
||||||
# if not approved:
|
# if not approved:
|
||||||
# operator = await initdb(
|
# operator = await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# get_settings_value,
|
# sqlite.get_setting_value,
|
||||||
# 'masters'
|
# 'masters'
|
||||||
# )
|
# )
|
||||||
# if operator:
|
# if operator:
|
||||||
|
@ -266,18 +266,18 @@ async def message(self, message):
|
||||||
# acode = message[9:]
|
# acode = message[9:]
|
||||||
# token = await initdb(
|
# token = await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# get_settings_value,
|
# sqlite.get_setting_value,
|
||||||
# 'token'
|
# 'token'
|
||||||
# )
|
# )
|
||||||
# if int(acode) == token:
|
# if int(acode) == token:
|
||||||
# await initdb(
|
# await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# update_settings_value,
|
# sqlite.update_setting_value,
|
||||||
# ['masters', nick]
|
# ['masters', nick]
|
||||||
# )
|
# )
|
||||||
# await initdb(
|
# await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# update_settings_value,
|
# sqlite.update_setting_value,
|
||||||
# ['token', 'accepted']
|
# ['token', 'accepted']
|
||||||
# )
|
# )
|
||||||
# response = '{}, your are in command.'.format(nick)
|
# response = '{}, your are in command.'.format(nick)
|
||||||
|
@ -327,13 +327,13 @@ async def message(self, message):
|
||||||
val = message_text[7:]
|
val = message_text[7:]
|
||||||
if val:
|
if val:
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
keywords = await sqlite.get_filters_value(db_file, key)
|
keywords = sqlite.get_filter_value(db_file, key)
|
||||||
val = await config.add_to_list(val, keywords)
|
val = await config.add_to_list(val, keywords)
|
||||||
if await sqlite.get_filters_value(db_file, key):
|
if sqlite.is_filter_key(db_file, key):
|
||||||
await sqlite.update_filters_value(db_file,
|
await sqlite.update_filter_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_filters_value(db_file, [key, val])
|
await sqlite.set_filter_value(db_file, [key, val])
|
||||||
response = ('Approved keywords\n'
|
response = ('Approved keywords\n'
|
||||||
'```\n{}\n```'
|
'```\n{}\n```'
|
||||||
.format(val))
|
.format(val))
|
||||||
|
@ -345,13 +345,13 @@ async def message(self, message):
|
||||||
val = message_text[7:]
|
val = message_text[7:]
|
||||||
if val:
|
if val:
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
keywords = await sqlite.get_filters_value(db_file, key)
|
keywords = sqlite.get_filter_value(db_file, key)
|
||||||
val = await config.remove_from_list(val, keywords)
|
val = await config.remove_from_list(val, keywords)
|
||||||
if await sqlite.get_filters_value(db_file, key):
|
if sqlite.is_filter_key(db_file, key):
|
||||||
await sqlite.update_filters_value(db_file,
|
await sqlite.update_filter_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_filters_value(db_file, [key, val])
|
await sqlite.set_filter_value(db_file, [key, val])
|
||||||
response = ('Approved keywords\n'
|
response = ('Approved keywords\n'
|
||||||
'```\n{}\n```'
|
'```\n{}\n```'
|
||||||
.format(val))
|
.format(val))
|
||||||
|
@ -367,13 +367,13 @@ async def message(self, message):
|
||||||
response = 'Value may not be greater than 500.'
|
response = 'Value may not be greater than 500.'
|
||||||
else:
|
else:
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
print('update archive')
|
print('update archive')
|
||||||
await sqlite.update_settings_value(db_file,
|
await sqlite.update_setting_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
else:
|
else:
|
||||||
print('set archive')
|
print('set archive')
|
||||||
await sqlite.set_settings_value(db_file,
|
await sqlite.set_setting_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
response = ('Maximum archived items has '
|
response = ('Maximum archived items has '
|
||||||
'been set to {}.'
|
'been set to {}.'
|
||||||
|
@ -403,11 +403,23 @@ async def message(self, message):
|
||||||
response = ('This action is restricted. '
|
response = ('This action is restricted. '
|
||||||
'Type: removing bookmarks.')
|
'Type: removing bookmarks.')
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case 'default': # TODO Set default per key
|
case _ if message_lowercase.startswith('default '):
|
||||||
response = action.reset_settings(jid_file)
|
key = message_text[8:]
|
||||||
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
|
await sqlite.delete_setting(db_file, key)
|
||||||
|
response = ('Setting {} has been restored to default value.'
|
||||||
|
.format(key))
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case 'defaults':
|
case 'defaults':
|
||||||
response = action.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.'
|
||||||
|
XmppMessage.send_reply(self, message, response)
|
||||||
|
case _ if message_lowercase.startswith('clear '):
|
||||||
|
key = message_text[6:]
|
||||||
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
|
await sqlite.delete_filter(db_file, key)
|
||||||
|
response = 'Filter {} has been purged.'.format(key)
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case 'bookmarks':
|
case 'bookmarks':
|
||||||
if jid == config.get_value('accounts', 'XMPP', 'operator'):
|
if jid == config.get_value('accounts', 'XMPP', 'operator'):
|
||||||
|
@ -417,17 +429,17 @@ async def message(self, message):
|
||||||
'Type: viewing bookmarks.')
|
'Type: viewing bookmarks.')
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case _ if message_lowercase.startswith('deny +'):
|
case _ if message_lowercase.startswith('deny +'):
|
||||||
key = 'filter-' + message_text[:4]
|
key = message_text[:4]
|
||||||
val = message_text[6:]
|
val = message_text[6:]
|
||||||
if val:
|
if val:
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
keywords = await sqlite.get_filters_value(db_file, key)
|
keywords = sqlite.get_filter_value(db_file, key)
|
||||||
val = await config.add_to_list(val, keywords)
|
val = await config.add_to_list(val, keywords)
|
||||||
if await sqlite.get_filters_value(db_file, key):
|
if sqlite.is_filter_key(db_file, key):
|
||||||
await sqlite.update_filters_value(db_file,
|
await sqlite.update_filter_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_filters_value(db_file, [key, val])
|
await sqlite.set_filter_value(db_file, [key, val])
|
||||||
response = ('Rejected keywords\n'
|
response = ('Rejected keywords\n'
|
||||||
'```\n{}\n```'
|
'```\n{}\n```'
|
||||||
.format(val))
|
.format(val))
|
||||||
|
@ -435,17 +447,17 @@ async def message(self, message):
|
||||||
response = 'Missing keywords.'
|
response = 'Missing keywords.'
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case _ if message_lowercase.startswith('deny -'):
|
case _ if message_lowercase.startswith('deny -'):
|
||||||
key = 'filter-' + message_text[:4]
|
key = message_text[:4]
|
||||||
val = message_text[6:]
|
val = message_text[6:]
|
||||||
if val:
|
if val:
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
keywords = await sqlite.get_filters_value(db_file, key)
|
keywords = sqlite.get_filter_value(db_file, key)
|
||||||
val = await config.remove_from_list(val, keywords)
|
val = await config.remove_from_list(val, keywords)
|
||||||
if await sqlite.get_filters_value(db_file, key):
|
if sqlite.is_filter_key(db_file, key):
|
||||||
await sqlite.update_filters_value(db_file,
|
await sqlite.update_filter_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_filters_value(db_file, [key, val])
|
await sqlite.set_filter_value(db_file, [key, val])
|
||||||
response = ('Rejected keywords\n'
|
response = ('Rejected keywords\n'
|
||||||
'```\n{}\n```'
|
'```\n{}\n```'
|
||||||
.format(val))
|
.format(val))
|
||||||
|
@ -606,11 +618,11 @@ async def message(self, message):
|
||||||
try:
|
try:
|
||||||
val = int(val)
|
val = int(val)
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file,
|
await sqlite.update_setting_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file,
|
await sqlite.set_setting_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
if val == 0: # if not val:
|
if val == 0: # if not val:
|
||||||
response = 'Summary length limit is disabled.'
|
response = 'Summary length limit is disabled.'
|
||||||
|
@ -628,7 +640,7 @@ async def message(self, message):
|
||||||
# if val:
|
# if val:
|
||||||
# names = await initdb(
|
# names = await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# get_settings_value,
|
# sqlite.get_setting_value,
|
||||||
# key
|
# key
|
||||||
# )
|
# )
|
||||||
# val = await config.add_to_list(
|
# val = await config.add_to_list(
|
||||||
|
@ -637,7 +649,7 @@ async def message(self, message):
|
||||||
# )
|
# )
|
||||||
# await initdb(
|
# await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# update_settings_valuevv,
|
# sqlite.update_setting_valuevv,
|
||||||
# [key, val]
|
# [key, val]
|
||||||
# )
|
# )
|
||||||
# response = (
|
# response = (
|
||||||
|
@ -651,30 +663,30 @@ async def message(self, message):
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
key = 'media'
|
key = 'media'
|
||||||
val = 0
|
val = 0
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
response = 'Media is disabled.'
|
response = 'Media is disabled.'
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case 'media on':
|
case 'media on':
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
key = 'media'
|
key = 'media'
|
||||||
val = 1
|
val = 1
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
response = 'Media is enabled.'
|
response = 'Media is enabled.'
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case 'new':
|
case 'new':
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
key = 'old'
|
key = 'old'
|
||||||
val = 0
|
val = 0
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
response = 'Only new items of newly added feeds will be sent.'
|
response = 'Only new items of newly added feeds will be sent.'
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
# TODO Will you add support for number of messages?
|
# TODO Will you add support for number of messages?
|
||||||
|
@ -694,10 +706,10 @@ async def message(self, message):
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
key = 'old'
|
key = 'old'
|
||||||
val = 1
|
val = 1
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_setting_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_setting_value(db_file, [key, val])
|
||||||
response = 'All items of newly added feeds will be sent.'
|
response = 'All items of newly added feeds will be sent.'
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case _ if message_lowercase.startswith('quantum'):
|
case _ if message_lowercase.startswith('quantum'):
|
||||||
|
@ -710,11 +722,11 @@ async def message(self, message):
|
||||||
# 'Every update will contain {} news items.'
|
# 'Every update will contain {} news items.'
|
||||||
# ).format(response)
|
# ).format(response)
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
if sqlite.get_settings_value(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_settings_value(db_file,
|
await sqlite.update_setting_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file,
|
await sqlite.set_setting_value(db_file,
|
||||||
[key, val])
|
[key, val])
|
||||||
response = ('Next update will contain {} news items.'
|
response = ('Next update will contain {} news items.'
|
||||||
.format(val))
|
.format(val))
|
||||||
|
|
Loading…
Reference in a new issue