Add functionality profile

This commit is contained in:
Schimon Jehudah 2024-01-17 14:36:28 +00:00
parent 80e49a8d38
commit 6a7d99f1a2
10 changed files with 139 additions and 13 deletions

View file

@ -2,12 +2,30 @@
# and also from which accounts it receives instructions. # and also from which accounts it receives instructions.
[XMPP] [XMPP]
nickname = nickname = Slixfeed
username = username =
password = password =
# port = 5347
operator = operator =
[XMPP Profile]
name = Slixfeed
nickname = Slixfeed
role = Syndication News Bot
organization = RSS Task Force
url = https://gitgud.io/sjehuda/slixfeed
description = This is an XMPP syndication news bot. It supports Atom, JSON, RDF and RSS feeds.
note = This is a news bot powered by Slixfeed
birthday = 21 June 2022
[XMPP Connect]
port = 5347
proxy_host = 127.0.0.1
proxy_port = 9050
proxy_username =
proxy_password =
proxy_enabled = 1
reconnect_timeout = 30
[ActivityPub] [ActivityPub]
# Not yet implemented # Not yet implemented
username = username =

1
assets/image.svg Normal file
View file

@ -0,0 +1 @@
<svg height="600" width="600" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="M167 406a60 60 0 1 1-120 0 60 60 0 0 1 120 0zm0 0" style="fill:#ffa000" transform="translate(44 44)"/><path d="M47 186v80c110 0 199 89 199 199h80c0-154-125-279-279-279zm0 0" style="fill:#ffa000" transform="translate(44 44)"/><path d="M47 47v79c187 0 338 152 338 339h80C465 234 277 47 47 47Zm0 0" style="fill:#ffa000" transform="translate(44 44)"/></svg>

After

Width:  |  Height:  |  Size: 448 B

View file

@ -111,10 +111,13 @@ class Jabber:
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0045') # Multi-User Chat xmpp.register_plugin('xep_0045') # Multi-User Chat
xmpp.register_plugin('xep_0048') # Bookmarks xmpp.register_plugin('xep_0048') # Bookmarks
xmpp.register_plugin('xep_0054') # vcard-temp
xmpp.register_plugin('xep_0060') # Publish-Subscribe xmpp.register_plugin('xep_0060') # Publish-Subscribe
# xmpp.register_plugin('xep_0065') # SOCKS5 Bytestreams # xmpp.register_plugin('xep_0065') # SOCKS5 Bytestreams
xmpp.register_plugin('xep_0066') # Out of Band Data xmpp.register_plugin('xep_0066') # Out of Band Data
xmpp.register_plugin('xep_0071') # XHTML-IM xmpp.register_plugin('xep_0071') # XHTML-IM
xmpp.register_plugin('xep_0084') # User Avatar
xmpp.register_plugin('xep_0153') # vCard-Based Avatars
xmpp.register_plugin('xep_0199', {'keepalive': True}) # XMPP Ping xmpp.register_plugin('xep_0199', {'keepalive': True}) # XMPP Ping
xmpp.register_plugin('xep_0249') # Multi-User Chat xmpp.register_plugin('xep_0249') # Multi-User Chat
xmpp.register_plugin('xep_0363') # HTTP File Upload xmpp.register_plugin('xep_0363') # HTTP File Upload

View file

@ -442,7 +442,10 @@ async def add_feed(db_file, url):
encoding = '' encoding = ''
if "updated_parsed" in feed["feed"].keys(): if "updated_parsed" in feed["feed"].keys():
updated = feed["feed"]["updated_parsed"] updated = feed["feed"]["updated_parsed"]
updated = convert_struct_time_to_iso8601(updated) try:
updated = convert_struct_time_to_iso8601(updated)
except:
updated = ''
else: else:
updated = '' updated = ''
version = feed["version"] version = feed["version"]
@ -668,7 +671,10 @@ async def scan(db_file, url):
db_file, feed_id, valid) db_file, feed_id, valid)
if "updated_parsed" in feed["feed"].keys(): if "updated_parsed" in feed["feed"].keys():
updated = feed["feed"]["updated_parsed"] updated = feed["feed"]["updated_parsed"]
updated = convert_struct_time_to_iso8601(updated) try:
updated = convert_struct_time_to_iso8601(updated)
except:
updated = ''
else: else:
updated = '' updated = ''
feed_id = await sqlite.get_feed_id(db_file, url) feed_id = await sqlite.get_feed_id(db_file, url)
@ -855,7 +861,14 @@ async def extract_image_from_html(url):
"Check that package readability is installed.") "Check that package readability is installed.")
tree = html.fromstring(content) tree = html.fromstring(content)
# TODO Exclude banners, class="share" links etc. # TODO Exclude banners, class="share" links etc.
images = tree.xpath('//img/@src') images = tree.xpath(
'//img[not('
'contains(@src, "avatar") or '
'contains(@src, "emoji") or '
'contains(@src, "icon") or '
'contains(@src, "logo") or '
'contains(@src, "smiley")'
')]/@src')
if len(images): if len(images):
image = images[0] image = images[0]
image = str(image) image = str(image)

View file

@ -15,6 +15,8 @@ TODO
4) Copy file from /etc/slixfeed/ or /usr/share/slixfeed/ 4) Copy file from /etc/slixfeed/ or /usr/share/slixfeed/
5) Merge get_value_default into get_value.
""" """
import configparser import configparser

