forked from sch/Slixfeed
Enable usage of private chat on groupchat
This commit is contained in:
parent
4406e61fbe
commit
9094921b40
8 changed files with 414 additions and 371 deletions
|
@ -252,14 +252,14 @@ def get_default_config_directory():
|
|||
return os.path.join(config_home, 'slixfeed')
|
||||
|
||||
|
||||
def get_pathname_to_database(jid):
|
||||
def get_pathname_to_database(jid_file):
|
||||
"""
|
||||
Callback function to instantiate action on database.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
jid : str
|
||||
Jabber ID.
|
||||
jid_file : str
|
||||
Filename.
|
||||
callback : ?
|
||||
Function name.
|
||||
message : str, optional
|
||||
|
@ -276,7 +276,7 @@ def get_pathname_to_database(jid):
|
|||
os.mkdir(db_dir)
|
||||
if not os.path.isdir(db_dir + "/sqlite"):
|
||||
os.mkdir(db_dir + "/sqlite")
|
||||
db_file = os.path.join(db_dir, "sqlite", r"{}.db".format(jid))
|
||||
db_file = os.path.join(db_dir, "sqlite", r"{}.db".format(jid_file))
|
||||
sqlite.create_tables(db_file)
|
||||
return db_file
|
||||
# await set_default_values(db_file)
|
||||
|
|
|
@ -103,7 +103,8 @@ async def start_tasks_xmpp(self, jid, tasks):
|
|||
task_manager[jid]["status"] = asyncio.create_task(
|
||||
send_status(self, jid))
|
||||
case "interval":
|
||||
db_file = get_pathname_to_database(jid)
|
||||
jid_file = jid.replace('/', '_')
|
||||
db_file = get_pathname_to_database(jid_file)
|
||||
update_interval = (
|
||||
await get_settings_value(db_file, "interval") or
|
||||
get_value("settings", "Settings", "interval")
|
||||
|
@ -176,7 +177,8 @@ async def task_jid(self, jid):
|
|||
jid : str
|
||||
Jabber ID.
|
||||
"""
|
||||
db_file = get_pathname_to_database(jid)
|
||||
jid_file = jid.replace('/', '_')
|
||||
db_file = get_pathname_to_database(jid_file)
|
||||
enabled = (
|
||||
await get_settings_value(db_file, "enabled") or
|
||||
get_value("settings", "Settings", "enabled")
|
||||
|
@ -229,7 +231,8 @@ async def send_update(self, jid, num=None):
|
|||
Number. The default is None.
|
||||
"""
|
||||
logging.debug("Sending a news update to JID {}".format(jid))
|
||||
db_file = get_pathname_to_database(jid)
|
||||
jid_file = jid.replace('/', '_')
|
||||
db_file = get_pathname_to_database(jid_file)
|
||||
enabled = (
|
||||
await get_settings_value(db_file, "enabled") or
|
||||
get_value("settings", "Settings", "enabled")
|
||||
|
@ -246,7 +249,7 @@ async def send_update(self, jid, num=None):
|
|||
results = await get_unread_entries(db_file, num)
|
||||
news_digest = ''
|
||||
media = None
|
||||
chat_type = await utility.jid_type(self, jid)
|
||||
chat_type = await utility.get_chat_type(self, jid)
|
||||
for result in results:
|
||||
ix = result[0]
|
||||
title_e = result[1]
|
||||
|
@ -356,7 +359,8 @@ async def send_status(self, jid):
|
|||
logging.debug(
|
||||
"Sending a status message to JID {}".format(jid))
|
||||
status_text = "📜️ Slixfeed RSS News Bot"
|
||||
db_file = get_pathname_to_database(jid)
|
||||
jid_file = jid.replace('/', '_')
|
||||
db_file = get_pathname_to_database(jid_file)
|
||||
enabled = (
|
||||
await get_settings_value(db_file, "enabled") or
|
||||
get_value("settings", "Settings", "enabled")
|
||||
|
@ -426,7 +430,8 @@ async def refresh_task(self, jid, callback, key, val=None):
|
|||
"Refreshing task {} for JID {}".format(callback, jid)
|
||||
)
|
||||
if not val:
|
||||
db_file = get_pathname_to_database(jid)
|
||||
jid_file = jid.replace('/', '_')
|
||||
db_file = get_pathname_to_database(jid_file)
|
||||
val = (
|
||||
await get_settings_value(db_file, key) or
|
||||
get_value("settings", "Settings", key)
|
||||
|
@ -481,7 +486,8 @@ async def check_updates(jid):
|
|||
"Scanning for updates for JID {}".format(jid)
|
||||
)
|
||||
while True:
|
||||
db_file = get_pathname_to_database(jid)
|
||||
jid_file = jid.replace('/', '_')
|
||||
db_file = get_pathname_to_database(jid_file)
|
||||
urls = await get_feeds_url(db_file)
|
||||
for url in urls:
|
||||
await action.scan(db_file, url)
|
||||
|
|
|
@ -7,11 +7,11 @@ from slixmpp.plugins.xep_0048.stanza import Bookmarks
|
|||
|
||||
async def add(self, muc_jid):
|
||||
result = await self.plugin['xep_0048'].get_bookmarks()
|
||||
bookmarks = result["private"]["bookmarks"]
|
||||
conferences = bookmarks["conferences"]
|
||||
bookmarks = result['private']['bookmarks']
|
||||
conferences = bookmarks['conferences']
|
||||
mucs = []
|
||||
for conference in conferences:
|
||||
jid = conference["jid"]
|
||||
jid = conference['jid']
|
||||
mucs.extend([jid])
|
||||
if muc_jid not in mucs:
|
||||
bookmarks = Bookmarks()
|
||||
|
@ -34,18 +34,18 @@ async def add(self, muc_jid):
|
|||
|
||||
async def get(self):
|
||||
result = await self.plugin['xep_0048'].get_bookmarks()
|
||||
bookmarks = result["private"]["bookmarks"]
|
||||
conferences = bookmarks["conferences"]
|
||||
bookmarks = result['private']['bookmarks']
|
||||
conferences = bookmarks['conferences']
|
||||
return conferences
|
||||
|
||||
|
||||
async def remove(self, muc_jid):
|
||||
result = await self.plugin['xep_0048'].get_bookmarks()
|
||||
bookmarks = result["private"]["bookmarks"]
|
||||
conferences = bookmarks["conferences"]
|
||||
bookmarks = result['private']['bookmarks']
|
||||
conferences = bookmarks['conferences']
|
||||
mucs = []
|
||||
for conference in conferences:
|
||||
jid = conference["jid"]
|
||||
jid = conference['jid']
|
||||
mucs.extend([jid])
|
||||
if muc_jid in mucs:
|
||||
bookmarks = Bookmarks()
|
||||
|
|
|
@ -165,7 +165,10 @@ class Slixfeed(slixmpp.ClientXMPP):
|
|||
|
||||
|
||||
async def on_session_end(self, event):
|
||||
message = "Session has ended. Reason: {}".format(event)
|
||||
if event:
|
||||
message = "Session has ended. Reason: {}".format(event)
|
||||
else:
|
||||
message = "Session has ended."
|
||||
await connect.recover_connection(self, event, message)
|
||||
|
||||
|
||||
|
@ -189,7 +192,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
|||
# TODO Request for subscription
|
||||
async def on_message(self, message):
|
||||
jid = message["from"].bare
|
||||
if "chat" == await utility.jid_type(self, jid):
|
||||
if "chat" == await utility.get_chat_type(self, jid):
|
||||
await roster.add(self, jid)
|
||||
await state.request(self, jid)
|
||||
# chat_type = message["type"]
|
||||
|
|
|
@ -150,7 +150,10 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
|||
|
||||
|
||||
async def on_session_end(self, event):
|
||||
message = "Session has ended. Reason: {}".format(event)
|
||||
if event:
|
||||
message = "Session has ended. Reason: {}".format(event)
|
||||
else:
|
||||
message = "Session has ended."
|
||||
await connect.recover_connection(self, event, message)
|
||||
|
||||
|
||||
|
@ -173,10 +176,8 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
|||
|
||||
# TODO Request for subscription
|
||||
async def on_message(self, message):
|
||||
# print(message)
|
||||
# breakpoint()
|
||||
jid = message["from"].bare
|
||||
# if "chat" == await utility.jid_type(self, jid):
|
||||
# jid = message["from"].bare
|
||||
# if "chat" == await utility.get_chat_type(self, jid):
|
||||
# await roster.add(self, jid)
|
||||
# await state.request(self, jid)
|
||||
# chat_type = message["type"]
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -44,7 +44,7 @@ async def add(self, jid):
|
|||
-------
|
||||
None.
|
||||
"""
|
||||
if await utility.jid_type(self, jid) == "groupchat":
|
||||
if await utility.get_chat_type(self, jid) == "groupchat":
|
||||
# Check whether JID is in bookmarks; otherwise, add it.
|
||||
print(jid, "is muc")
|
||||
return
|
||||
|
|
|
@ -5,10 +5,18 @@ from slixmpp.exceptions import IqTimeout
|
|||
import logging
|
||||
|
||||
|
||||
async def jid_type(self, jid):
|
||||
async def get_chat_type(self, jid):
|
||||
"""
|
||||
Check whether a JID is of MUC.
|
||||
|
||||
If iqresult["disco_info"]["features"] contains XML namespace
|
||||
of 'http://jabber.org/protocol/muc', then it is a "groupchat".
|
||||
|
||||
Unless it has forward slash, which would indicate that it is
|
||||
a chat which is conducted through a groupchat.
|
||||
|
||||
Otherwise, determine type "chat".
|
||||
|
||||
Parameters
|
||||
----------
|
||||
jid : str
|
||||
|
@ -16,7 +24,7 @@ async def jid_type(self, jid):
|
|||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
chat_type : str
|
||||
"chat" or "groupchat.
|
||||
"""
|
||||
try:
|
||||
|
@ -25,12 +33,14 @@ async def jid_type(self, jid):
|
|||
# identity = iqresult['disco_info']['identities']
|
||||
# if 'account' in indentity:
|
||||
# if 'conference' in indentity:
|
||||
if 'http://jabber.org/protocol/muc' in features:
|
||||
return "groupchat"
|
||||
if ('http://jabber.org/protocol/muc' in features) and not ('/' in jid):
|
||||
chat_type = "groupchat"
|
||||
# TODO elif <feature var='jabber:iq:gateway'/>
|
||||
# NOTE Is it needed? We do not interact with gateways or services
|
||||
else:
|
||||
return "chat"
|
||||
chat_type = "chat"
|
||||
print('JID {} chat type is {}'.format(jid, chat_type))
|
||||
return chat_type
|
||||
# TODO Test whether this exception is realized
|
||||
except IqTimeout as e:
|
||||
messages = [
|
||||
|
|
Loading…
Reference in a new issue