Bot now sets its profile picture
This commit is contained in:
		
							parent
							
								
									82a5c15bd4
								
							
						
					
					
						commit
						197e30bdf7
					
				
							
								
								
									
										45
									
								
								bot.py
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								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() | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								qbittorrent_logo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								qbittorrent_logo.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 56 KiB | 
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user