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.
|
||||
class Config:
|
||||
|
||||
def add_settings_default(settings):
|
||||
def add_settings_default(self):
|
||||
settings_default = get_values('settings.toml', 'settings')
|
||||
settings['default'] = settings_default
|
||||
self.defaults = settings_default
|
||||
|
||||
# TODO Open SQLite file once
|
||||
def add_settings_jid(settings, jid_bare, db_file):
|
||||
settings[jid_bare] = {}
|
||||
def add_settings_jid(self, jid_bare, db_file):
|
||||
self.settings[jid_bare] = {}
|
||||
for key in ('archive', 'enabled', 'filter', 'formatting', 'interval',
|
||||
'length', 'media', 'old', 'quantum'):
|
||||
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):
|
||||
result = get_values('accounts.toml', 'xmpp')
|
||||
result = result[key] if key else 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_val = [key, val]
|
||||
settings[jid_bare][key] = val
|
||||
self.settings[jid_bare][key] = val
|
||||
if sqlite.is_setting_key(db_file, key):
|
||||
await sqlite.update_setting_value(db_file, key_val)
|
||||
else:
|
||||
|
@ -79,11 +84,11 @@ class Config:
|
|||
|
||||
# TODO Segregate Jabber ID settings from Slixfeed wide settings.
|
||||
# self.settings, self.settings_xmpp, self.settings_irc etc.
|
||||
def get_setting_value(settings, jid_bare, key):
|
||||
if jid_bare in settings and key in settings[jid_bare]:
|
||||
value = settings[jid_bare][key]
|
||||
def get_setting_value(self, jid_bare, key):
|
||||
if jid_bare in self.settings and key in self.settings[jid_bare]:
|
||||
value = self.settings[jid_bare][key]
|
||||
else:
|
||||
value = settings['default'][key]
|
||||
value = self.defaults['default'][key]
|
||||
return value
|
||||
|
||||
class ConfigNetwork:
|
||||
|
|
|
@ -348,7 +348,7 @@ class Feed:
|
|||
if new_entries:
|
||||
await sqlite.add_entries_and_update_feed_state(
|
||||
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)
|
||||
result_final = {'link' : url,
|
||||
'index' : feed_id,
|
||||
|
@ -1335,7 +1335,7 @@ class FeedTask:
|
|||
new_entries.extend([new_entry])
|
||||
if 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_invalid = {}
|
||||
for ix in ixs:
|
||||
|
@ -1361,7 +1361,7 @@ class FeedTask:
|
|||
await sqlite.maintain_archive(db_file, limit)
|
||||
# await sqlite.process_invalid_entries(db_file, ixs)
|
||||
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))
|
||||
# Schedule to call this function again in 90 minutes
|
||||
# loop.call_at(
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
__version__ = '0.1.90'
|
||||
__version_info__ = (0, 1, 90)
|
||||
__version__ = '0.1.91'
|
||||
__version_info__ = (0, 1, 91)
|
||||
|
|
|
@ -84,7 +84,7 @@ class XmppChat:
|
|||
command = ' '.join(message['body'].split())
|
||||
command_time_start = time.time()
|
||||
|
||||
# if (message['type'] == 'groupchat' and
|
||||
# if (message_type == 'groupchat' and
|
||||
# message['muc']['nick'] == self.alias):
|
||||
# return
|
||||
|
||||
|
@ -160,7 +160,7 @@ class XmppChat:
|
|||
else:
|
||||
omemo_decrypted = None
|
||||
|
||||
if message['type'] == 'groupchat':
|
||||
if message_type == 'groupchat':
|
||||
command = command[1:]
|
||||
command_lowercase = command.lower()
|
||||
|
||||
|
@ -168,7 +168,7 @@ class XmppChat:
|
|||
|
||||
# Support private message via groupchat
|
||||
# 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_full = message_from.full
|
||||
if (jid_bare == jid_full[:jid_full.index('/')]):
|
||||
|
@ -349,7 +349,7 @@ class XmppChat:
|
|||
status_type=status_type)
|
||||
pathname, response = XmppCommands.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
|
||||
url = await XmppUpload.start(self, jid_bare, Path(pathname), encrypted=encrypted)
|
||||
# response = (
|
||||
|
@ -360,8 +360,8 @@ class XmppChat:
|
|||
chat_type = await XmppUtilities.get_chat_type(self, jid_bare)
|
||||
if encrypted:
|
||||
url_encrypted, omemo_encrypted = await XmppOmemo.encrypt(
|
||||
self, JID(jid_bare), url)
|
||||
XmppMessage.send_omemo_oob(self, JID(jid_bare), url_encrypted, chat_type)
|
||||
self, message_from, url)
|
||||
XmppMessage.send_omemo_oob(self, message_from, url_encrypted, chat_type)
|
||||
else:
|
||||
XmppMessage.send_oob(self, jid_bare, url, chat_type)
|
||||
else:
|
||||
|
@ -383,7 +383,7 @@ class XmppChat:
|
|||
response = (first_line + result +
|
||||
'\n```\nTotal of {} feeds'.format(number))
|
||||
case 'goodbye':
|
||||
if message['type'] == 'groupchat':
|
||||
if message_type == 'groupchat':
|
||||
await XmppCommands.muc_leave(self, jid_bare)
|
||||
else:
|
||||
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 = round(command_time_total, 3)
|
||||
if response:
|
||||
encrypt_omemo = Config.get_setting_value(self, jid_bare, 'omemo')
|
||||
encrypted = True if encrypt_omemo else False
|
||||
if encrypted and self['xep_0384'].is_encrypted(message):
|
||||
response_encrypted, omemo_encrypted = await XmppOmemo.encrypt(
|
||||
self, message_from, response)
|
||||
if omemo_encrypted and omemo_decrypted:
|
||||
message_from = message['from']
|
||||
message_type = message['type']
|
||||
if omemo_decrypted and omemo_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:
|
||||
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)
|
||||
XmppMessage.send_reply(self, message, response_finished)
|
||||
|
||||
|
@ -676,12 +679,12 @@ class XmppChatAction:
|
|||
function_name = sys._getframe().f_code.co_name
|
||||
logger.debug('{}: jid: {} num: {}'.format(function_name, jid_bare, num))
|
||||
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
|
||||
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:
|
||||
num = Config.get_setting_value(self.settings, jid_bare, 'quantum')
|
||||
num = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||
else:
|
||||
num = int(num)
|
||||
results = sqlite.get_unread_entries(db_file, num)
|
||||
|
@ -883,7 +886,7 @@ class XmppChatAction:
|
|||
summary = summary.replace(' ', ' ')
|
||||
# summary = summary.replace(' ', ' ')
|
||||
summary = ' '.join(summary.split())
|
||||
length = Config.get_setting_value(self.settings, jid, 'length')
|
||||
length = Config.get_setting_value(self, jid, 'length')
|
||||
length = int(length)
|
||||
summary = summary[:length] + " […]"
|
||||
# summary = summary.strip().split('\n')
|
||||
|
@ -897,7 +900,7 @@ class XmppChatAction:
|
|||
feed_id = result[4]
|
||||
# news_item = ("\n{}\n{}\n{} [{}]\n").format(str(title), str(link),
|
||||
# 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,
|
||||
title=title,
|
||||
summary=summary,
|
||||
|
@ -914,9 +917,9 @@ class XmppChatTask:
|
|||
async def task_message(self, jid_bare):
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
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:
|
||||
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)
|
||||
last_update_time = sqlite.get_last_update_time(db_file)
|
||||
if last_update_time:
|
||||
|
|
|
@ -117,14 +117,16 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
# Handler for ping
|
||||
self.task_ping_instance = {}
|
||||
|
||||
# Handler for default configuration
|
||||
self.defaults = config.get_values('settings.toml')
|
||||
# Handler for configuration
|
||||
self.settings = config.get_values('settings.toml')
|
||||
self.settings = {}
|
||||
# Handler for operators
|
||||
self.operators = config.get_values('accounts.toml', 'xmpp')['operators']
|
||||
|
||||
# self.settings = {}
|
||||
# # Populate dict handler
|
||||
# Config.add_settings_default(self.settings)
|
||||
# Config.add_settings_default(self)
|
||||
|
||||
# Handlers for connection events
|
||||
self.connection_attempts = 0
|
||||
|
@ -353,12 +355,12 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
# jid_bare = result['jid']
|
||||
# if jid_bare not in self.settings:
|
||||
# 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)
|
||||
# XmppPubsubTask.task_publish(self, jid_bare)
|
||||
bookmarks = await XmppBookmark.get_bookmarks(self)
|
||||
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
|
||||
print('POSIX sockets: Initiating IPC server...')
|
||||
self.ipc = asyncio.create_task(XmppIpcServer.ipc(self))
|
||||
|
@ -408,7 +410,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
jid_bare = message['from'].bare
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
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:
|
||||
status_type = 'dnd'
|
||||
status_message = ('Slixfeed is not designed to receive messages '
|
||||
|
@ -1308,7 +1310,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
jid_bare = session['from'].bare
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
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['instructions'] = ('Displaying information\nJabber ID {}'
|
||||
.format(jid_bare))
|
||||
|
@ -1332,42 +1334,42 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
value=unread)
|
||||
form.add_field(ftype='fixed',
|
||||
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)
|
||||
form.add_field(label='Archive',
|
||||
ftype='text-single',
|
||||
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)
|
||||
form.add_field(label='Enabled',
|
||||
ftype='text-single',
|
||||
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)
|
||||
form.add_field(label='Interval',
|
||||
ftype='text-single',
|
||||
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)
|
||||
form.add_field(label='Length',
|
||||
ftype='text-single',
|
||||
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)
|
||||
form.add_field(label='Media',
|
||||
ftype='text-single',
|
||||
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)
|
||||
form.add_field(label='Old',
|
||||
ftype='text-single',
|
||||
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)
|
||||
form.add_field(label='Quantum',
|
||||
ftype='text-single',
|
||||
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 = 60 * int(update_interval)
|
||||
last_update_time = sqlite.get_last_update_time(db_file)
|
||||
|
@ -2899,7 +2901,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
exts = values['filetype']
|
||||
for ext in exts:
|
||||
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
|
||||
url = await XmppUpload.start(
|
||||
self, jid_bare, Path(filename), encrypted=encrypted)
|
||||
|
@ -3079,7 +3081,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
form['instructions'] = ('Select a Publish-Subscribe service '
|
||||
'of which nodes you want to list.')
|
||||
# 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)
|
||||
options = form.add_field(desc='Select a PubSub service.',
|
||||
|
@ -3104,7 +3106,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
ftype='fixed',
|
||||
label='Jabber ID')
|
||||
# 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)
|
||||
for result in results + [{'jid' : self.boundjid.bare,
|
||||
|
@ -3112,7 +3114,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
jid_bare = result['jid']
|
||||
name = result['name']
|
||||
enabled_state = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'enabled')
|
||||
self, jid_bare, 'enabled')
|
||||
form.add_field(desc=jid_bare,
|
||||
ftype='boolean',
|
||||
label=name,
|
||||
|
@ -3383,9 +3385,9 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
value = values[key]
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
if jid_bare not in self.settings:
|
||||
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
||||
await Config.set_setting_value(self.settings, jid_bare,
|
||||
db_file, 'enabled', value)
|
||||
Config.add_settings_jid(self, jid_bare, db_file)
|
||||
await Config.set_setting_value(
|
||||
self, jid_bare, db_file, 'enabled', value)
|
||||
print(self.settings)
|
||||
text_note = 'Done.'
|
||||
session['has_next'] = False
|
||||
|
@ -3645,10 +3647,10 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
if XmppUtilities.is_access(self, jid_bare, jid_full, chat_type):
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
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['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 = int(value)
|
||||
if value:
|
||||
|
@ -3660,7 +3662,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
label='Enabled',
|
||||
value=value,
|
||||
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 = int(value)
|
||||
if value:
|
||||
|
@ -3672,7 +3674,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
label='Display media',
|
||||
value=value,
|
||||
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 = int(value)
|
||||
if value:
|
||||
|
@ -3686,7 +3688,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
label='Include old news',
|
||||
value=value,
|
||||
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 = int(value)
|
||||
value = value/60
|
||||
|
@ -3707,7 +3709,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
i += 6
|
||||
else:
|
||||
i += 1
|
||||
value = Config.get_setting_value(self.settings, jid_bare, 'quantum')
|
||||
value = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||
value = str(value)
|
||||
options = form.add_field(desc='Amount of items per update.',
|
||||
ftype='list-single',
|
||||
|
@ -3721,7 +3723,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
x = str(i)
|
||||
options.addOption(x, x)
|
||||
i += 1
|
||||
value = Config.get_setting_value(self.settings, jid_bare, 'archive')
|
||||
value = Config.get_setting_value(self, jid_bare, 'archive')
|
||||
value = str(value)
|
||||
options = form.add_field(desc='Number of news items to archive.',
|
||||
ftype='list-single',
|
||||
|
@ -3762,7 +3764,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
jid_bare = session['from'].bare
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
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
|
||||
values = payload['values']
|
||||
for key in values:
|
||||
|
@ -3781,7 +3783,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
if val < 1: val = 1
|
||||
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
|
||||
val == 1 and
|
||||
|
@ -3807,7 +3809,7 @@ class XmppClient(slixmpp.ClientXMPP):
|
|||
XmppPresence.send(self, jid_bare, status_message,
|
||||
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]
|
||||
|
||||
if key in ('enabled', 'media', 'old'):
|
||||
|
|
|
@ -174,10 +174,8 @@ class XmppCommands:
|
|||
# the look into function "check_updates" of module "task".
|
||||
# await action.scan(self, jid_bare, db_file, url)
|
||||
# if jid_bare not in self.settings:
|
||||
# Config.add_settings_jid(self.settings, jid_bare,
|
||||
# db_file)
|
||||
# old = Config.get_setting_value(self.settings, jid_bare,
|
||||
# 'old')
|
||||
# Config.add_settings_jid(self, jid_bare, db_file)
|
||||
# old = Config.get_setting_value(self, jid_bare, 'old')
|
||||
# if old:
|
||||
# # task.clean_tasks_xmpp_chat(self, jid_bare, ['status'])
|
||||
# # await send_status(jid)
|
||||
|
@ -234,8 +232,7 @@ class XmppCommands:
|
|||
|
||||
|
||||
def get_archive(self, jid_bare):
|
||||
result = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'archive')
|
||||
result = Config.get_setting_value(self, jid_bare, 'archive')
|
||||
message = str(result)
|
||||
return message
|
||||
|
||||
|
@ -246,10 +243,9 @@ class XmppCommands:
|
|||
if val_new > 500:
|
||||
message = 'Value may not be greater than 500.'
|
||||
else:
|
||||
val_old = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'archive')
|
||||
val_old = Config.get_setting_value(self, jid_bare, 'archive')
|
||||
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: {}).'
|
||||
.format(val_new, val_old))
|
||||
except:
|
||||
|
@ -550,8 +546,7 @@ class XmppCommands:
|
|||
|
||||
|
||||
def get_interval(self, jid_bare):
|
||||
result = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'interval')
|
||||
result = Config.get_setting_value(self, jid_bare, 'interval')
|
||||
message = str(result)
|
||||
return message
|
||||
|
||||
|
@ -559,10 +554,9 @@ class XmppCommands:
|
|||
async def set_interval(self, db_file, jid_bare, val):
|
||||
try:
|
||||
val_new = int(val)
|
||||
val_old = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'interval')
|
||||
val_old = Config.get_setting_value(self, jid_bare, 'interval')
|
||||
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 '
|
||||
'(was: {}).'.format(val_new, val_old))
|
||||
except Exception as e:
|
||||
|
@ -596,8 +590,7 @@ class XmppCommands:
|
|||
|
||||
|
||||
def get_length(self, jid_bare):
|
||||
result = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'length')
|
||||
result = Config.get_setting_value(self, jid_bare, 'length')
|
||||
result = str(result)
|
||||
return result
|
||||
|
||||
|
@ -605,10 +598,9 @@ class XmppCommands:
|
|||
async def set_length(self, db_file, jid_bare, val):
|
||||
try:
|
||||
val_new = int(val)
|
||||
val_old = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'length')
|
||||
val_old = Config.get_setting_value(self, jid_bare, 'length')
|
||||
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
|
||||
# TODO Add action to disable limit
|
||||
message = ('Summary length limit is disabled '
|
||||
|
@ -625,37 +617,37 @@ class XmppCommands:
|
|||
|
||||
|
||||
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.'
|
||||
return message
|
||||
|
||||
|
||||
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.'
|
||||
return message
|
||||
|
||||
|
||||
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.'
|
||||
return message
|
||||
|
||||
|
||||
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.'
|
||||
return message
|
||||
|
||||
|
||||
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.'
|
||||
return message
|
||||
|
||||
|
||||
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.'
|
||||
return message
|
||||
|
||||
|
@ -699,8 +691,8 @@ class XmppCommands:
|
|||
def print_options(self, jid_bare):
|
||||
message = ''
|
||||
for key in self.settings[jid_bare]:
|
||||
val = Config.get_setting_value(self.settings, jid_bare, key)
|
||||
# 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, jid_bare, key)
|
||||
steps = 11 - len(key)
|
||||
pulse = ''
|
||||
for step in range(steps):
|
||||
|
@ -710,8 +702,7 @@ class XmppCommands:
|
|||
|
||||
|
||||
def get_quantum(self, jid_bare):
|
||||
result = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'quantum')
|
||||
result = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||
message = str(result)
|
||||
return message
|
||||
|
||||
|
@ -719,14 +710,13 @@ class XmppCommands:
|
|||
async def set_quantum(self, db_file, jid_bare, val):
|
||||
try:
|
||||
val_new = int(val)
|
||||
val_old = Config.get_setting_value(
|
||||
self.settings, jid_bare, 'quantum')
|
||||
val_old = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||
# response = (
|
||||
# 'Every update will contain {} news items.'
|
||||
# ).format(response)
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
await Config.set_setting_value(self.settings, jid_bare,
|
||||
db_file, 'quantum', val_new)
|
||||
await Config.set_setting_value(
|
||||
self, jid_bare, db_file, 'quantum', val_new)
|
||||
message = ('Next update will contain {} news items (was: {}).'
|
||||
.format(val_new, val_old))
|
||||
except:
|
||||
|
@ -971,7 +961,7 @@ class XmppCommands:
|
|||
# Tasks are classes which are passed to this function
|
||||
# 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):
|
||||
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:
|
||||
callback.restart_task(self, jid_bare)
|
||||
message = 'Updates are enabled.'
|
||||
|
@ -979,8 +969,7 @@ class XmppCommands:
|
|||
|
||||
|
||||
async def scheduler_stop(self, db_file, jid_bare):
|
||||
await Config.set_setting_value(
|
||||
self.settings, jid_bare, db_file, 'enabled', 0)
|
||||
await Config.set_setting_value(self, jid_bare, db_file, 'enabled', 0)
|
||||
for task in ('interval', 'status'):
|
||||
if (jid_bare in self.task_manager and
|
||||
task in self.task_manager[jid_bare]):
|
||||
|
|
Loading…
Reference in a new issue