2023-12-28 15:50:23 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
1) Use loop (with gather) instead of TaskGroup.
|
|
|
|
|
|
|
|
2) Assure message delivery before calling a new task.
|
|
|
|
See https://slixmpp.readthedocs.io/en/latest/event_index.html#term-marker_acknowledged
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
3) XHTTML-IM
|
2023-12-28 15:50:23 +01:00
|
|
|
case _ if message_lowercase.startswith("html"):
|
|
|
|
message['html']="
|
|
|
|
Parse me!
|
|
|
|
"
|
|
|
|
self.send_message(
|
|
|
|
mto=jid,
|
|
|
|
mfrom=self.boundjid.bare,
|
|
|
|
mhtml=message
|
|
|
|
)
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
|
2024-02-12 10:53:49 +01:00
|
|
|
1) Extracting attribute using xmltodict.
|
2023-12-28 15:50:23 +01:00
|
|
|
import xmltodict
|
|
|
|
message = xmltodict.parse(str(message))
|
|
|
|
jid = message["message"]["x"]["@jid"]
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
# import os
|
|
|
|
from random import randrange
|
|
|
|
import slixmpp
|
|
|
|
import slixfeed.task as task
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
from slixmpp.plugins.xep_0363.http_upload import FileTooBig, HTTPError, UploadServiceNotFound
|
|
|
|
# from slixmpp.plugins.xep_0402 import BookmarkStorage, Conference
|
|
|
|
from slixmpp.plugins.xep_0048.stanza import Bookmarks
|
|
|
|
|
2024-01-04 02:16:24 +01:00
|
|
|
# import xmltodict
|
|
|
|
# import xml.etree.ElementTree as ET
|
|
|
|
# from lxml import etree
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
import slixfeed.config as config
|
|
|
|
import slixfeed.sqlite as sqlite
|
|
|
|
from slixfeed.xmpp.bookmark import XmppBookmark
|
2024-02-07 01:26:42 +01:00
|
|
|
from slixfeed.xmpp.connect import XmppConnect
|
|
|
|
from slixfeed.xmpp.muc import XmppGroupchat
|
2024-02-07 02:12:51 +01:00
|
|
|
from slixfeed.xmpp.message import XmppMessage
|
2024-01-17 15:36:28 +01:00
|
|
|
import slixfeed.xmpp.process as process
|
|
|
|
import slixfeed.xmpp.profile as profile
|
2024-02-07 01:26:42 +01:00
|
|
|
from slixfeed.xmpp.roster import XmppRoster
|
2024-02-04 18:08:12 +01:00
|
|
|
# import slixfeed.xmpp.service as service
|
2024-02-07 01:26:42 +01:00
|
|
|
from slixfeed.xmpp.presence import XmppPresence
|
|
|
|
from slixfeed.xmpp.utility import get_chat_type
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
main_task = []
|
|
|
|
jid_tasker = {}
|
|
|
|
task_manager = {}
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
# asyncio.set_event_loop(loop)
|
|
|
|
|
|
|
|
# time_now = datetime.now()
|
|
|
|
# time_now = time_now.strftime("%H:%M:%S")
|
|
|
|
|
|
|
|
# def print_time():
|
|
|
|
# # return datetime.now().strftime("%H:%M:%S")
|
|
|
|
# now = datetime.now()
|
|
|
|
# current_time = now.strftime("%H:%M:%S")
|
|
|
|
# return current_time
|
|
|
|
|
|
|
|
|
|
|
|
class Slixfeed(slixmpp.ClientXMPP):
|
|
|
|
"""
|
2024-01-26 12:34:07 +01:00
|
|
|
Slixfeed:
|
2023-12-28 15:50:23 +01:00
|
|
|
News bot that sends updates from RSS feeds.
|
|
|
|
"""
|
2024-01-24 21:28:14 +01:00
|
|
|
def __init__(self, jid, password, hostname=None, port=None, alias=None):
|
2023-12-28 15:50:23 +01:00
|
|
|
slixmpp.ClientXMPP.__init__(self, jid, password)
|
|
|
|
|
|
|
|
# NOTE
|
|
|
|
# The bot works fine when the nickname is hardcoded; or
|
|
|
|
# The bot won't join some MUCs when its nickname has brackets
|
2024-02-07 23:24:59 +01:00
|
|
|
|
|
|
|
# Handler for nickname
|
2024-01-24 19:11:39 +01:00
|
|
|
self.alias = alias
|
2024-02-07 23:24:59 +01:00
|
|
|
|
|
|
|
# Handlers for tasks
|
|
|
|
self.task_manager = {}
|
|
|
|
|
|
|
|
# Handlers for ping
|
2024-02-10 18:53:53 +01:00
|
|
|
self.task_ping_instance = {}
|
2024-02-07 23:24:59 +01:00
|
|
|
|
|
|
|
# Handlers for connection events
|
|
|
|
self.connection_attempts = 0
|
|
|
|
self.max_connection_attempts = 10
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
self.add_event_handler("session_start",
|
|
|
|
self.on_session_start)
|
|
|
|
self.add_event_handler("session_resumed",
|
|
|
|
self.on_session_resumed)
|
2023-12-28 15:50:23 +01:00
|
|
|
self.add_event_handler("got_offline", print("got_offline"))
|
|
|
|
# self.add_event_handler("got_online", self.check_readiness)
|
2024-02-04 18:08:12 +01:00
|
|
|
self.add_event_handler("changed_status",
|
|
|
|
self.on_changed_status)
|
|
|
|
self.add_event_handler("presence_available",
|
|
|
|
self.on_presence_available)
|
2024-02-10 18:53:53 +01:00
|
|
|
# self.add_event_handler("presence_unavailable",
|
|
|
|
# self.on_presence_unavailable)
|
2024-02-04 18:08:12 +01:00
|
|
|
self.add_event_handler("chatstate_active",
|
|
|
|
self.on_chatstate_active)
|
|
|
|
self.add_event_handler("chatstate_composing",
|
|
|
|
self.on_chatstate_composing)
|
|
|
|
self.add_event_handler("chatstate_gone",
|
|
|
|
self.on_chatstate_gone)
|
|
|
|
self.add_event_handler("chatstate_inactive",
|
|
|
|
self.on_chatstate_inactive)
|
|
|
|
self.add_event_handler("chatstate_paused",
|
|
|
|
self.on_chatstate_paused)
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
# The message event is triggered whenever a message
|
|
|
|
# stanza is received. Be aware that that includes
|
|
|
|
# MUC messages and error messages.
|
2024-02-04 18:08:12 +01:00
|
|
|
self.add_event_handler("message",
|
|
|
|
self.on_message)
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
self.add_event_handler("groupchat_invite",
|
|
|
|
self.on_groupchat_invite) # XEP_0045
|
|
|
|
self.add_event_handler("groupchat_direct_invite",
|
|
|
|
self.on_groupchat_direct_invite) # XEP_0249
|
2023-12-28 15:50:23 +01:00
|
|
|
# self.add_event_handler("groupchat_message", self.message)
|
|
|
|
|
|
|
|
# self.add_event_handler("disconnected", self.reconnect)
|
|
|
|
# self.add_event_handler("disconnected", self.inspect_connection)
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
self.add_event_handler("reactions",
|
|
|
|
self.on_reactions)
|
2024-02-07 02:12:51 +01:00
|
|
|
self.add_event_handler("presence_error",
|
|
|
|
self.on_presence_error)
|
2024-02-04 18:08:12 +01:00
|
|
|
self.add_event_handler("presence_subscribe",
|
|
|
|
self.on_presence_subscribe)
|
|
|
|
self.add_event_handler("presence_subscribed",
|
|
|
|
self.on_presence_subscribed)
|
|
|
|
self.add_event_handler("presence_unsubscribed",
|
|
|
|
self.on_presence_unsubscribed)
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
# Initialize event loop
|
|
|
|
# self.loop = asyncio.get_event_loop()
|
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
self.add_event_handler('connection_failed',
|
|
|
|
self.on_connection_failed)
|
|
|
|
self.add_event_handler('session_end',
|
|
|
|
self.on_session_end)
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
# TODO Test
|
2024-01-02 12:42:41 +01:00
|
|
|
async def on_groupchat_invite(self, message):
|
2024-02-04 18:08:12 +01:00
|
|
|
logging.warning("on_groupchat_invite")
|
2024-02-07 01:26:42 +01:00
|
|
|
inviter = message['from'].bare
|
2024-02-04 18:08:12 +01:00
|
|
|
muc_jid = message['groupchat_invite']['jid']
|
2024-02-06 04:04:43 +01:00
|
|
|
await XmppBookmark.add(self, muc_jid)
|
2024-02-07 01:26:42 +01:00
|
|
|
await XmppGroupchat.join(self, inviter, muc_jid)
|
2024-02-07 23:24:59 +01:00
|
|
|
message_body = ('Greetings! I am {}, the news anchor.\n'
|
2024-02-07 01:26:42 +01:00
|
|
|
'My job is to bring you the latest '
|
|
|
|
'news from sources you provide me with.\n'
|
|
|
|
'You may always reach me via xmpp:{}?message'
|
|
|
|
.format(self.alias, self.boundjid.bare))
|
|
|
|
XmppMessage.send(self, muc_jid, message_body, 'groupchat')
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
# NOTE Tested with Gajim and Psi
|
2024-01-02 12:42:41 +01:00
|
|
|
async def on_groupchat_direct_invite(self, message):
|
2024-02-07 01:26:42 +01:00
|
|
|
inviter = message['from'].bare
|
2024-02-04 18:08:12 +01:00
|
|
|
muc_jid = message['groupchat_invite']['jid']
|
2024-02-06 04:04:43 +01:00
|
|
|
await XmppBookmark.add(self, muc_jid)
|
2024-02-07 01:26:42 +01:00
|
|
|
await XmppGroupchat.join(self, inviter, muc_jid)
|
2024-02-07 23:24:59 +01:00
|
|
|
message_body = ('Greetings! I am {}, the news anchor.\n'
|
2024-02-07 01:26:42 +01:00
|
|
|
'My job is to bring you the latest '
|
|
|
|
'news from sources you provide me with.\n'
|
|
|
|
'You may always reach me via xmpp:{}?message'
|
|
|
|
.format(self.alias, self.boundjid.bare))
|
|
|
|
XmppMessage.send(self, muc_jid, message_body, 'groupchat')
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
|
2024-01-02 12:42:41 +01:00
|
|
|
async def on_session_end(self, event):
|
2024-02-07 01:26:42 +01:00
|
|
|
message = 'Session has ended.'
|
|
|
|
await XmppConnect.recover(self, message)
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def on_connection_failed(self, event):
|
2024-02-07 01:26:42 +01:00
|
|
|
message = 'Connection has failed. Reason: {}'.format(event)
|
|
|
|
await XmppConnect.recover(self, message)
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def on_session_start(self, event):
|
2024-02-06 04:04:43 +01:00
|
|
|
self.send_presence()
|
2024-02-07 01:26:42 +01:00
|
|
|
await self['xep_0115'].update_caps()
|
2024-02-06 04:04:43 +01:00
|
|
|
await self.get_roster()
|
2024-02-07 01:26:42 +01:00
|
|
|
await XmppGroupchat.autojoin(self)
|
|
|
|
profile.set_identity(self, 'client')
|
2024-01-17 15:36:28 +01:00
|
|
|
await profile.update(self)
|
2024-02-10 18:53:53 +01:00
|
|
|
task.task_ping(self)
|
2024-02-06 04:04:43 +01:00
|
|
|
|
|
|
|
# Service.commands(self)
|
|
|
|
# Service.reactions(self)
|
|
|
|
|
|
|
|
self.service_commands()
|
|
|
|
self.service_reactions()
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def on_session_resumed(self, event):
|
2024-02-06 04:04:43 +01:00
|
|
|
self.send_presence()
|
2024-02-07 01:26:42 +01:00
|
|
|
self['xep_0115'].update_caps()
|
|
|
|
await XmppGroupchat.autojoin(self)
|
|
|
|
profile.set_identity(self, 'client')
|
2024-02-06 04:04:43 +01:00
|
|
|
|
|
|
|
# Service.commands(self)
|
|
|
|
# Service.reactions(self)
|
|
|
|
|
|
|
|
self.service_commands()
|
|
|
|
self.service_reactions()
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
# TODO Request for subscription
|
|
|
|
async def on_message(self, message):
|
|
|
|
jid = message["from"].bare
|
2024-02-07 01:26:42 +01:00
|
|
|
if (await get_chat_type(self, jid) == 'chat' and
|
|
|
|
not self.client_roster[jid]['to']):
|
2024-02-08 00:41:02 +01:00
|
|
|
XmppPresence.subscription(self, jid, 'subscribe')
|
2024-02-07 01:26:42 +01:00
|
|
|
await XmppRoster.add(self, jid)
|
|
|
|
status_message = '✒️ Share online status to receive updates'
|
|
|
|
XmppPresence.send(self, jid, status_message)
|
|
|
|
message_subject = 'RSS News Bot'
|
|
|
|
message_body = 'Share online status to receive updates.'
|
|
|
|
XmppMessage.send_headline(self, jid, message_subject, message_body,
|
|
|
|
'chat')
|
2024-02-04 18:08:12 +01:00
|
|
|
await process.message(self, message)
|
2024-01-02 12:42:41 +01:00
|
|
|
# chat_type = message["type"]
|
|
|
|
# message_body = message["body"]
|
|
|
|
# message_reply = message.reply
|
|
|
|
|
|
|
|
|
|
|
|
async def on_changed_status(self, presence):
|
2024-02-04 18:08:12 +01:00
|
|
|
# await task.check_readiness(self, presence)
|
|
|
|
jid = presence['from'].bare
|
2024-02-10 18:53:53 +01:00
|
|
|
if jid in self.boundjid.bare:
|
|
|
|
return
|
2024-02-04 18:08:12 +01:00
|
|
|
if presence['show'] in ('away', 'dnd', 'xa'):
|
2024-02-07 23:24:59 +01:00
|
|
|
task.clean_tasks_xmpp(self, jid, ['interval'])
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status', 'check'])
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def on_presence_subscribe(self, presence):
|
2024-02-07 01:26:42 +01:00
|
|
|
jid = presence['from'].bare
|
|
|
|
if not self.client_roster[jid]['to']:
|
2024-02-10 18:53:53 +01:00
|
|
|
# XmppPresence.subscription(self, jid, 'subscribe')
|
2024-02-08 00:41:02 +01:00
|
|
|
XmppPresence.subscription(self, jid, 'subscribed')
|
2024-02-07 01:26:42 +01:00
|
|
|
await XmppRoster.add(self, jid)
|
|
|
|
status_message = '✒️ Share online status to receive updates'
|
|
|
|
XmppPresence.send(self, jid, status_message)
|
|
|
|
message_subject = 'RSS News Bot'
|
|
|
|
message_body = 'Share online status to receive updates.'
|
|
|
|
XmppMessage.send_headline(self, jid, message_subject, message_body,
|
|
|
|
'chat')
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-01-02 12:42:41 +01:00
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
def on_presence_subscribed(self, presence):
|
2024-02-07 01:26:42 +01:00
|
|
|
jid = presence['from'].bare
|
2024-02-10 18:53:53 +01:00
|
|
|
# XmppPresence.subscription(self, jid, 'subscribed')
|
2024-02-07 01:26:42 +01:00
|
|
|
message_subject = 'RSS News Bot'
|
2024-02-07 23:24:59 +01:00
|
|
|
message_body = ('Greetings! I am {}, the news anchor.\n'
|
2024-02-07 01:26:42 +01:00
|
|
|
'My job is to bring you the latest '
|
|
|
|
'news from sources you provide me with.\n'
|
|
|
|
'You may always reach me via xmpp:{}?message'
|
|
|
|
.format(self.alias, self.boundjid.bare))
|
|
|
|
XmppMessage.send_headline(self, jid, message_subject, message_body,
|
|
|
|
'chat')
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def on_presence_available(self, presence):
|
2024-01-22 13:48:00 +01:00
|
|
|
# TODO Add function to check whether task is already running or not
|
2024-02-04 18:08:12 +01:00
|
|
|
# await task.start_tasks(self, presence)
|
|
|
|
# NOTE Already done inside the start-task function
|
2024-02-07 01:26:42 +01:00
|
|
|
jid = presence['from'].bare
|
2024-02-10 18:53:53 +01:00
|
|
|
if jid in self.boundjid.bare:
|
|
|
|
return
|
2024-02-11 22:31:31 +01:00
|
|
|
logging.info('JID {} is available'.format(jid))
|
2024-02-07 01:26:42 +01:00
|
|
|
# FIXME TODO Find out what is the source responsible for a couple presences with empty message
|
|
|
|
# NOTE This is a temporary solution
|
|
|
|
await asyncio.sleep(10)
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid)
|
2024-02-10 18:53:53 +01:00
|
|
|
self.add_event_handler("presence_unavailable",
|
|
|
|
self.on_presence_unavailable)
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-01-02 12:42:41 +01:00
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
def on_presence_unsubscribed(self, presence):
|
2024-02-07 01:26:42 +01:00
|
|
|
jid = presence['from'].bare
|
|
|
|
message_body = 'You have been unsubscribed.'
|
2024-02-07 23:24:59 +01:00
|
|
|
# status_message = '🖋️ Subscribe to receive updates'
|
|
|
|
# status_message = None
|
2024-02-07 01:26:42 +01:00
|
|
|
XmppMessage.send(self, jid, message_body, 'chat')
|
2024-02-08 00:41:02 +01:00
|
|
|
XmppPresence.subscription(self, jid, 'unsubscribed')
|
2024-02-07 23:24:59 +01:00
|
|
|
# XmppPresence.send(self, jid, status_message,
|
|
|
|
# presence_type='unsubscribed')
|
2024-02-10 18:53:53 +01:00
|
|
|
XmppRoster.remove(self, jid)
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
def on_presence_unavailable(self, presence):
|
2024-02-07 01:26:42 +01:00
|
|
|
jid = presence['from'].bare
|
2024-02-11 22:31:31 +01:00
|
|
|
logging.info('JID {} is unavailable'.format(jid))
|
2024-02-04 18:08:12 +01:00
|
|
|
# await task.stop_tasks(self, jid)
|
2024-02-07 23:24:59 +01:00
|
|
|
task.clean_tasks_xmpp(self, jid)
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
# NOTE Albeit nice to ~have~ see, this would constantly
|
|
|
|
# send presence messages to server to no end.
|
|
|
|
status_message = 'Farewell'
|
|
|
|
XmppPresence.send(self, jid, status_message,
|
|
|
|
presence_type='unavailable')
|
|
|
|
self.del_event_handler("presence_unavailable",
|
|
|
|
self.on_presence_unavailable)
|
|
|
|
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
# TODO
|
|
|
|
# Send message that database will be deleted within 30 days
|
|
|
|
# Check whether JID is in bookmarks or roster
|
|
|
|
# If roster, remove contact JID into file
|
|
|
|
# If bookmarks, remove groupchat JID into file
|
2024-02-10 18:53:53 +01:00
|
|
|
def on_presence_error(self, presence):
|
2024-02-04 18:08:12 +01:00
|
|
|
jid = presence["from"].bare
|
2024-02-11 22:31:31 +01:00
|
|
|
logging.info('JID {} (error)'.format(jid))
|
2024-02-07 23:24:59 +01:00
|
|
|
task.clean_tasks_xmpp(self, jid)
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
def on_reactions(self, message):
|
2024-02-04 18:08:12 +01:00
|
|
|
print(message['from'])
|
|
|
|
print(message['reactions']['values'])
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def on_chatstate_active(self, message):
|
2024-02-10 18:53:53 +01:00
|
|
|
jid = message['from'].bare
|
|
|
|
if jid in self.boundjid.bare:
|
|
|
|
return
|
2024-02-04 18:08:12 +01:00
|
|
|
if message['type'] in ('chat', 'normal'):
|
2024-02-07 23:24:59 +01:00
|
|
|
# task.clean_tasks_xmpp(self, jid, ['status'])
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
|
|
|
|
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
def on_chatstate_composing(self, message):
|
2024-02-04 18:08:12 +01:00
|
|
|
if message['type'] in ('chat', 'normal'):
|
|
|
|
jid = message['from'].bare
|
2024-02-07 23:24:59 +01:00
|
|
|
# task.clean_tasks_xmpp(self, jid, ['status'])
|
2024-02-10 18:53:53 +01:00
|
|
|
status_message = ('💡 Send "help" for manual, or "info" for '
|
|
|
|
'information.')
|
2024-02-07 01:26:42 +01:00
|
|
|
XmppPresence.send(self, jid, status_message)
|
2024-01-02 12:42:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def on_chatstate_gone(self, message):
|
2024-02-10 18:53:53 +01:00
|
|
|
jid = message['from'].bare
|
|
|
|
if jid in self.boundjid.bare:
|
|
|
|
return
|
2024-02-04 18:08:12 +01:00
|
|
|
if message['type'] in ('chat', 'normal'):
|
2024-02-07 23:24:59 +01:00
|
|
|
# task.clean_tasks_xmpp(self, jid, ['status'])
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2023-12-28 15:50:23 +01:00
|
|
|
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
async def on_chatstate_inactive(self, message):
|
2024-02-10 18:53:53 +01:00
|
|
|
jid = message['from'].bare
|
|
|
|
if jid in self.boundjid.bare:
|
|
|
|
return
|
2024-02-04 18:08:12 +01:00
|
|
|
if message['type'] in ('chat', 'normal'):
|
2024-02-07 23:24:59 +01:00
|
|
|
# task.clean_tasks_xmpp(self, jid, ['status'])
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
|
|
|
|
2023-12-28 15:50:23 +01:00
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
async def on_chatstate_paused(self, message):
|
2024-02-10 18:53:53 +01:00
|
|
|
jid = message['from'].bare
|
|
|
|
if jid in self.boundjid.bare:
|
|
|
|
return
|
2024-02-04 18:08:12 +01:00
|
|
|
if message['type'] in ('chat', 'normal'):
|
2024-02-07 23:24:59 +01:00
|
|
|
# task.clean_tasks_xmpp(self, jid, ['status'])
|
2024-02-04 18:08:12 +01:00
|
|
|
await task.start_tasks_xmpp(self, jid, ['status'])
|
2024-02-06 04:04:43 +01:00
|
|
|
|
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
|
|
|
|
# NOTE Failed attempt
|
|
|
|
# Need to use Super or Inheritance or both
|
|
|
|
# self['xep_0050'].add_command(node='settings',
|
|
|
|
# name='Settings',
|
|
|
|
# handler=self._handle_settings)
|
|
|
|
# self['xep_0050'].add_command(node='subscriptions',
|
|
|
|
# name='Subscriptions',
|
|
|
|
# handler=self._handle_subscriptions)
|
|
|
|
|
|
|
|
|
|
|
|
# async def _handle_settings(self, iq, session):
|
|
|
|
# await XmppCommand._handle_settings(self, iq, session)
|
|
|
|
|
|
|
|
|
|
|
|
# async def _handle_subscriptions(self, iq, session):
|
|
|
|
# await XmppCommand._handle_subscriptions(self, iq, session)
|
|
|
|
|
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
# TODO Move class Service to a separate file
|
|
|
|
# class Service(Slixfeed):
|
|
|
|
# def __init__(self):
|
|
|
|
# super().__init__()
|
|
|
|
|
|
|
|
# TODO https://xmpp.org/extensions/xep-0115.html
|
|
|
|
# https://xmpp.org/extensions/xep-0444.html#disco
|
|
|
|
|
|
|
|
|
|
|
|
# TODO https://xmpp.org/extensions/xep-0444.html#disco-restricted
|
|
|
|
def service_reactions(self):
|
|
|
|
"""
|
|
|
|
Publish allow list of reactions.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
None.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
None.
|
|
|
|
|
|
|
|
"""
|
|
|
|
form = self['xep_0004'].make_form(
|
|
|
|
'form', 'Reactions Information'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Move class Command to a separate file
|
|
|
|
# class Command(Slixfeed):
|
|
|
|
# def __init__(self):
|
|
|
|
# super().__init__()
|
|
|
|
|
|
|
|
|
|
|
|
def service_commands(self):
|
|
|
|
# self["xep_0050"].add_command(
|
|
|
|
# node="updates_enable",
|
|
|
|
# name="Enable/Disable News Updates",
|
|
|
|
# handler=option_enable_updates,
|
|
|
|
# )
|
|
|
|
|
|
|
|
# if jid == config.get_value('accounts', 'XMPP', 'operator'):
|
|
|
|
# self['xep_0050'].add_command(node='bookmarks',
|
|
|
|
# name='Bookmarks',
|
|
|
|
# handler=self._handle_bookmarks)
|
|
|
|
# self['xep_0050'].add_command(node='roster',
|
|
|
|
# name='Roster',
|
|
|
|
# handler=self._handle_roster)
|
|
|
|
self['xep_0050'].add_command(node='settings',
|
2024-02-12 20:01:28 +01:00
|
|
|
name='Edit Settings',
|
2024-02-06 04:04:43 +01:00
|
|
|
handler=self._handle_settings)
|
2024-02-12 22:01:48 +01:00
|
|
|
self['xep_0050'].add_command(node='filters',
|
|
|
|
name='Manage Filters',
|
|
|
|
handler=self._handle_filters)
|
2024-02-06 04:04:43 +01:00
|
|
|
self['xep_0050'].add_command(node='subscriptions',
|
2024-02-12 20:01:28 +01:00
|
|
|
name='Manage subscriptions',
|
2024-02-06 04:04:43 +01:00
|
|
|
handler=self._handle_subscriptions)
|
2024-02-12 20:01:28 +01:00
|
|
|
self['xep_0050'].add_command(node='subscription',
|
|
|
|
name='View subscription',
|
|
|
|
handler=self._handle_subscription)
|
2024-02-06 04:04:43 +01:00
|
|
|
# self['xep_0050'].add_command(node='search',
|
|
|
|
# name='Search',
|
|
|
|
# handler=self._handle_search)
|
2024-02-12 22:01:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def _handle_filters(self, iq, session):
|
|
|
|
jid = session['from'].bare
|
|
|
|
jid_file = jid
|
|
|
|
db_file = config.get_pathname_to_database(jid_file)
|
|
|
|
form = self['xep_0004'].make_form('form',
|
|
|
|
'Filters for {}'.format(jid))
|
|
|
|
form['instructions'] = '🕸️ Manage filters' # 🪄️
|
|
|
|
value = await sqlite.get_filters_value(db_file, 'allow')
|
|
|
|
form.add_field(var='allow',
|
|
|
|
ftype='text-single',
|
|
|
|
label='Allow list',
|
|
|
|
value=value,
|
|
|
|
desc=('Keywords to allow (comma-separated keywords).'))
|
|
|
|
value = await sqlite.get_filters_value(db_file, 'deny')
|
|
|
|
form.add_field(var='deny',
|
|
|
|
ftype='text-single',
|
|
|
|
label='Deny list',
|
|
|
|
value=value,
|
|
|
|
desc=('Keywords to deny (comma-separated keywords).'))
|
|
|
|
session['payload'] = form
|
|
|
|
session['next'] = self._handle_filters_complete
|
|
|
|
session['has_next'] = True
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
|
|
|
async def _handle_filters_complete(self, payload, session):
|
|
|
|
"""
|
|
|
|
Process a command result from the user.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
payload -- Either a single item, such as a form, or a list
|
|
|
|
of items or forms if more than one form was
|
|
|
|
provided to the user. The payload may be any
|
|
|
|
stanza, such as jabber:x:oob for out of band
|
|
|
|
data, or jabber:x:data for typical data forms.
|
|
|
|
session -- A dictionary of data relevant to the command
|
|
|
|
session. Additional, custom data may be saved
|
|
|
|
here to persist across handler callbacks.
|
|
|
|
"""
|
|
|
|
# Text is not displayed; only labels
|
|
|
|
form = payload
|
|
|
|
|
|
|
|
jid = session['from'].bare
|
|
|
|
form = self['xep_0004'].make_form('form', 'Filters for {}'.format(jid))
|
|
|
|
form['instructions'] = ('🛡️ Filters have been updated')
|
|
|
|
jid_file = jid
|
|
|
|
db_file = config.get_pathname_to_database(jid_file)
|
|
|
|
# In this case (as is typical), the payload is a form
|
|
|
|
values = payload['values']
|
|
|
|
for value in values:
|
|
|
|
key = value
|
|
|
|
val = values[value]
|
|
|
|
# NOTE We might want to add new keywords from
|
|
|
|
# an empty form instead of editing a form.
|
|
|
|
# keywords = await sqlite.get_filters_value(db_file, key)
|
|
|
|
keywords = ''
|
|
|
|
val = await config.add_to_list(val, keywords)
|
|
|
|
if await sqlite.get_filters_value(db_file, key):
|
|
|
|
await sqlite.update_filters_value(db_file, [key, val])
|
|
|
|
else:
|
|
|
|
await sqlite.set_filters_value(db_file, [key, val])
|
|
|
|
# result = '{}: {}'.format(key, val)
|
|
|
|
form.add_field(var=key + '_title',
|
|
|
|
ftype='fixed',
|
|
|
|
value=key.capitalize() + ' Filter')
|
|
|
|
form.add_field(var=key.capitalize() + ' list',
|
|
|
|
ftype='text-single',
|
|
|
|
value=val)
|
|
|
|
session['payload'] = form
|
|
|
|
session["has_next"] = False
|
|
|
|
session['next'] = None
|
|
|
|
return session
|
2024-02-06 04:04:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def _handle_subscriptions(self, iq, session):
|
2024-02-11 22:31:31 +01:00
|
|
|
jid = session['from'].bare
|
|
|
|
form = self['xep_0004'].make_form('form',
|
|
|
|
'Subscriptions for {}'.format(jid))
|
2024-02-12 20:01:28 +01:00
|
|
|
form['instructions'] = '📰️ Manage subscriptions'
|
2024-02-06 04:04:43 +01:00
|
|
|
# form.addField(var='interval',
|
|
|
|
# ftype='text-single',
|
|
|
|
# label='Interval period')
|
|
|
|
options = form.add_field(var='subscriptions',
|
|
|
|
ftype='list-multi',
|
|
|
|
label='Select subscriptions',
|
2024-02-12 20:01:28 +01:00
|
|
|
desc='Select subscriptions to edit.')
|
2024-02-06 04:04:43 +01:00
|
|
|
jid_file = jid
|
|
|
|
db_file = config.get_pathname_to_database(jid_file)
|
|
|
|
subscriptions = await sqlite.get_feeds(db_file)
|
|
|
|
for subscription in subscriptions:
|
|
|
|
title = subscription[0]
|
|
|
|
url = subscription[1]
|
|
|
|
options.addOption(title, url)
|
|
|
|
session['payload'] = form
|
2024-02-12 20:01:28 +01:00
|
|
|
session['next'] = self._edit_subscription
|
2024-02-06 04:04:43 +01:00
|
|
|
session['has_next'] = True
|
|
|
|
# Other useful session values:
|
|
|
|
# session['to'] -- The JID that received the
|
|
|
|
# command request.
|
|
|
|
# session['from'] -- The JID that sent the
|
|
|
|
# command request.
|
|
|
|
# session['has_next'] = True -- There are more steps to complete
|
|
|
|
# session['allow_complete'] = True -- Allow user to finish immediately
|
|
|
|
# and possibly skip steps
|
|
|
|
# session['cancel'] = handler -- Assign a handler for if the user
|
|
|
|
# cancels the command.
|
|
|
|
# session['notes'] = [ -- Add informative notes about the
|
|
|
|
# ('info', 'Info message'), command's results.
|
|
|
|
# ('warning', 'Warning message'),
|
|
|
|
# ('error', 'Error message')]
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Make form for a single subscription and several subscriptions
|
|
|
|
# single: Delete, Disable, Reset and Rename
|
|
|
|
# several: Delete, Disable, Reset
|
2024-02-12 20:01:28 +01:00
|
|
|
async def _handle_subscription(self, iq, session):
|
2024-02-11 22:31:31 +01:00
|
|
|
jid = session['from'].bare
|
|
|
|
form = self['xep_0004'].make_form('form',
|
|
|
|
'Subscriptions for {}'.format(jid))
|
2024-02-12 20:01:28 +01:00
|
|
|
form['instructions'] = '📰️ View subscription properties'
|
|
|
|
# form.addField(var='interval',
|
|
|
|
# ftype='text-single',
|
|
|
|
# label='Interval period')
|
|
|
|
options = form.add_field(var='subscriptions',
|
|
|
|
ftype='list-single',
|
|
|
|
label='Select subscriptions',
|
|
|
|
desc='Select a subscription to view.')
|
|
|
|
jid_file = jid
|
|
|
|
db_file = config.get_pathname_to_database(jid_file)
|
|
|
|
subscriptions = await sqlite.get_feeds(db_file)
|
|
|
|
for subscription in subscriptions:
|
|
|
|
title = subscription[0]
|
|
|
|
url = subscription[1]
|
|
|
|
options.addOption(title, url)
|
|
|
|
session['payload'] = form
|
|
|
|
session['next'] = self._edit_subscription
|
|
|
|
session['has_next'] = True
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
|
|
|
async def _edit_subscription(self, iq, session):
|
|
|
|
jid = session['from'].bare
|
|
|
|
form = self['xep_0004'].make_form('form',
|
|
|
|
'Subscription editor'.format(jid))
|
|
|
|
form['instructions'] = '🗞️ Edit subscription: {}'.format(title)
|
2024-02-06 04:04:43 +01:00
|
|
|
options = form.add_field(var='enable',
|
|
|
|
ftype='boolean',
|
|
|
|
label='Enable',
|
|
|
|
value=True)
|
|
|
|
options = form.add_field(var='action',
|
|
|
|
ftype='list-single',
|
|
|
|
label='Action',
|
|
|
|
value='reset')
|
|
|
|
options.addOption('Delete', 'delete')
|
|
|
|
options.addOption('Reset', 'reset')
|
|
|
|
session['payload'] = form
|
|
|
|
session['next'] = None
|
|
|
|
session['has_next'] = False
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
|
|
|
async def _handle_bookmarks(self, iq, session):
|
2024-02-11 22:31:31 +01:00
|
|
|
jid = session['from'].bare
|
|
|
|
form = self['xep_0004'].make_form('form',
|
|
|
|
'Bookmarks for {}'.format(jid))
|
2024-02-12 20:01:28 +01:00
|
|
|
form['instructions'] = '📑️ Organize bookmarks'
|
2024-02-06 04:04:43 +01:00
|
|
|
options = form.add_field(var='bookmarks',
|
|
|
|
# ftype='list-multi'
|
|
|
|
ftype='list-single',
|
|
|
|
label='Select a bookmark',
|
|
|
|
desc='Select a bookmark to edit.')
|
|
|
|
conferences = await XmppBookmark.get(self)
|
|
|
|
for conference in conferences:
|
|
|
|
options.addOption(conference['jid'], conference['jid'])
|
|
|
|
session['payload'] = form
|
|
|
|
session['next'] = self._handle_command_complete
|
|
|
|
session['has_next'] = False
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
|
|
|
async def _handle_bookmarks_editor(self, iq, session):
|
2024-02-11 22:31:31 +01:00
|
|
|
jid = session['from'].bare
|
|
|
|
form = self['xep_0004'].make_form('form',
|
|
|
|
'Bookmarks for {}'.format(jid))
|
2024-02-12 20:01:28 +01:00
|
|
|
form['instructions'] = '📝️ Edit bookmarks'
|
2024-02-06 04:04:43 +01:00
|
|
|
form.addField(var='name',
|
|
|
|
ftype='text-single',
|
|
|
|
label='Name')
|
|
|
|
form.addField(var='host',
|
|
|
|
ftype='text-single',
|
|
|
|
label='Host',
|
|
|
|
required=True)
|
|
|
|
form.addField(var='room',
|
|
|
|
ftype='text-single',
|
|
|
|
label='Room',
|
|
|
|
required=True)
|
|
|
|
form.addField(var='alias',
|
|
|
|
ftype='text-single',
|
|
|
|
label='Alias')
|
|
|
|
form.addField(var='password',
|
|
|
|
ftype='text-private',
|
|
|
|
label='Password')
|
|
|
|
form.add_field(var='autojoin',
|
|
|
|
ftype='boolean',
|
|
|
|
label='Auto-join',
|
|
|
|
value=True)
|
|
|
|
options = form.add_field(var='action',
|
|
|
|
ftype='list-single',
|
|
|
|
label='Action',
|
|
|
|
value='join')
|
|
|
|
options.addOption('Add', 'add')
|
|
|
|
options.addOption('Join', 'join')
|
|
|
|
options.addOption('Remove', 'remove')
|
|
|
|
session['payload'] = form
|
|
|
|
session['next'] = None
|
|
|
|
session['has_next'] = False
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
|
|
|
async def _handle_settings(self, iq, session):
|
|
|
|
"""
|
|
|
|
Respond to the initial request for a command.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
iq -- The iq stanza containing the command request.
|
|
|
|
session -- A dictionary of data relevant to the command
|
|
|
|
session. Additional, custom data may be saved
|
|
|
|
here to persist across handler callbacks.
|
|
|
|
"""
|
|
|
|
jid = session['from'].bare
|
|
|
|
jid_file = jid
|
|
|
|
db_file = config.get_pathname_to_database(jid_file)
|
2024-02-11 22:31:31 +01:00
|
|
|
form = self['xep_0004'].make_form('form',
|
|
|
|
'Settings for {}'.format(jid))
|
2024-02-12 20:01:28 +01:00
|
|
|
form['instructions'] = ('📮️ Customize news updates')
|
2024-02-11 22:31:31 +01:00
|
|
|
|
2024-02-12 20:01:28 +01:00
|
|
|
value = config.get_setting_value(db_file, 'enabled')
|
2024-02-06 04:04:43 +01:00
|
|
|
value = int(value)
|
|
|
|
if value:
|
|
|
|
value = True
|
|
|
|
else:
|
|
|
|
value = False
|
|
|
|
form.add_field(var='enabled',
|
|
|
|
ftype='boolean',
|
|
|
|
label='Enable',
|
|
|
|
desc='Enable news updates.',
|
|
|
|
value=value)
|
2024-02-11 22:31:31 +01:00
|
|
|
|
2024-02-12 20:01:28 +01:00
|
|
|
value = config.get_setting_value(db_file, 'media')
|
2024-02-11 22:31:31 +01:00
|
|
|
value = int(value)
|
|
|
|
if value:
|
|
|
|
value = True
|
|
|
|
else:
|
|
|
|
value = False
|
|
|
|
form.add_field(var='media',
|
|
|
|
ftype='boolean',
|
|
|
|
desc='Send audio, images or videos if found.',
|
|
|
|
label='Display media',
|
|
|
|
value=value)
|
|
|
|
|
2024-02-12 20:01:28 +01:00
|
|
|
value = config.get_setting_value(db_file, 'old')
|
2024-02-06 04:04:43 +01:00
|
|
|
value = int(value)
|
|
|
|
if value:
|
|
|
|
value = True
|
2024-02-12 20:01:28 +01:00
|
|
|
else:
|
|
|
|
value = False
|
2024-02-06 04:04:43 +01:00
|
|
|
form.add_field(var='old',
|
|
|
|
ftype='boolean',
|
2024-02-11 22:31:31 +01:00
|
|
|
desc='Send old items of newly added subscriptions.',
|
2024-02-06 04:04:43 +01:00
|
|
|
# label='Send only new items',
|
|
|
|
label='Include old news',
|
|
|
|
value=value)
|
2024-02-11 22:31:31 +01:00
|
|
|
|
2024-02-12 20:01:28 +01:00
|
|
|
value = config.get_setting_value(db_file, 'interval')
|
|
|
|
value = int(value)
|
|
|
|
value = value
|
|
|
|
value = int(value)
|
|
|
|
value = str(value)
|
2024-02-06 04:04:43 +01:00
|
|
|
options = form.add_field(var='interval',
|
|
|
|
ftype='list-single',
|
|
|
|
label='Interval',
|
|
|
|
desc='Set interval update (in hours).',
|
|
|
|
value=value)
|
|
|
|
i = 60
|
|
|
|
while i <= 2880:
|
|
|
|
var = str(i)
|
|
|
|
lab = str(int(i/60))
|
|
|
|
options.addOption(lab, var)
|
2024-02-12 20:01:28 +01:00
|
|
|
if i >= 720:
|
|
|
|
i += 360
|
|
|
|
else:
|
|
|
|
i += 60
|
2024-02-11 22:31:31 +01:00
|
|
|
|
2024-02-12 20:01:28 +01:00
|
|
|
value = config.get_setting_value(db_file, 'archive')
|
2024-02-06 04:04:43 +01:00
|
|
|
value = str(value)
|
|
|
|
options = form.add_field(var='archive',
|
|
|
|
ftype='list-single',
|
|
|
|
label='Archive',
|
|
|
|
desc='Number of news items to archive.',
|
|
|
|
value=value)
|
|
|
|
i = 0
|
|
|
|
while i <= 500:
|
|
|
|
x = str(i)
|
|
|
|
options.addOption(x, x)
|
2024-02-11 22:31:31 +01:00
|
|
|
i += 50
|
|
|
|
|
2024-02-12 20:01:28 +01:00
|
|
|
value = config.get_setting_value(db_file, 'quantum')
|
2024-02-06 04:04:43 +01:00
|
|
|
value = str(value)
|
|
|
|
options = form.add_field(var='quantum',
|
|
|
|
ftype='list-single',
|
|
|
|
label='Amount',
|
|
|
|
desc='Set amount of updates per update.',
|
2024-02-12 20:01:28 +01:00
|
|
|
value=value)
|
2024-02-06 04:04:43 +01:00
|
|
|
i = 1
|
2024-02-11 22:31:31 +01:00
|
|
|
while i <= 5:
|
2024-02-06 04:04:43 +01:00
|
|
|
x = str(i)
|
|
|
|
options.addOption(x, x)
|
|
|
|
i += 1
|
2024-02-11 22:31:31 +01:00
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
session['payload'] = form
|
|
|
|
session['next'] = self._handle_settings_complete
|
|
|
|
session['has_next'] = False
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
|
|
|
async def _handle_settings_complete(self, payload, session):
|
|
|
|
"""
|
|
|
|
Process a command result from the user.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
payload -- Either a single item, such as a form, or a list
|
|
|
|
of items or forms if more than one form was
|
|
|
|
provided to the user. The payload may be any
|
|
|
|
stanza, such as jabber:x:oob for out of band
|
|
|
|
data, or jabber:x:data for typical data forms.
|
|
|
|
session -- A dictionary of data relevant to the command
|
|
|
|
session. Additional, custom data may be saved
|
|
|
|
here to persist across handler callbacks.
|
|
|
|
"""
|
2024-02-12 20:01:28 +01:00
|
|
|
# This looks nice in Gajim, though there are dropdown menues
|
|
|
|
# form = payload
|
2024-02-06 04:04:43 +01:00
|
|
|
|
|
|
|
jid = session['from'].bare
|
2024-02-12 20:01:28 +01:00
|
|
|
form = self['xep_0004'].make_form('form',
|
|
|
|
'Settings for {}'.format(jid))
|
|
|
|
form['instructions'] = ('🛡️ Settings have beem saved')
|
|
|
|
|
2024-02-06 04:04:43 +01:00
|
|
|
jid_file = jid
|
|
|
|
db_file = config.get_pathname_to_database(jid_file)
|
|
|
|
# In this case (as is typical), the payload is a form
|
2024-02-12 20:01:28 +01:00
|
|
|
values = payload['values']
|
2024-02-06 04:04:43 +01:00
|
|
|
for value in values:
|
|
|
|
key = value
|
|
|
|
val = values[value]
|
2024-02-12 20:01:28 +01:00
|
|
|
|
|
|
|
if key == 'interval':
|
|
|
|
val = int(val)
|
|
|
|
if val < 60:
|
|
|
|
val = 90
|
|
|
|
|
2024-02-11 22:31:31 +01:00
|
|
|
if sqlite.get_settings_value(db_file, key):
|
2024-02-06 04:04:43 +01:00
|
|
|
await sqlite.update_settings_value(db_file, [key, val])
|
|
|
|
else:
|
|
|
|
await sqlite.set_settings_value(db_file, [key, val])
|
2024-02-12 20:01:28 +01:00
|
|
|
|
|
|
|
val = sqlite.get_settings_value(db_file, key)
|
|
|
|
if key in ('enabled', 'media', 'old'):
|
|
|
|
if val == '1':
|
|
|
|
val = 'Yes'
|
|
|
|
elif val == '0':
|
|
|
|
val = 'No'
|
|
|
|
|
|
|
|
if key == 'interval':
|
|
|
|
val = int(val)
|
|
|
|
val = val/60
|
|
|
|
val = int(val)
|
|
|
|
val = str(val)
|
|
|
|
|
|
|
|
# match value:
|
|
|
|
# case 'enabled':
|
|
|
|
# pass
|
|
|
|
# case 'interval':
|
|
|
|
# pass
|
|
|
|
|
|
|
|
result = '{}: {}'.format(key.capitalize(), val)
|
|
|
|
|
|
|
|
form.add_field(var=key,
|
|
|
|
ftype='fixed',
|
|
|
|
value=result)
|
|
|
|
session['payload'] = form # Comment when this is fixed in Gajim
|
|
|
|
session["has_next"] = False
|
2024-02-06 04:04:43 +01:00
|
|
|
session['next'] = None
|
2024-02-12 20:01:28 +01:00
|
|
|
# return session
|