summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-03-31 01:24:37 +0200
committermathieui <mathieui@mathieui.net>2012-03-31 01:24:37 +0200
commit57e586531db1893849a73b27f8b7dea263b96a82 (patch)
treea5728994b8a43dbaffd45fafd81522676061ac76
parent372b032380ff3703f1458fd965f5a8431c53f7bc (diff)
downloadpoezio-57e586531db1893849a73b27f8b7dea263b96a82.tar.gz
poezio-57e586531db1893849a73b27f8b7dea263b96a82.tar.bz2
poezio-57e586531db1893849a73b27f8b7dea263b96a82.tar.xz
poezio-57e586531db1893849a73b27f8b7dea263b96a82.zip
Add a /tell plugin
-rw-r--r--plugins/tell.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins/tell.py b/plugins/tell.py
new file mode 100644
index 00000000..bcb488b7
--- /dev/null
+++ b/plugins/tell.py
@@ -0,0 +1,56 @@
+from plugin import BasePlugin
+import tabs
+import common
+
+class Plugin(BasePlugin):
+ def init(self):
+ self.add_tab_command(tabs.MucTab, 'tell', self.command_tell,
+ '/tell <nick> <message>\nTell: will tell <nick> of <message> when he next joins.')
+ self.add_tab_command(tabs.MucTab, 'untell', self.command_untell,
+ '/untell <nick>\nUntell: will remove the saved messages from /tell.',
+ self.completion_untell)
+ self.add_event_handler('muc_join', self.on_join)
+ # {tab -> {nick -> [messages]}
+ self.tabs = {}
+
+ def on_join(self, presence, tab):
+ if not tab in self.tabs:
+ return
+ nick = presence['from'].resource
+ if not nick in self.tabs[tab]:
+ return
+ for i in self.tabs[tab][nick]:
+ tab.command_say("%s: %s" % (nick, i))
+ del self.tabs[tab][nick]
+
+ def command_tell(self, args):
+ """/tell <nick> <message>"""
+ arg = common.shell_split(args)
+ if len(arg) != 2:
+ self.core.command_help('tell')
+ return
+ nick, msg = arg
+ tab = self.core.current_tab()
+ if not tab in self.tabs:
+ self.tabs[tab] = {}
+ if not nick in self.tabs[tab]:
+ self.tabs[tab][nick] = []
+ self.tabs[tab][nick].append(msg)
+ self.core.information('Will tell %s' % nick, 'Info')
+
+ def command_untell(self, args):
+ """/untell <nick>"""
+ tab = self.core.current_tab()
+ if not tab in self.tabs:
+ return
+ nick = args
+ if not nick in self.tabs[tab]:
+ return
+ del self.tabs[tab][nick]
+
+ def completion_untell(self, the_input):
+ tab = self.core.current_tab()
+ if not tab in self.tabs:
+ return the_input.auto_completion([], '')
+ return the_input.auto_completion(list(self.tabs[tab]), '')
+