diff --git a/bot.py b/bot.py index 7748e97..4c1b7ef 100644 --- a/bot.py +++ b/bot.py @@ -174,6 +174,49 @@ class QBBot(slixmpp.ClientXMPP): await self.get_roster() self.send_presence() self.plugin['xep_0045'].join_muc(self.room, self.nick) + avatar_file = "./qbittorrent_logo.png" + try: + avatar_file = open(avatar_file, 'rb') + except IOError: + logging.error("Could not find avatar file") + return self.disconnect() + + avatar = avatar_file.read() + avatar_type = 'image/png' + avatar_id = self['xep_0084'].generate_id(avatar) + avatar_bytes = len(avatar) + avatar_file.close() + + used_xep84 = False + + logging.info('Publish XEP-0084 avatar data') + result = await self['xep_0084'].publish_avatar(avatar) + if isinstance(result, slixmpp.exceptions.XMPPError): + logging.warning('Could not publish XEP-0084 avatar') + else: + used_xep84 = True + + logging.info('Update vCard with avatar') + result = await self['xep_0153'].set_avatar(avatar=avatar, mtype=avatar_type) + if isinstance(result, slixmpp.exceptions.XMPPError): + print('Could not set vCard avatar') + + if used_xep84: + logging.info('Advertise XEP-0084 avatar metadata') + result = await self['xep_0084'].publish_avatar_metadata([ + {'id': avatar_id, + 'type': avatar_type, + 'bytes': avatar_bytes} + # We could advertise multiple avatars to provide + # options in image type, source (HTTP vs pubsub), + # size, etc. + # {'id': ....} + ]) + if isinstance(result, slixmpp.exceptions.XMPPError): + logging.warning('Could not publish XEP-0084 metadata') + + logging.info('Wait for presence updates to propagate...') + #self.schedule('end', 5, self.disconnect, kwargs={'wait': True}) # Most get_*/set_* methods from plugins use Iq stanzas, which # are sent asynchronously. You can almost always provide a @@ -265,5 +308,7 @@ if __name__ == '__main__': xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0045') # Multi-User Chat xmpp.register_plugin('xep_0199') # XMPP Ping + xmpp.register_plugin('xep_0084') # vCard avatar + xmpp.register_plugin('xep_0153') # Something required for vCard xmpp.connect() xmpp.process() diff --git a/docker-compose.yml b/docker-compose.yml index 72b8bbb..f0f1507 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,4 +7,5 @@ services: - ./bot.py:/bot.py # Mount a local directory to the container - ./init.sh:/init.sh - ./config.conf:/config.conf + - ./qbittorrent_logo.png:/qbittorrent_logo.png command: /init.sh diff --git a/qbittorrent_logo.png b/qbittorrent_logo.png new file mode 100644 index 0000000..697ddb0 Binary files /dev/null and b/qbittorrent_logo.png differ