summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-11-15 12:30:09 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-11-15 12:30:09 +0100
commitd789a59f0c1d849e3074c890913882f09b048cd2 (patch)
tree4f6d62c7f5a5c4abafe0e9ff9546be7f136d4d3b
parent4e201be745521ace9701623d684dde316cb43af4 (diff)
parent4208920f425e9f37072715e52a5c7e95f074ab6e (diff)
downloadpoezio-d789a59f0c1d849e3074c890913882f09b048cd2.tar.gz
poezio-d789a59f0c1d849e3074c890913882f09b048cd2.tar.bz2
poezio-d789a59f0c1d849e3074c890913882f09b048cd2.tar.xz
poezio-d789a59f0c1d849e3074c890913882f09b048cd2.zip
Merge branch 'master' of http://git.louiz.org/poezio
-rw-r--r--plugins/iq_show.py14
-rw-r--r--plugins/ping.py53
-rw-r--r--plugins/reminder.py22
-rw-r--r--src/common.py1
4 files changed, 88 insertions, 2 deletions
diff --git a/plugins/iq_show.py b/plugins/iq_show.py
new file mode 100644
index 00000000..bfb2105a
--- /dev/null
+++ b/plugins/iq_show.py
@@ -0,0 +1,14 @@
+from plugin import BasePlugin
+from sleekxmpp.xmlstream.matcher import StanzaPath
+from sleekxmpp.xmlstream.handler import Callback
+
+class Plugin(BasePlugin):
+ def init(self):
+ self.core.xmpp.register_handler(Callback('Iq_show', StanzaPath('iq'), self.handle_iq))
+
+ def handle_iq(self, iq):
+ self.core.information('%s' % iq, 'Iq')
+
+ def cleanup(self):
+ self.core.xmpp.remove_handler('Iq_show')
+ del self.handle_iq
diff --git a/plugins/ping.py b/plugins/ping.py
new file mode 100644
index 00000000..349b7f52
--- /dev/null
+++ b/plugins/ping.py
@@ -0,0 +1,53 @@
+from plugin import BasePlugin
+from sleekxmpp.xmlstream.jid import JID
+from roster import roster
+import common
+import tabs
+
+
+class Plugin(BasePlugin):
+ def init(self):
+ self.core.xmpp.register_plugin('xep_0199')
+ self.add_command('ping', self.command_ping, '/ping <jid>\nPing: Send a XMPP ping to jid (see XEP-0199).', self.completion_ping)
+ self.add_tab_command(tabs.MucTab, 'ping', self.command_muc_ping, '/ping <jid or nick>\nPing: Send a XMPP ping to jid or nick (see XEP-0199)', self.completion_muc_ping)
+ self.add_tab_command(tabs.PrivateTab, 'ping', self.command_private_ping, '/ping\nPing: Send a XMPP ping to the current interlocutor (see XEP-0199)')
+ self.add_tab_command(tabs.ConversationTab, 'ping', self.command_private_ping, '/ping\nPing: Send a XMPP ping to the current interlocutor (see XEP-0199)')
+
+ def command_ping(self, arg):
+ if not arg:
+ return
+ jid = JID(arg)
+ try:
+ delay = self.core.xmpp.plugin['xep_0199'].send_ping(jid=jid)
+ except:
+ delay = None
+ if delay is not None:
+ self.core.information('%s responded to ping after %s s' % (jid, round(delay, 4)), 'Info')
+ else:
+ self.core.information('%s did not respond to ping' % jid, 'Info')
+
+ def completion_muc_ping(self, the_input):
+ users = [user.nick for user in self.core.current_tab().users]
+ l = [contact.bare_jid for contact in roster.get_contacts()]
+ users.extend(l)
+ return the_input.auto_completion(users, '')
+
+ def command_private_ping(self, arg):
+ self.command_ping(self.core.current_tab().get_name())
+
+ def command_muc_ping(self, arg):
+ args = common.shell_split(arg)
+ if not args:
+ return
+ user = self.core.current_tab().get_user_by_name(args[0])
+ if user:
+ jid = JID(self.core.current_tab().get_name())
+ jid.resource = user.nick
+ else:
+ jid = JID(args[0])
+ self.command_ping(jid.full)
+
+ def completion_ping(self, the_input):
+ l = [contact.bare_jid for contact in roster.get_contacts()]
+ return the_input.auto_completion(l, '')
+
diff --git a/plugins/reminder.py b/plugins/reminder.py
index 8426dcfe..ed45985c 100644
--- a/plugins/reminder.py
+++ b/plugins/reminder.py
@@ -29,11 +29,29 @@ class Plugin(BasePlugin):
args = common.shell_split(arg)
if len(args) < 2:
return
+ if args[0].endswith('d'):
+ modifier = 'd'
+ elif args[0].endswith('h'):
+ modifier = 'h'
+ elif args[0].endswith('m'):
+ modifier = 'm'
+ else:
+ modifier = None
try:
- time = int(args[0])
+ if modifier:
+ time = int(args[0][:-1])
+ else:
+ time = int(args[0])
except:
return
+ if modifier == 'd':
+ time = time * 86400
+ elif modifier == 'h':
+ time = time * 3600
+ elif modifier == 'm':
+ time = time * 60
+
self.tasks[self.count] = (time, args[1])
timed_event = timed_events.DelayedEvent(time, self.remind, self.count)
self.core.add_timed_event(timed_event)
@@ -47,7 +65,7 @@ class Plugin(BasePlugin):
if txt.endswith(' '):
n += 1
if n == 2:
- return the_input.auto_completion(["60", "300", "600", "900", "3600", "36000", "86400"], '')
+ return the_input.auto_completion(["60", "5m", "15m", "30m", "1h", "10h", "1d"], '')
def completion_done(self, the_input):
return the_input.auto_completion(["%s" % key for key in self.tasks], '')
diff --git a/src/common.py b/src/common.py
index 7e1c0642..35fd08da 100644
--- a/src/common.py
+++ b/src/common.py
@@ -173,6 +173,7 @@ def datetime_tuple(timestamp):
def shell_split(st):
sh = shlex.shlex(st, posix=True)
+ sh.commenters = ''
sh.whitespace_split = True
sh.quotes = '"'
ret = list()