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