forked from sch/Slixfeed
Add functionality profile
This commit is contained in:
parent
80e49a8d38
commit
6a7d99f1a2
10 changed files with 139 additions and 13 deletions
|
@ -2,12 +2,30 @@
|
|||
# and also from which accounts it receives instructions.
|
||||
|
||||
[XMPP]
|
||||
nickname =
|
||||
nickname = Slixfeed
|
||||
username =
|
||||
password =
|
||||
# port = 5347
|
||||
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]
|
||||
# Not yet implemented
|
||||
username =
|
||||
|
|
1
assets/image.svg
Normal file
1
assets/image.svg
Normal 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 |
|
@ -111,10 +111,13 @@ class Jabber:
|
|||
xmpp.register_plugin('xep_0030') # Service Discovery
|
||||
xmpp.register_plugin('xep_0045') # Multi-User Chat
|
||||
xmpp.register_plugin('xep_0048') # Bookmarks
|
||||
xmpp.register_plugin('xep_0054') # vcard-temp
|
||||
xmpp.register_plugin('xep_0060') # Publish-Subscribe
|
||||
# xmpp.register_plugin('xep_0065') # SOCKS5 Bytestreams
|
||||
xmpp.register_plugin('xep_0066') # Out of Band Data
|
||||
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_0249') # Multi-User Chat
|
||||
xmpp.register_plugin('xep_0363') # HTTP File Upload
|
||||
|
|
|
@ -442,7 +442,10 @@ async def add_feed(db_file, url):
|
|||
encoding = ''
|
||||
if "updated_parsed" in feed["feed"].keys():
|
||||
updated = feed["feed"]["updated_parsed"]
|
||||
try:
|
||||
updated = convert_struct_time_to_iso8601(updated)
|
||||
except:
|
||||
updated = ''
|
||||
else:
|
||||
updated = ''
|
||||
version = feed["version"]
|
||||
|
@ -668,7 +671,10 @@ async def scan(db_file, url):
|
|||
db_file, feed_id, valid)
|
||||
if "updated_parsed" in feed["feed"].keys():
|
||||
updated = feed["feed"]["updated_parsed"]
|
||||
try:
|
||||
updated = convert_struct_time_to_iso8601(updated)
|
||||
except:
|
||||
updated = ''
|
||||
else:
|
||||
updated = ''
|
||||
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.")
|
||||
tree = html.fromstring(content)
|
||||
# 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):
|
||||
image = images[0]
|
||||
image = str(image)
|
||||
|
|
|
@ -15,6 +15,8 @@ TODO
|
|||
|
||||
4) Copy file from /etc/slixfeed/ or /usr/share/slixfeed/
|
||||
|
||||
5) Merge get_value_default into get_value.
|
||||
|
||||
"""
|
||||
|
||||
import configparser
|
||||
|
|
|
@ -61,8 +61,9 @@ from slixmpp.plugins.xep_0048.stanza import Bookmarks
|
|||
# from lxml import etree
|
||||
|
||||
import slixfeed.xmpp.connect as connect
|
||||
import slixfeed.xmpp.process as process
|
||||
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.state as state
|
||||
import slixfeed.xmpp.status as status
|
||||
|
@ -169,6 +170,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
|||
async def on_session_start(self, event):
|
||||
await process.event(self, event)
|
||||
await muc.autojoin(self, event)
|
||||
await profile.update(self)
|
||||
|
||||
|
||||
async def on_session_resumed(self, event):
|
||||
|
|
|
@ -352,7 +352,8 @@ async def message(self, message):
|
|||
response = "Missing value."
|
||||
send_reply_message(self, message, response)
|
||||
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:]
|
||||
await bookmark.remove(self, muc_jid)
|
||||
response = (
|
||||
|
|
72
slixfeed/xmpp/profile.py
Normal file
72
slixfeed/xmpp/profile.py
Normal 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)
|
||||
|
|
@ -7,7 +7,8 @@ https://codeberg.org/poezio/slixmpp/src/branch/master/examples/http_upload.py
|
|||
"""
|
||||
|
||||
import logging
|
||||
from slixmpp.exceptions import IqTimeout
|
||||
from slixmpp.exceptions import IqTimeout, IqError
|
||||
from slixmpp.plugins.xep_0363.http_upload import HTTPError
|
||||
# import sys
|
||||
|
||||
|
||||
|
@ -25,11 +26,23 @@ async def start(self, jid, filename, domain=None):
|
|||
# return
|
||||
# elif self.encrypted:
|
||||
# upload_file = self['xep_0454'].upload_file
|
||||
try:
|
||||
url = await upload_file(
|
||||
filename, domain, timeout=10,
|
||||
)
|
||||
except IqTimeout:
|
||||
raise TimeoutError('Could not send message in time')
|
||||
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:
|
||||
raise TimeoutError('Could not send message in time')
|
||||
return url
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
from slixmpp.exceptions import IqTimeout
|
||||
import logging
|
||||
|
||||
|
||||
async def jid_type(self, jid):
|
||||
"""
|
||||
Check whether a JID is of MUC.
|
||||
|
|
Loading…
Reference in a new issue