Slixfeed/slixfeed/xmpp/profile.py
Schimon Jehudah b1a1955545 Replace configuration file INI by TOML.
Fix ping functionality when activated as component (thank you Guus and MattJ).
Add initial code for XEP-0060: Publish-Subscribe.
Fix case-sensitivity with setting keys sent in-chat-command (Thank you mirux)
2024-03-12 17:13:01 +00:00

97 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 Config
import slixfeed.config as config
# from slixmpp.exceptions import IqTimeout, IqError
# import logging
import os
# class XmppProfile:
async def update(self):
"""
Update profile.
"""
await set_vcard(self)
await set_avatar(self)
async def set_avatar(self):
config_dir = config.get_default_config_directory()
if not os.path.isdir(config_dir):
config_dir = '/usr/share/slixfeed/'
filename = glob.glob(config_dir + '/image.*')
if not filename and os.path.isdir('/usr/share/slixfeed/'):
# filename = '/usr/share/slixfeed/image.svg'
filename = glob.glob('/usr/share/slixfeed/image.*')
if not filename:
config_dir = os.path.dirname(__file__)
config_dir = config_dir.split('/')
config_dir.pop()
config_dir = '/'.join(config_dir)
filename = glob.glob(config_dir + '/assets/image.*')
if len(filename):
filename = filename[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)
def set_identity(self, category):
"""
Identify for Service Descovery.
Parameters
----------
category : str
"client" or "service".
Returns
-------
None.
"""
self['xep_0030'].add_identity(
category=category,
itype='news',
name='slixfeed',
node=None,
jid=self.boundjid.full,
)
async def set_vcard(self):
vcard = self.plugin['xep_0054'].make_vcard()
profile = config.get_values('accounts.toml', 'xmpp')['profile']
for key in profile:
vcard[key] = profile[key]
await self.plugin['xep_0054'].publish_vcard(vcard)