forked from sch/Slixfeed
Fix groupchat responses.
Segregate self.settings from 'default' settings with handler self.defaults.
This commit is contained in:
parent
bd058ebf73
commit
21cb7df160
6 changed files with 104 additions and 105 deletions
|
@ -51,27 +51,32 @@ logger = Logger(__name__)
|
||||||
# setting_jid.setting_key has value, otherwise resort to setting_default.setting_key.
|
# setting_jid.setting_key has value, otherwise resort to setting_default.setting_key.
|
||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
def add_settings_default(settings):
|
def add_settings_default(self):
|
||||||
settings_default = get_values('settings.toml', 'settings')
|
settings_default = get_values('settings.toml', 'settings')
|
||||||
settings['default'] = settings_default
|
self.defaults = settings_default
|
||||||
|
|
||||||
# TODO Open SQLite file once
|
# TODO Open SQLite file once
|
||||||
def add_settings_jid(settings, jid_bare, db_file):
|
def add_settings_jid(self, jid_bare, db_file):
|
||||||
settings[jid_bare] = {}
|
self.settings[jid_bare] = {}
|
||||||
for key in ('archive', 'enabled', 'filter', 'formatting', 'interval',
|
for key in ('archive', 'enabled', 'filter', 'formatting', 'interval',
|
||||||
'length', 'media', 'old', 'quantum'):
|
'length', 'media', 'old', 'quantum'):
|
||||||
value = sqlite.get_setting_value(db_file, key)
|
value = sqlite.get_setting_value(db_file, key)
|
||||||
if value: settings[jid_bare][key] = value[0]
|
if value:
|
||||||
|
self.settings[jid_bare][key] = value[0]
|
||||||
|
elif key != 'formatting':
|
||||||
|
# NOTE This might neglects the need for
|
||||||
|
# self.defaults of get_setting_value
|
||||||
|
self.settings[jid_bare][key] = self.defaults['default'][key]
|
||||||
|
|
||||||
def get_settings_xmpp(key=None):
|
def get_settings_xmpp(key=None):
|
||||||
result = get_values('accounts.toml', 'xmpp')
|
result = get_values('accounts.toml', 'xmpp')
|
||||||
result = result[key] if key else result
|
result = result[key] if key else result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def set_setting_value(settings, jid_bare, db_file, key, val):
|
async def set_setting_value(self, jid_bare, db_file, key, val):
|
||||||
key = key.lower()
|
key = key.lower()
|
||||||
key_val = [key, val]
|
key_val = [key, val]
|
||||||
settings[jid_bare][key] = val
|
self.settings[jid_bare][key] = val
|
||||||
if sqlite.is_setting_key(db_file, key):
|
if sqlite.is_setting_key(db_file, key):
|
||||||
await sqlite.update_setting_value(db_file, key_val)
|
await sqlite.update_setting_value(db_file, key_val)
|
||||||
else:
|
else:
|
||||||
|
@ -79,11 +84,11 @@ class Config:
|
||||||
|
|
||||||
# TODO Segregate Jabber ID settings from Slixfeed wide settings.
|
# TODO Segregate Jabber ID settings from Slixfeed wide settings.
|
||||||
# self.settings, self.settings_xmpp, self.settings_irc etc.
|
# self.settings, self.settings_xmpp, self.settings_irc etc.
|
||||||
def get_setting_value(settings, jid_bare, key):
|
def get_setting_value(self, jid_bare, key):
|
||||||
if jid_bare in settings and key in settings[jid_bare]:
|
if jid_bare in self.settings and key in self.settings[jid_bare]:
|
||||||
value = settings[jid_bare][key]
|
value = self.settings[jid_bare][key]
|
||||||
else:
|
else:
|
||||||
value = settings['default'][key]
|
value = self.defaults['default'][key]
|
||||||
return value
|
return value
|
||||||
|
|
||||||
class ConfigNetwork:
|
class ConfigNetwork:
|
||||||
|
|
|
@ -348,7 +348,7 @@ class Feed:
|
||||||
if new_entries:
|
if new_entries:
|
||||||
await sqlite.add_entries_and_update_feed_state(
|
await sqlite.add_entries_and_update_feed_state(
|
||||||
db_file, feed_id, new_entries)
|
db_file, feed_id, new_entries)
|
||||||
old = Config.get_setting_value(self.settings, jid_bare, 'old')
|
old = Config.get_setting_value(self, jid_bare, 'old')
|
||||||
if not old: await sqlite.mark_feed_as_read(db_file, feed_id)
|
if not old: await sqlite.mark_feed_as_read(db_file, feed_id)
|
||||||
result_final = {'link' : url,
|
result_final = {'link' : url,
|
||||||
'index' : feed_id,
|
'index' : feed_id,
|
||||||
|
@ -1335,7 +1335,7 @@ class FeedTask:
|
||||||
new_entries.extend([new_entry])
|
new_entries.extend([new_entry])
|
||||||
if new_entries:
|
if new_entries:
|
||||||
await sqlite.add_entries_and_update_feed_state(db_file, feed_id, new_entries)
|
await sqlite.add_entries_and_update_feed_state(db_file, feed_id, new_entries)
|
||||||
limit = Config.get_setting_value(self.settings, jid_bare, 'archive')
|
limit = Config.get_setting_value(self, jid_bare, 'archive')
|
||||||
ixs = sqlite.get_entries_id_of_feed(db_file, feed_id)
|
ixs = sqlite.get_entries_id_of_feed(db_file, feed_id)
|
||||||
ixs_invalid = {}
|
ixs_invalid = {}
|
||||||
for ix in ixs:
|
for ix in ixs:
|
||||||
|
@ -1361,7 +1361,7 @@ class FeedTask:
|
||||||
await sqlite.maintain_archive(db_file, limit)
|
await sqlite.maintain_archive(db_file, limit)
|
||||||
# await sqlite.process_invalid_entries(db_file, ixs)
|
# await sqlite.process_invalid_entries(db_file, ixs)
|
||||||
await asyncio.sleep(60 * 2)
|
await asyncio.sleep(60 * 2)
|
||||||
val = Config.get_setting_value(self.settings, jid_bare, 'check')
|
val = Config.get_setting_value(self, jid_bare, 'check')
|
||||||
await asyncio.sleep(60 * float(val))
|
await asyncio.sleep(60 * float(val))
|
||||||
# Schedule to call this function again in 90 minutes
|
# Schedule to call this function again in 90 minutes
|
||||||
# loop.call_at(
|
# loop.call_at(
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__version__ = '0.1.90'
|
__version__ = '0.1.91'
|
||||||
__version_info__ = (0, 1, 90)
|
__version_info__ = (0, 1, 91)
|
||||||
|
|
|
@ -84,7 +84,7 @@ class XmppChat:
|
||||||
command = ' '.join(message['body'].split())
|
command = ' '.join(message['body'].split())
|
||||||
command_time_start = time.time()
|
command_time_start = time.time()
|
||||||
|
|
||||||
# if (message['type'] == 'groupchat' and
|
# if (message_type == 'groupchat' and
|
||||||
# message['muc']['nick'] == self.alias):
|
# message['muc']['nick'] == self.alias):
|
||||||
# return
|
# return
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ class XmppChat:
|
||||||
else:
|
else:
|
||||||
omemo_decrypted = None
|
omemo_decrypted = None
|
||||||
|
|
||||||
if message['type'] == 'groupchat':
|
if message_type == 'groupchat':
|
||||||
command = command[1:]
|
command = command[1:]
|
||||||
command_lowercase = command.lower()
|
command_lowercase = command.lower()
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ class XmppChat:
|
||||||
|
|
||||||
# Support private message via groupchat
|
# Support private message via groupchat
|
||||||
# See https://codeberg.org/poezio/slixmpp/issues/3506
|
# See https://codeberg.org/poezio/slixmpp/issues/3506
|
||||||
if message['type'] == 'chat' and message.get_plugin('muc', check=True):
|
if message_type == 'chat' and message.get_plugin('muc', check=True):
|
||||||
# jid_bare = message_from.bare
|
# jid_bare = message_from.bare
|
||||||
jid_full = message_from.full
|
jid_full = message_from.full
|
||||||
if (jid_bare == jid_full[:jid_full.index('/')]):
|
if (jid_bare == jid_full[:jid_full.index('/')]):
|
||||||
|
@ -349,7 +349,7 @@ class XmppChat:
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
pathname, response = XmppCommands.export_feeds(
|
pathname, response = XmppCommands.export_feeds(
|
||||||
jid_bare, ext)
|
jid_bare, ext)
|
||||||
encrypt_omemo = Config.get_setting_value(self.settings, jid_bare, 'omemo')
|
encrypt_omemo = Config.get_setting_value(self, jid_bare, 'omemo')
|
||||||
encrypted = True if encrypt_omemo else False
|
encrypted = True if encrypt_omemo else False
|
||||||
url = await XmppUpload.start(self, jid_bare, Path(pathname), encrypted=encrypted)
|
url = await XmppUpload.start(self, jid_bare, Path(pathname), encrypted=encrypted)
|
||||||
# response = (
|
# response = (
|
||||||
|
@ -360,8 +360,8 @@ class XmppChat:
|
||||||
chat_type = await XmppUtilities.get_chat_type(self, jid_bare)
|
chat_type = await XmppUtilities.get_chat_type(self, jid_bare)
|
||||||
if encrypted:
|
if encrypted:
|
||||||
url_encrypted, omemo_encrypted = await XmppOmemo.encrypt(
|
url_encrypted, omemo_encrypted = await XmppOmemo.encrypt(
|
||||||
self, JID(jid_bare), url)
|
self, message_from, url)
|
||||||
XmppMessage.send_omemo_oob(self, JID(jid_bare), url_encrypted, chat_type)
|
XmppMessage.send_omemo_oob(self, message_from, url_encrypted, chat_type)
|
||||||
else:
|
else:
|
||||||
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
||||||
else:
|
else:
|
||||||
|
@ -383,7 +383,7 @@ class XmppChat:
|
||||||
response = (first_line + result +
|
response = (first_line + result +
|
||||||
'\n```\nTotal of {} feeds'.format(number))
|
'\n```\nTotal of {} feeds'.format(number))
|
||||||
case 'goodbye':
|
case 'goodbye':
|
||||||
if message['type'] == 'groupchat':
|
if message_type == 'groupchat':
|
||||||
await XmppCommands.muc_leave(self, jid_bare)
|
await XmppCommands.muc_leave(self, jid_bare)
|
||||||
else:
|
else:
|
||||||
response = 'This command is valid in groupchat only.'
|
response = 'This command is valid in groupchat only.'
|
||||||
|
@ -625,16 +625,19 @@ class XmppChat:
|
||||||
command_time_total = command_time_finish - command_time_start
|
command_time_total = command_time_finish - command_time_start
|
||||||
command_time_total = round(command_time_total, 3)
|
command_time_total = round(command_time_total, 3)
|
||||||
if response:
|
if response:
|
||||||
response_encrypted, omemo_encrypted = await XmppOmemo.encrypt(
|
encrypt_omemo = Config.get_setting_value(self, jid_bare, 'omemo')
|
||||||
self, message_from, response)
|
encrypted = True if encrypt_omemo else False
|
||||||
if omemo_encrypted and omemo_decrypted:
|
if encrypted and self['xep_0384'].is_encrypted(message):
|
||||||
message_from = message['from']
|
response_encrypted, omemo_encrypted = await XmppOmemo.encrypt(
|
||||||
message_type = message['type']
|
self, message_from, response)
|
||||||
XmppMessage.send_omemo(self, message_from, message_type, response_encrypted)
|
if omemo_decrypted and omemo_encrypted:
|
||||||
# XmppMessage.send_omemo_reply(self, message, response_encrypted)
|
# message_from = message['from']
|
||||||
|
# message_type = message['type']
|
||||||
|
XmppMessage.send_omemo(self, message_from, message_type, response_encrypted)
|
||||||
|
# XmppMessage.send_omemo_reply(self, message, response_encrypted)
|
||||||
else:
|
else:
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
if Config.get_setting_value(self.settings, jid_bare, 'finished'):
|
if Config.get_setting_value(self, jid_bare, 'finished'):
|
||||||
response_finished = 'Finished. Total time: {}s'.format(command_time_total)
|
response_finished = 'Finished. Total time: {}s'.format(command_time_total)
|
||||||
XmppMessage.send_reply(self, message, response_finished)
|
XmppMessage.send_reply(self, message, response_finished)
|
||||||
|
|
||||||
|
@ -676,12 +679,12 @@ class XmppChatAction:
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug('{}: jid: {} num: {}'.format(function_name, jid_bare, num))
|
logger.debug('{}: jid: {} num: {}'.format(function_name, jid_bare, num))
|
||||||
db_file = config.get_pathname_to_database(jid_bare)
|
db_file = config.get_pathname_to_database(jid_bare)
|
||||||
encrypt_omemo = Config.get_setting_value(self.settings, jid_bare, 'omemo')
|
encrypt_omemo = Config.get_setting_value(self, jid_bare, 'omemo')
|
||||||
encrypted = True if encrypt_omemo else False
|
encrypted = True if encrypt_omemo else False
|
||||||
jid = JID(jid_bare)
|
jid = JID(jid_bare)
|
||||||
show_media = Config.get_setting_value(self.settings, jid_bare, 'media')
|
show_media = Config.get_setting_value(self, jid_bare, 'media')
|
||||||
if not num:
|
if not num:
|
||||||
num = Config.get_setting_value(self.settings, jid_bare, 'quantum')
|
num = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||||
else:
|
else:
|
||||||
num = int(num)
|
num = int(num)
|
||||||
results = sqlite.get_unread_entries(db_file, num)
|
results = sqlite.get_unread_entries(db_file, num)
|
||||||
|
@ -883,7 +886,7 @@ class XmppChatAction:
|
||||||
summary = summary.replace(' ', ' ')
|
summary = summary.replace(' ', ' ')
|
||||||
# summary = summary.replace(' ', ' ')
|
# summary = summary.replace(' ', ' ')
|
||||||
summary = ' '.join(summary.split())
|
summary = ' '.join(summary.split())
|
||||||
length = Config.get_setting_value(self.settings, jid, 'length')
|
length = Config.get_setting_value(self, jid, 'length')
|
||||||
length = int(length)
|
length = int(length)
|
||||||
summary = summary[:length] + " […]"
|
summary = summary[:length] + " […]"
|
||||||
# summary = summary.strip().split('\n')
|
# summary = summary.strip().split('\n')
|
||||||
|
@ -897,7 +900,7 @@ class XmppChatAction:
|
||||||
feed_id = result[4]
|
feed_id = result[4]
|
||||||
# news_item = ("\n{}\n{}\n{} [{}]\n").format(str(title), str(link),
|
# news_item = ("\n{}\n{}\n{} [{}]\n").format(str(title), str(link),
|
||||||
# str(feed_title), str(ix))
|
# str(feed_title), str(ix))
|
||||||
formatting = Config.get_setting_value(self.settings, jid, 'formatting')
|
formatting = Config.get_setting_value(self, jid, 'formatting')
|
||||||
news_item = formatting.format(feed_title=feed_title,
|
news_item = formatting.format(feed_title=feed_title,
|
||||||
title=title,
|
title=title,
|
||||||
summary=summary,
|
summary=summary,
|
||||||
|
@ -914,9 +917,9 @@ class XmppChatTask:
|
||||||
async def task_message(self, jid_bare):
|
async def task_message(self, jid_bare):
|
||||||
db_file = config.get_pathname_to_database(jid_bare)
|
db_file = config.get_pathname_to_database(jid_bare)
|
||||||
if jid_bare not in self.settings:
|
if jid_bare not in self.settings:
|
||||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
Config.add_settings_jid(self, jid_bare, db_file)
|
||||||
while True:
|
while True:
|
||||||
update_interval = Config.get_setting_value(self.settings, jid_bare, 'interval')
|
update_interval = Config.get_setting_value(self, jid_bare, 'interval')
|
||||||
update_interval = 60 * int(update_interval)
|
update_interval = 60 * int(update_interval)
|
||||||
last_update_time = sqlite.get_last_update_time(db_file)
|
last_update_time = sqlite.get_last_update_time(db_file)
|
||||||
if last_update_time:
|
if last_update_time:
|
||||||
|
|
|
@ -117,14 +117,16 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
# Handler for ping
|
# Handler for ping
|
||||||
self.task_ping_instance = {}
|
self.task_ping_instance = {}
|
||||||
|
|
||||||
|
# Handler for default configuration
|
||||||
|
self.defaults = config.get_values('settings.toml')
|
||||||
# Handler for configuration
|
# Handler for configuration
|
||||||
self.settings = config.get_values('settings.toml')
|
self.settings = {}
|
||||||
# Handler for operators
|
# Handler for operators
|
||||||
self.operators = config.get_values('accounts.toml', 'xmpp')['operators']
|
self.operators = config.get_values('accounts.toml', 'xmpp')['operators']
|
||||||
|
|
||||||
# self.settings = {}
|
# self.settings = {}
|
||||||
# # Populate dict handler
|
# # Populate dict handler
|
||||||
# Config.add_settings_default(self.settings)
|
# Config.add_settings_default(self)
|
||||||
|
|
||||||
# Handlers for connection events
|
# Handlers for connection events
|
||||||
self.connection_attempts = 0
|
self.connection_attempts = 0
|
||||||
|
@ -353,12 +355,12 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
# jid_bare = result['jid']
|
# jid_bare = result['jid']
|
||||||
# if jid_bare not in self.settings:
|
# if jid_bare not in self.settings:
|
||||||
# db_file = config.get_pathname_to_database(jid_bare)
|
# db_file = config.get_pathname_to_database(jid_bare)
|
||||||
# Config.add_settings_jid(self.settings, jid_bare, db_file)
|
# Config.add_settings_jid(self, jid_bare, db_file)
|
||||||
# await FeedTask.check_updates(self, jid_bare)
|
# await FeedTask.check_updates(self, jid_bare)
|
||||||
# XmppPubsubTask.task_publish(self, jid_bare)
|
# XmppPubsubTask.task_publish(self, jid_bare)
|
||||||
bookmarks = await XmppBookmark.get_bookmarks(self)
|
bookmarks = await XmppBookmark.get_bookmarks(self)
|
||||||
await XmppGroupchat.autojoin(self, bookmarks)
|
await XmppGroupchat.autojoin(self, bookmarks)
|
||||||
if 'ipc' in self.settings and self.settings['ipc']['bsd']:
|
if 'ipc' in self.defaults and self.defaults['ipc']['bsd']:
|
||||||
# Start Inter-Process Communication
|
# Start Inter-Process Communication
|
||||||
print('POSIX sockets: Initiating IPC server...')
|
print('POSIX sockets: Initiating IPC server...')
|
||||||
self.ipc = asyncio.create_task(XmppIpcServer.ipc(self))
|
self.ipc = asyncio.create_task(XmppIpcServer.ipc(self))
|
||||||
|
@ -408,7 +410,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
jid_bare = message['from'].bare
|
jid_bare = message['from'].bare
|
||||||
db_file = config.get_pathname_to_database(jid_bare)
|
db_file = config.get_pathname_to_database(jid_bare)
|
||||||
if jid_bare not in self.settings:
|
if jid_bare not in self.settings:
|
||||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
Config.add_settings_jid(self, jid_bare, db_file)
|
||||||
if jid_bare == self.boundjid.bare:
|
if jid_bare == self.boundjid.bare:
|
||||||
status_type = 'dnd'
|
status_type = 'dnd'
|
||||||
status_message = ('Slixfeed is not designed to receive messages '
|
status_message = ('Slixfeed is not designed to receive messages '
|
||||||
|
@ -1308,7 +1310,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
db_file = config.get_pathname_to_database(jid_bare)
|
db_file = config.get_pathname_to_database(jid_bare)
|
||||||
if jid_bare not in self.settings:
|
if jid_bare not in self.settings:
|
||||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
Config.add_settings_jid(self, jid_bare, db_file)
|
||||||
form = self['xep_0004'].make_form('form', 'Profile')
|
form = self['xep_0004'].make_form('form', 'Profile')
|
||||||
form['instructions'] = ('Displaying information\nJabber ID {}'
|
form['instructions'] = ('Displaying information\nJabber ID {}'
|
||||||
.format(jid_bare))
|
.format(jid_bare))
|
||||||
|
@ -1332,42 +1334,42 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
value=unread)
|
value=unread)
|
||||||
form.add_field(ftype='fixed',
|
form.add_field(ftype='fixed',
|
||||||
label='Options')
|
label='Options')
|
||||||
key_archive = Config.get_setting_value(self.settings, jid_bare, 'archive')
|
key_archive = Config.get_setting_value(self, jid_bare, 'archive')
|
||||||
key_archive = str(key_archive)
|
key_archive = str(key_archive)
|
||||||
form.add_field(label='Archive',
|
form.add_field(label='Archive',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_archive)
|
value=key_archive)
|
||||||
key_enabled = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
key_enabled = Config.get_setting_value(self, jid_bare, 'enabled')
|
||||||
key_enabled = str(key_enabled)
|
key_enabled = str(key_enabled)
|
||||||
form.add_field(label='Enabled',
|
form.add_field(label='Enabled',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_enabled)
|
value=key_enabled)
|
||||||
key_interval = Config.get_setting_value(self.settings, jid_bare, 'interval')
|
key_interval = Config.get_setting_value(self, jid_bare, 'interval')
|
||||||
key_interval = str(key_interval)
|
key_interval = str(key_interval)
|
||||||
form.add_field(label='Interval',
|
form.add_field(label='Interval',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_interval)
|
value=key_interval)
|
||||||
key_length = Config.get_setting_value(self.settings, jid_bare, 'length')
|
key_length = Config.get_setting_value(self, jid_bare, 'length')
|
||||||
key_length = str(key_length)
|
key_length = str(key_length)
|
||||||
form.add_field(label='Length',
|
form.add_field(label='Length',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_length)
|
value=key_length)
|
||||||
key_media = Config.get_setting_value(self.settings, jid_bare, 'media')
|
key_media = Config.get_setting_value(self, jid_bare, 'media')
|
||||||
key_media = str(key_media)
|
key_media = str(key_media)
|
||||||
form.add_field(label='Media',
|
form.add_field(label='Media',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_media)
|
value=key_media)
|
||||||
key_old = Config.get_setting_value(self.settings, jid_bare, 'old')
|
key_old = Config.get_setting_value(self, jid_bare, 'old')
|
||||||
key_old = str(key_old)
|
key_old = str(key_old)
|
||||||
form.add_field(label='Old',
|
form.add_field(label='Old',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_old)
|
value=key_old)
|
||||||
key_quantum = Config.get_setting_value(self.settings, jid_bare, 'quantum')
|
key_quantum = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||||
key_quantum = str(key_quantum)
|
key_quantum = str(key_quantum)
|
||||||
form.add_field(label='Quantum',
|
form.add_field(label='Quantum',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_quantum)
|
value=key_quantum)
|
||||||
update_interval = Config.get_setting_value(self.settings, jid_bare, 'interval')
|
update_interval = Config.get_setting_value(self, jid_bare, 'interval')
|
||||||
update_interval = str(update_interval)
|
update_interval = str(update_interval)
|
||||||
update_interval = 60 * int(update_interval)
|
update_interval = 60 * int(update_interval)
|
||||||
last_update_time = sqlite.get_last_update_time(db_file)
|
last_update_time = sqlite.get_last_update_time(db_file)
|
||||||
|
@ -2899,7 +2901,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
exts = values['filetype']
|
exts = values['filetype']
|
||||||
for ext in exts:
|
for ext in exts:
|
||||||
filename = Feed.export_feeds(jid_bare, ext)
|
filename = Feed.export_feeds(jid_bare, ext)
|
||||||
encrypt_omemo = Config.get_setting_value(self.settings, jid_bare, 'omemo')
|
encrypt_omemo = Config.get_setting_value(self, jid_bare, 'omemo')
|
||||||
encrypted = True if encrypt_omemo else False
|
encrypted = True if encrypt_omemo else False
|
||||||
url = await XmppUpload.start(
|
url = await XmppUpload.start(
|
||||||
self, jid_bare, Path(filename), encrypted=encrypted)
|
self, jid_bare, Path(filename), encrypted=encrypted)
|
||||||
|
@ -3079,7 +3081,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
form['instructions'] = ('Select a Publish-Subscribe service '
|
form['instructions'] = ('Select a Publish-Subscribe service '
|
||||||
'of which nodes you want to list.')
|
'of which nodes you want to list.')
|
||||||
# jid_bare = self.boundjid.bare
|
# jid_bare = self.boundjid.bare
|
||||||
# enabled_state = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
# enabled_state = Config.get_setting_value(self, jid_bare, 'enabled')
|
||||||
|
|
||||||
results = await XmppPubsub.get_pubsub_services(self)
|
results = await XmppPubsub.get_pubsub_services(self)
|
||||||
options = form.add_field(desc='Select a PubSub service.',
|
options = form.add_field(desc='Select a PubSub service.',
|
||||||
|
@ -3104,7 +3106,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
ftype='fixed',
|
ftype='fixed',
|
||||||
label='Jabber ID')
|
label='Jabber ID')
|
||||||
# jid_bare = self.boundjid.bare
|
# jid_bare = self.boundjid.bare
|
||||||
# enabled_state = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
# enabled_state = Config.get_setting_value(self, jid_bare, 'enabled')
|
||||||
|
|
||||||
results = await XmppPubsub.get_pubsub_services(self)
|
results = await XmppPubsub.get_pubsub_services(self)
|
||||||
for result in results + [{'jid' : self.boundjid.bare,
|
for result in results + [{'jid' : self.boundjid.bare,
|
||||||
|
@ -3112,7 +3114,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
jid_bare = result['jid']
|
jid_bare = result['jid']
|
||||||
name = result['name']
|
name = result['name']
|
||||||
enabled_state = Config.get_setting_value(
|
enabled_state = Config.get_setting_value(
|
||||||
self.settings, jid_bare, 'enabled')
|
self, jid_bare, 'enabled')
|
||||||
form.add_field(desc=jid_bare,
|
form.add_field(desc=jid_bare,
|
||||||
ftype='boolean',
|
ftype='boolean',
|
||||||
label=name,
|
label=name,
|
||||||
|
@ -3383,9 +3385,9 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
value = values[key]
|
value = values[key]
|
||||||
db_file = config.get_pathname_to_database(jid_bare)
|
db_file = config.get_pathname_to_database(jid_bare)
|
||||||
if jid_bare not in self.settings:
|
if jid_bare not in self.settings:
|
||||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
Config.add_settings_jid(self, jid_bare, db_file)
|
||||||
await Config.set_setting_value(self.settings, jid_bare,
|
await Config.set_setting_value(
|
||||||
db_file, 'enabled', value)
|
self, jid_bare, db_file, 'enabled', value)
|
||||||
print(self.settings)
|
print(self.settings)
|
||||||
text_note = 'Done.'
|
text_note = 'Done.'
|
||||||
session['has_next'] = False
|
session['has_next'] = False
|
||||||
|
@ -3645,10 +3647,10 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
if XmppUtilities.is_access(self, jid_bare, jid_full, chat_type):
|
if XmppUtilities.is_access(self, jid_bare, jid_full, chat_type):
|
||||||
db_file = config.get_pathname_to_database(jid_bare)
|
db_file = config.get_pathname_to_database(jid_bare)
|
||||||
if jid_bare not in self.settings:
|
if jid_bare not in self.settings:
|
||||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
Config.add_settings_jid(self, jid_bare, db_file)
|
||||||
form = self['xep_0004'].make_form('form', 'Settings')
|
form = self['xep_0004'].make_form('form', 'Settings')
|
||||||
form['instructions'] = 'Editing settings of {}'.format(jid_bare)
|
form['instructions'] = 'Editing settings of {}'.format(jid_bare)
|
||||||
value = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
value = Config.get_setting_value(self, jid_bare, 'enabled')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if value:
|
if value:
|
||||||
|
@ -3660,7 +3662,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
label='Enabled',
|
label='Enabled',
|
||||||
value=value,
|
value=value,
|
||||||
var='enabled')
|
var='enabled')
|
||||||
value = Config.get_setting_value(self.settings, jid_bare, 'media')
|
value = Config.get_setting_value(self, jid_bare, 'media')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if value:
|
if value:
|
||||||
|
@ -3672,7 +3674,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
label='Display media',
|
label='Display media',
|
||||||
value=value,
|
value=value,
|
||||||
var='media')
|
var='media')
|
||||||
value = Config.get_setting_value(self.settings, jid_bare, 'old')
|
value = Config.get_setting_value(self, jid_bare, 'old')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if value:
|
if value:
|
||||||
|
@ -3686,7 +3688,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
label='Include old news',
|
label='Include old news',
|
||||||
value=value,
|
value=value,
|
||||||
var='old')
|
var='old')
|
||||||
value = Config.get_setting_value(self.settings, jid_bare, 'interval')
|
value = Config.get_setting_value(self, jid_bare, 'interval')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
value = value/60
|
value = value/60
|
||||||
|
@ -3707,7 +3709,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
i += 6
|
i += 6
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
value = Config.get_setting_value(self.settings, jid_bare, 'quantum')
|
value = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
options = form.add_field(desc='Amount of items per update.',
|
options = form.add_field(desc='Amount of items per update.',
|
||||||
ftype='list-single',
|
ftype='list-single',
|
||||||
|
@ -3721,7 +3723,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
x = str(i)
|
x = str(i)
|
||||||
options.addOption(x, x)
|
options.addOption(x, x)
|
||||||
i += 1
|
i += 1
|
||||||
value = Config.get_setting_value(self.settings, jid_bare, 'archive')
|
value = Config.get_setting_value(self, jid_bare, 'archive')
|
||||||
value = str(value)
|
value = str(value)
|
||||||
options = form.add_field(desc='Number of news items to archive.',
|
options = form.add_field(desc='Number of news items to archive.',
|
||||||
ftype='list-single',
|
ftype='list-single',
|
||||||
|
@ -3762,7 +3764,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
db_file = config.get_pathname_to_database(jid_bare)
|
db_file = config.get_pathname_to_database(jid_bare)
|
||||||
if jid_bare not in self.settings:
|
if jid_bare not in self.settings:
|
||||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
Config.add_settings_jid(self, jid_bare, db_file)
|
||||||
# In this case (as is typical), the payload is a form
|
# In this case (as is typical), the payload is a form
|
||||||
values = payload['values']
|
values = payload['values']
|
||||||
for key in values:
|
for key in values:
|
||||||
|
@ -3781,7 +3783,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
if val < 1: val = 1
|
if val < 1: val = 1
|
||||||
val = val * 60
|
val = val * 60
|
||||||
|
|
||||||
is_enabled = Config.get_setting_value(self.settings, jid_bare, 'enabled')
|
is_enabled = Config.get_setting_value(self, jid_bare, 'enabled')
|
||||||
|
|
||||||
if (key == 'enabled' and
|
if (key == 'enabled' and
|
||||||
val == 1 and
|
val == 1 and
|
||||||
|
@ -3807,7 +3809,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
|
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val)
|
await Config.set_setting_value(self, jid_bare, db_file, key, val)
|
||||||
val = self.settings[jid_bare][key]
|
val = self.settings[jid_bare][key]
|
||||||
|
|
||||||
if key in ('enabled', 'media', 'old'):
|
if key in ('enabled', 'media', 'old'):
|
||||||
|
|
|
@ -174,10 +174,8 @@ class XmppCommands:
|
||||||
# the look into function "check_updates" of module "task".
|
# the look into function "check_updates" of module "task".
|
||||||
# await action.scan(self, jid_bare, db_file, url)
|
# await action.scan(self, jid_bare, db_file, url)
|
||||||
# if jid_bare not in self.settings:
|
# if jid_bare not in self.settings:
|
||||||
# Config.add_settings_jid(self.settings, jid_bare,
|
# Config.add_settings_jid(self, jid_bare, db_file)
|
||||||
# db_file)
|
# old = Config.get_setting_value(self, jid_bare, 'old')
|
||||||
# old = Config.get_setting_value(self.settings, jid_bare,
|
|
||||||
# 'old')
|
|
||||||
# if old:
|
# if old:
|
||||||
# # task.clean_tasks_xmpp_chat(self, jid_bare, ['status'])
|
# # task.clean_tasks_xmpp_chat(self, jid_bare, ['status'])
|
||||||
# # await send_status(jid)
|
# # await send_status(jid)
|
||||||
|
@ -234,8 +232,7 @@ class XmppCommands:
|
||||||
|
|
||||||
|
|
||||||
def get_archive(self, jid_bare):
|
def get_archive(self, jid_bare):
|
||||||
result = Config.get_setting_value(
|
result = Config.get_setting_value(self, jid_bare, 'archive')
|
||||||
self.settings, jid_bare, 'archive')
|
|
||||||
message = str(result)
|
message = str(result)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@ -246,10 +243,9 @@ class XmppCommands:
|
||||||
if val_new > 500:
|
if val_new > 500:
|
||||||
message = 'Value may not be greater than 500.'
|
message = 'Value may not be greater than 500.'
|
||||||
else:
|
else:
|
||||||
val_old = Config.get_setting_value(
|
val_old = Config.get_setting_value(self, jid_bare, 'archive')
|
||||||
self.settings, jid_bare, 'archive')
|
|
||||||
await Config.set_setting_value(
|
await Config.set_setting_value(
|
||||||
self.settings, jid_bare, db_file, 'archive', val_new)
|
self, jid_bare, db_file, 'archive', val_new)
|
||||||
message = ('Maximum archived items has been set to {} (was: {}).'
|
message = ('Maximum archived items has been set to {} (was: {}).'
|
||||||
.format(val_new, val_old))
|
.format(val_new, val_old))
|
||||||
except:
|
except:
|
||||||
|
@ -550,8 +546,7 @@ class XmppCommands:
|
||||||
|
|
||||||
|
|
||||||
def get_interval(self, jid_bare):
|
def get_interval(self, jid_bare):
|
||||||
result = Config.get_setting_value(
|
result = Config.get_setting_value(self, jid_bare, 'interval')
|
||||||
self.settings, jid_bare, 'interval')
|
|
||||||
message = str(result)
|
message = str(result)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@ -559,10 +554,9 @@ class XmppCommands:
|
||||||
async def set_interval(self, db_file, jid_bare, val):
|
async def set_interval(self, db_file, jid_bare, val):
|
||||||
try:
|
try:
|
||||||
val_new = int(val)
|
val_new = int(val)
|
||||||
val_old = Config.get_setting_value(
|
val_old = Config.get_setting_value(self, jid_bare, 'interval')
|
||||||
self.settings, jid_bare, 'interval')
|
|
||||||
await Config.set_setting_value(
|
await Config.set_setting_value(
|
||||||
self.settings, jid_bare, db_file, 'interval', val_new)
|
self, jid_bare, db_file, 'interval', val_new)
|
||||||
message = ('Updates will be sent every {} minutes '
|
message = ('Updates will be sent every {} minutes '
|
||||||
'(was: {}).'.format(val_new, val_old))
|
'(was: {}).'.format(val_new, val_old))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -596,8 +590,7 @@ class XmppCommands:
|
||||||
|
|
||||||
|
|
||||||
def get_length(self, jid_bare):
|
def get_length(self, jid_bare):
|
||||||
result = Config.get_setting_value(
|
result = Config.get_setting_value(self, jid_bare, 'length')
|
||||||
self.settings, jid_bare, 'length')
|
|
||||||
result = str(result)
|
result = str(result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -605,10 +598,9 @@ class XmppCommands:
|
||||||
async def set_length(self, db_file, jid_bare, val):
|
async def set_length(self, db_file, jid_bare, val):
|
||||||
try:
|
try:
|
||||||
val_new = int(val)
|
val_new = int(val)
|
||||||
val_old = Config.get_setting_value(
|
val_old = Config.get_setting_value(self, jid_bare, 'length')
|
||||||
self.settings, jid_bare, 'length')
|
|
||||||
await Config.set_setting_value(
|
await Config.set_setting_value(
|
||||||
self.settings, jid_bare, db_file, 'length', val_new)
|
self, jid_bare, db_file, 'length', val_new)
|
||||||
if not val_new: # i.e. val_new == 0
|
if not val_new: # i.e. val_new == 0
|
||||||
# TODO Add action to disable limit
|
# TODO Add action to disable limit
|
||||||
message = ('Summary length limit is disabled '
|
message = ('Summary length limit is disabled '
|
||||||
|
@ -625,37 +617,37 @@ class XmppCommands:
|
||||||
|
|
||||||
|
|
||||||
async def set_media_off(self, jid_bare, db_file):
|
async def set_media_off(self, jid_bare, db_file):
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, 'media', 0)
|
await Config.set_setting_value(self, jid_bare, db_file, 'media', 0)
|
||||||
message = 'Media is disabled.'
|
message = 'Media is disabled.'
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
async def set_media_on(self, jid_bare, db_file):
|
async def set_media_on(self, jid_bare, db_file):
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, 'media', 1)
|
await Config.set_setting_value(self, jid_bare, db_file, 'media', 1)
|
||||||
message = 'Media is enabled.'
|
message = 'Media is enabled.'
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
async def set_old_off(self, jid_bare, db_file):
|
async def set_old_off(self, jid_bare, db_file):
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, 'old', 0)
|
await Config.set_setting_value(self, jid_bare, db_file, 'old', 0)
|
||||||
message = 'Only new items of newly added feeds be delivered.'
|
message = 'Only new items of newly added feeds be delivered.'
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
async def set_old_on(self, jid_bare, db_file):
|
async def set_old_on(self, jid_bare, db_file):
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, 'old', 1)
|
await Config.set_setting_value(self, jid_bare, db_file, 'old', 1)
|
||||||
message = 'All items of newly added feeds be delivered.'
|
message = 'All items of newly added feeds be delivered.'
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
async def set_omemo_off(self, jid_bare, db_file):
|
async def set_omemo_off(self, jid_bare, db_file):
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, 'omemo', 0)
|
await Config.set_setting_value(self, jid_bare, db_file, 'omemo', 0)
|
||||||
message = 'OMEMO is disabled.'
|
message = 'OMEMO is disabled.'
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
async def set_omemo_on(self, jid_bare, db_file):
|
async def set_omemo_on(self, jid_bare, db_file):
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, 'omemo', 1)
|
await Config.set_setting_value(self, jid_bare, db_file, 'omemo', 1)
|
||||||
message = 'OMEMO is enabled.'
|
message = 'OMEMO is enabled.'
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@ -699,8 +691,8 @@ class XmppCommands:
|
||||||
def print_options(self, jid_bare):
|
def print_options(self, jid_bare):
|
||||||
message = ''
|
message = ''
|
||||||
for key in self.settings[jid_bare]:
|
for key in self.settings[jid_bare]:
|
||||||
val = Config.get_setting_value(self.settings, jid_bare, key)
|
val = Config.get_setting_value(self, jid_bare, key)
|
||||||
# val = Config.get_setting_value(self.settings, jid_bare, key)
|
# val = Config.get_setting_value(self, jid_bare, key)
|
||||||
steps = 11 - len(key)
|
steps = 11 - len(key)
|
||||||
pulse = ''
|
pulse = ''
|
||||||
for step in range(steps):
|
for step in range(steps):
|
||||||
|
@ -710,8 +702,7 @@ class XmppCommands:
|
||||||
|
|
||||||
|
|
||||||
def get_quantum(self, jid_bare):
|
def get_quantum(self, jid_bare):
|
||||||
result = Config.get_setting_value(
|
result = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||||
self.settings, jid_bare, 'quantum')
|
|
||||||
message = str(result)
|
message = str(result)
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@ -719,14 +710,13 @@ class XmppCommands:
|
||||||
async def set_quantum(self, db_file, jid_bare, val):
|
async def set_quantum(self, db_file, jid_bare, val):
|
||||||
try:
|
try:
|
||||||
val_new = int(val)
|
val_new = int(val)
|
||||||
val_old = Config.get_setting_value(
|
val_old = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||||
self.settings, jid_bare, 'quantum')
|
|
||||||
# response = (
|
# response = (
|
||||||
# 'Every update will contain {} news items.'
|
# 'Every update will contain {} news items.'
|
||||||
# ).format(response)
|
# ).format(response)
|
||||||
db_file = config.get_pathname_to_database(jid_bare)
|
db_file = config.get_pathname_to_database(jid_bare)
|
||||||
await Config.set_setting_value(self.settings, jid_bare,
|
await Config.set_setting_value(
|
||||||
db_file, 'quantum', val_new)
|
self, jid_bare, db_file, 'quantum', val_new)
|
||||||
message = ('Next update will contain {} news items (was: {}).'
|
message = ('Next update will contain {} news items (was: {}).'
|
||||||
.format(val_new, val_old))
|
.format(val_new, val_old))
|
||||||
except:
|
except:
|
||||||
|
@ -971,7 +961,7 @@ class XmppCommands:
|
||||||
# Tasks are classes which are passed to this function
|
# Tasks are classes which are passed to this function
|
||||||
# On an occasion in which they would have returned, variable "tasks" might be called "callback"
|
# On an occasion in which they would have returned, variable "tasks" might be called "callback"
|
||||||
async def scheduler_start(self, db_file, jid_bare, callbacks):
|
async def scheduler_start(self, db_file, jid_bare, callbacks):
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, 'enabled', 1)
|
await Config.set_setting_value(self, jid_bare, db_file, 'enabled', 1)
|
||||||
for callback in callbacks:
|
for callback in callbacks:
|
||||||
callback.restart_task(self, jid_bare)
|
callback.restart_task(self, jid_bare)
|
||||||
message = 'Updates are enabled.'
|
message = 'Updates are enabled.'
|
||||||
|
@ -979,8 +969,7 @@ class XmppCommands:
|
||||||
|
|
||||||
|
|
||||||
async def scheduler_stop(self, db_file, jid_bare):
|
async def scheduler_stop(self, db_file, jid_bare):
|
||||||
await Config.set_setting_value(
|
await Config.set_setting_value(self, jid_bare, db_file, 'enabled', 0)
|
||||||
self.settings, jid_bare, db_file, 'enabled', 0)
|
|
||||||
for task in ('interval', 'status'):
|
for task in ('interval', 'status'):
|
||||||
if (jid_bare in self.task_manager and
|
if (jid_bare in self.task_manager and
|
||||||
task in self.task_manager[jid_bare]):
|
task in self.task_manager[jid_bare]):
|
||||||
|
|
Loading…
Reference in a new issue