summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-11-16 02:09:55 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-11-16 02:09:55 +0100
commitefeb0ad58e04104021897c401c73c6e5ff2831d0 (patch)
tree4162b0f24c2fc6632cc1d6ab0435ac3eb90430e9 /plugins
parentd789a59f0c1d849e3074c890913882f09b048cd2 (diff)
parent034a2bde2c571645c7319f89ef63ccc0451bcb0e (diff)
downloadpoezio-efeb0ad58e04104021897c401c73c6e5ff2831d0.tar.gz
poezio-efeb0ad58e04104021897c401c73c6e5ff2831d0.tar.bz2
poezio-efeb0ad58e04104021897c401c73c6e5ff2831d0.tar.xz
poezio-efeb0ad58e04104021897c401c73c6e5ff2831d0.zip
Merge branch 'master' of http://git.louiz.org/poezio
Diffstat (limited to 'plugins')
-rw-r--r--plugins/reminder.py29
-rw-r--r--plugins/send_delayed.py43
2 files changed, 49 insertions, 23 deletions
diff --git a/plugins/reminder.py b/plugins/reminder.py
index ed45985c..49062b2c 100644
--- a/plugins/reminder.py
+++ b/plugins/reminder.py
@@ -29,33 +29,15 @@ 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:
- if modifier:
- time = int(args[0][:-1])
- else:
- time = int(args[0])
- except:
+ time = common.parse_str_to_secs(args[0])
+ if not time:
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)
- self.core.information('Task %s added: %s every %s seconds.' % (self.count, args[1], time), 'Info')
+ self.core.information('Task %s added: %s every %s.' % (self.count, args[1],
+ common.parse_secs_to_str(time)), 'Info')
self.count += 1
def completion_remind(self, the_input):
@@ -87,7 +69,8 @@ class Plugin(BasePlugin):
else:
s = 'The following tasks are active:\n'
for key in self.tasks:
- s += 'Task %s: %s every %s seconds.\n' % (key, repr(self.tasks[key][1]), self.tasks[key][0])
+ s += 'Task %s: %s every %s.\n' % (key, repr(self.tasks[key][1]),
+ common.parse_secs_to_str(self.tasks[key][0]))
if s:
self.core.information(s, 'Info')
diff --git a/plugins/send_delayed.py b/plugins/send_delayed.py
new file mode 100644
index 00000000..61d2d397
--- /dev/null
+++ b/plugins/send_delayed.py
@@ -0,0 +1,43 @@
+from plugin import BasePlugin
+import tabs
+import common
+import timed_events
+
+class Plugin(BasePlugin):
+
+ def init(self):
+ self.add_tab_command(tabs.PrivateTab, 'send_delayed', self.command_delayed, "Usage: /send_delayed <delay> <message>\nSend Delayed: Send <message> with a delay of <delay> seconds.", self.completion_delay)
+ self.add_tab_command(tabs.MucTab, 'send_delayed', self.command_delayed, "Usage: /send_delayed <delay> <message>\nSend Delayed: Send <message> with a delay of <delay> seconds.", self.completion_delay)
+ self.add_tab_command(tabs.ConversationTab, 'send_delayed', self.command_delayed, "Usage: /send_delayed <delay> <message>\nSend Delayed: Send <message> with a delay of <delay> seconds.", self.completion_delay)
+
+ def command_delayed(self, arg):
+ args = common.shell_split(arg)
+ if len(args) != 2:
+ return
+ delay = common.parse_str_to_secs(args[0])
+ if not delay:
+ return
+
+ tab = self.core.current_tab()
+ timed_event = timed_events.DelayedEvent(delay, self.say, (tab, args[1]))
+ self.core.add_timed_event(timed_event)
+
+ def completion_delay(self, the_input):
+ txt = the_input.get_text()
+ args = common.shell_split(txt)
+ n = len(args)
+ if txt.endswith(' '):
+ n += 1
+ if n == 2:
+ return the_input.auto_completion(["60", "5m", "15m", "30m", "1h", "10h", "1d"], '')
+
+ def say(self, args=None):
+ if not args:
+ return
+
+ tab = args[0]
+ # anything could happen to the tab during the interval
+ try:
+ tab.command_say(args[1])
+ except:
+ pass