View file

@ -61,8 +61,9 @@ from slixmpp.plugins.xep_0048.stanza import Bookmarks
# from lxml import etree # from lxml import etree
import slixfeed.xmpp.connect as connect import slixfeed.xmpp.connect as connect
import slixfeed.xmpp.process as process
import slixfeed.xmpp.muc as muc import slixfeed.xmpp.muc as muc
import slixfeed.xmpp.process as process
import slixfeed.xmpp.profile as profile
import slixfeed.xmpp.roster as roster import slixfeed.xmpp.roster as roster
import slixfeed.xmpp.state as state import slixfeed.xmpp.state as state
import slixfeed.xmpp.status as status import slixfeed.xmpp.status as status
@ -169,6 +170,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def on_session_start(self, event): async def on_session_start(self, event):
await process.event(self, event) await process.event(self, event)
await muc.autojoin(self, event) await muc.autojoin(self, event)
await profile.update(self)
async def on_session_resumed(self, event): async def on_session_resumed(self, event):

View file

@ -352,7 +352,8 @@ async def message(self, message):
response = "Missing value." response = "Missing value."
send_reply_message(self, message, response) send_reply_message(self, message, response)
case _ if message_lowercase.startswith("bookmark -"): case _ if message_lowercase.startswith("bookmark -"):
if jid == get_value("accounts", "XMPP", "operator"): if jid == get_value(
"accounts", "XMPP", "operator"):
muc_jid = message_text[11:] muc_jid = message_text[11:]
await bookmark.remove(self, muc_jid) await bookmark.remove(self, muc_jid)
response = ( response = (

72
slixfeed/xmpp/profile.py Normal file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
NOTE
The VCard XML fields that can be set are as follows:
FN, NICKNAME, URL, BDAY, ROLE, NOTE, MAILER,
TZ, REV, UID, DESC, TITLE, PRODID, SORT-STRING,
N, ADR, TEL, EMAIL, JABBERID, ORG, CATEGORIES,
NOTE, PRODID, REV, SORT-STRING, SOUND, UID, URL,
CLASS, KEY, MAILER, GEO, TITLE, ROLE,
LOGO, AGENT
TODO
1) Test XEP-0084.
2) Make sure to support all type of servers.
3) Catch IqError
ERROR:slixmpp.basexmpp:internal-server-error: Database failure
WARNING:slixmpp.basexmpp:You should catch IqError exceptions
"""
import glob
from slixfeed.config import get_value, get_default_config_directory
# from slixmpp.exceptions import IqTimeout, IqError
# import logging
import os
async def update(self):
"""
Update profile.
"""
await set_vcard(self)
await set_avatar(self)
async def set_avatar(self):
config_dir = get_default_config_directory()
if not os.path.isdir(config_dir):
config_dir = '/usr/share/slixfeed/'
filename = glob.glob(config_dir + "/image.*")[0]
image_file = os.path.join(config_dir, filename)
with open(image_file, "rb") as avatar_file:
avatar = avatar_file.read()
# await self.plugin["xep_0084"].publish_avatar(avatar)
await self.plugin["xep_0153"].set_avatar(avatar=avatar)
async def set_vcard(self):
vcard = self.plugin["xep_0054"].make_vcard()
fields = {
"BDAY": "birthday",
"DESC": "description",
"FN": "name",
"NICKNAME": "nickname",
"NOTE": "note",
"ORG": "organization",
"ROLE": "role",
"TITLE": "title",
"URL": "url",
}
for key in fields:
vcard[key] = get_value(
"accounts", "XMPP Profile", fields[key])
await self.plugin["xep_0054"].publish_vcard(vcard)

View file

@ -7,7 +7,8 @@ https://codeberg.org/poezio/slixmpp/src/branch/master/examples/http_upload.py
""" """
import logging import logging
from slixmpp.exceptions import IqTimeout from slixmpp.exceptions import IqTimeout, IqError
from slixmpp.plugins.xep_0363.http_upload import HTTPError
# import sys # import sys
@ -25,11 +26,23 @@ async def start(self, jid, filename, domain=None):
# return # return
# elif self.encrypted: # elif self.encrypted:
# upload_file = self['xep_0454'].upload_file # upload_file = self['xep_0454'].upload_file
url = await upload_file( try:
filename, domain, timeout=10, url = await upload_file(
) filename, domain, timeout=10,
)
logging.info('Upload successful!')
logging.info('Sending file to %s', jid)
except HTTPError:
url = (
"Error: It appears that this server doesn't support "
"HTTP File Upload."
)
logging.error(
"It appears that this server doesn't support HTTP File Upload."
)
# raise HTTPError(
# "This server doesn't appear to support HTTP File Upload"
# )
except IqTimeout: except IqTimeout:
raise TimeoutError('Could not send message in time') raise TimeoutError('Could not send message in time')
logging.info('Upload successful!')
logging.info('Sending file to %s', jid)
return url return url

View file

@ -4,6 +4,7 @@
from slixmpp.exceptions import IqTimeout from slixmpp.exceptions import IqTimeout
import logging import logging
async def jid_type(self, jid): async def jid_type(self, jid):
""" """
Check whether a JID is of MUC. Check whether a JID is of MUC.