summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2016-07-15 16:47:08 +1200
committerFlorian Baumann <derflob@derflob.de>2016-07-15 17:20:46 +1200
commit7c83cbb43deee2b174bb0badff7e02e4de01366e (patch)
tree351db2fbee1f0a786f10ed93a90f72acea769640
parent11c4ddfa8a828a4ba671b427bae11574bafd6202 (diff)
downloadxmpp-7c83cbb43deee2b174bb0badff7e02e4de01366e.tar.gz
xmpp-7c83cbb43deee2b174bb0badff7e02e4de01366e.tar.bz2
cmd: snapshot
-rw-r--r--__init__.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/__init__.py b/__init__.py
index c173954..b55f842 100644
--- a/__init__.py
+++ b/__init__.py
@@ -29,6 +29,8 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
self._xmpp.register_plugin('xep_0030') # disco
self._xmpp.register_plugin('xep_0045') # muc
self._xmpp.register_plugin('xep_0066') # oob
+ self._xmpp.register_plugin('xep_0085') # chat state
+ self._xmpp.register_plugin('xep_0184') # delivery receipts
self._xmpp.register_plugin('xep_0363') # http upload
self._xmpp.connect()
@@ -44,27 +46,34 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
}
}
+ def _take_snapshot(self):
+ snapshot = self._settings.global_get(['webcam', 'snapshot'])
+ if (snapshot):
+ req = requests.get(snapshot)
+
+ if (req.ok):
+ return (req.content, req.headers.get('content-type', None))
+
+ return (None, None)
+
def _msg_recipients(self, msg, send_image=True):
for (chat_type, recipient) in self._settings.get(['xmpp', 'recipients']):
self._xmpp.send_message(mto=recipient, mbody=msg, mtype=chat_type)
if (send_image):
- snapshot = self._settings.global_get(['webcam', 'snapshot'])
+ (snapshot, content_type) = self._take_snapshot()
if (snapshot):
- req = requests.get(snapshot)
-
- if (req.ok):
- i = self._xmpp['xep_0363'].start_upload(
- 'rupert.jpg', io.BytesIO(req.content), len(req.content), req.headers.get('content-type', None))
+ i = self._xmpp['xep_0363'].start_upload(
+ 'rupert.jpg', io.BytesIO(snapshot), len(snapshot), content_type)
- def __send_get_url(get_url):
- for (chat_type, recipient) in self._settings.get(['xmpp', 'recipients']):
- m = self._xmpp.make_message(mto=recipient, mbody=get_url, mtype=chat_type)
- m['oob']['url'] = get_url
- m.send()
+ def __send_get_url(get_url):
+ for (chat_type, recipient) in self._settings.get(['xmpp', 'recipients']):
+ m = self._xmpp.make_message(mto=recipient, mbody=get_url, mtype=chat_type)
+ m['oob']['url'] = get_url
+ m.send()
- self._xmpp.add_event_handler("http_upload::{}::finished".format(i),
- __send_get_url, disposable=True)
+ self._xmpp.add_event_handler("http_upload::{}::finished".format(i),
+ __send_get_url, disposable=True)
def _join_groupchats(self):
nick = self._settings.get(['xmpp', 'resource'])
@@ -157,6 +166,20 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
else:
return "Machine state:\n{}".format(self._printer.get_state_string())
+ def _cmd_snapshot(self, msg):
+ (snapshot, content_type) = self._take_snapshot()
+ if (snapshot):
+ i = self._xmpp['xep_0363'].start_upload(
+ 'rupert.jpg', io.BytesIO(snapshot), len(snapshot), content_type)
+
+ def __send_get_url(get_url):
+ m = msg.reply(body=get_url)
+ m['oob']['url'] = get_url
+ m.send()
+
+ self._xmpp.add_event_handler("http_upload::{}::finished".format(i),
+ __send_get_url, disposable=True)
+
__plugin_name__ = "OctoXMPP"
__plugin_version__ = "0.2.0"