From 40bc7e66471f1b8dfc3403c282cf5a5b8ff308fe Mon Sep 17 00:00:00 2001 From: Seve Date: Sat, 31 Mar 2018 16:00:47 +0200 Subject: Initial start with the embed command --- plugins/embed.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 plugins/embed.py diff --git a/plugins/embed.py b/plugins/embed.py new file mode 100644 index 00000000..717fc3c5 --- /dev/null +++ b/plugins/embed.py @@ -0,0 +1,45 @@ +""" +Display an image URL as an embedded image in some clients like Conversations. +Uses: https://xmpp.org/extensions/xep-0066.html#x-oob + +Usage +----- + +.. glossary:: + + /embed + + Run this command to send the as an + embedded image in your contact's client. +""" + +from poezio import tabs +from poezio.plugin import BasePlugin +from poezio.theming import get_theme + +class Plugin(BasePlugin): + + def init(self): + for tab_t in [tabs.MucTab, tabs.ConversationTab, tabs.PrivateTab]: + self.api.add_tab_command(tab_t, 'embed', self.embed_image_url, + help='Embed an image url into the contact\'s client', + usage='') + + def embed_image_url(self, args): + tab = self.api.current_tab() + message = self.core.xmpp.make_message(tab.name) + message['body'] = args + message['oob']['url'] = args + if isinstance(tab, tabs.MucTab): + message['type'] = 'groupchat' + else: + message['type'] = 'chat' + tab.add_message( + message['body'], + nickname=tab.core.own_nick, + nick_color=get_theme().COLOR_OWN_NICK, + identifier=message['id'], + jid=tab.core.xmpp.boundjid, + typ=1, + ) + message.send() -- cgit v1.2.3