|
| 1 | +from plugin import BasePlugin |
| 2 | +import tabs |
| 3 | +import common |
| 4 | +import timed_events |
| 5 | + |
| 6 | +class Plugin(BasePlugin): |
| 7 | + |
| 8 | + def init(self): |
| 9 | + 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) |
| 10 | + 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) |
| 11 | + 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) |
| 12 | + |
| 13 | + def command_delayed(self, arg): |
| 14 | + args = common.shell_split(arg) |
| 15 | + if len(args) != 2: |
| 16 | + return |
| 17 | + delay = common.parse_str_to_secs(args[0]) |
| 18 | + if not delay: |
| 19 | + return |
| 20 | + |
| 21 | + tab = self.core.current_tab() |
| 22 | + timed_event = timed_events.DelayedEvent(delay, self.say, (tab, args[1])) |
| 23 | + self.core.add_timed_event(timed_event) |
| 24 | + |
| 25 | + def completion_delay(self, the_input): |
| 26 | + txt = the_input.get_text() |
| 27 | + args = common.shell_split(txt) |
| 28 | + n = len(args) |
| 29 | + if txt.endswith(' '): |
| 30 | + n += 1 |
| 31 | + if n == 2: |
| 32 | + return the_input.auto_completion(["60", "5m", "15m", "30m", "1h", "10h", "1d"], '') |
| 33 | + |
| 34 | + def say(self, args=None): |
| 35 | + if not args: |
| 36 | + return |
| 37 | + |
| 38 | + tab = args[0] |
| 39 | + # anything could happen to the tab during the interval |
| 40 | + try: |
| 41 | + tab.command_say(args[1]) |
| 42 | + except: |
| 43 | + pass |
0 commit comments