2013-05-20 21:14:37 +00:00
|
|
|
"""
|
|
|
|
The command added by this plugin sends a message to someone when he next joins.
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
This plugin defines two new commands for MUC tabs: :term:`/tell` and :term:`/untell`.
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
:sorted:
|
|
|
|
|
|
|
|
/tell
|
2014-03-27 22:45:47 +00:00
|
|
|
**Usage:** ``/tell <nick> <message>``
|
2013-05-20 21:14:37 +00:00
|
|
|
|
|
|
|
Send *message* to *nick* at his next join.
|
|
|
|
|
|
|
|
/untell
|
2014-03-27 22:45:47 +00:00
|
|
|
**Usage:** ``/untell <nick>``
|
2013-05-20 21:14:37 +00:00
|
|
|
|
|
|
|
Cancel all scheduled messages to *nick*.
|
|
|
|
|
|
|
|
"""
|
2012-03-30 23:24:37 +00:00
|
|
|
from plugin import BasePlugin
|
|
|
|
import tabs
|
|
|
|
import common
|
|
|
|
|
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.add_tab_command(tabs.MucTab, 'tell', self.command_tell,
|
2013-03-01 18:25:31 +00:00
|
|
|
usage='<nick> <message>',
|
|
|
|
help='Will tell <nick> of <message> when he next joins.',
|
|
|
|
short='Send a message when someone joins')
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.add_tab_command(tabs.MucTab, 'untell', self.command_untell,
|
2013-03-01 18:25:31 +00:00
|
|
|
usage='<nick>',
|
|
|
|
help='Remove the planned messages from /tell.',
|
|
|
|
short='Cancel a /tell message',
|
|
|
|
completion=self.completion_untell)
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.add_event_handler('muc_join', self.on_join)
|
2012-03-30 23:24:37 +00:00
|
|
|
# {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:
|
2013-06-16 12:47:14 +00:00
|
|
|
self.core.command_help('tell')
|
2012-03-30 23:24:37 +00:00
|
|
|
return
|
|
|
|
nick, msg = arg
|
2013-03-08 21:53:35 +00:00
|
|
|
tab = self.api.current_tab()
|
2012-03-30 23:24:37 +00:00
|
|
|
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)
|
2014-09-17 16:51:56 +00:00
|
|
|
self.api.information('Message for %s queued' % nick, 'Info')
|
2012-03-30 23:24:37 +00:00
|
|
|
|
|
|
|
def command_untell(self, args):
|
|
|
|
"""/untell <nick>"""
|
2013-03-08 21:53:35 +00:00
|
|
|
tab = self.api.current_tab()
|
2012-03-30 23:24:37 +00:00
|
|
|
if not tab in self.tabs:
|
|
|
|
return
|
|
|
|
nick = args
|
|
|
|
if not nick in self.tabs[tab]:
|
|
|
|
return
|
|
|
|
del self.tabs[tab][nick]
|
2014-09-17 16:51:56 +00:00
|
|
|
self.api.information('Messages for %s unqueued' % nick, 'Info')
|
2012-03-30 23:24:37 +00:00
|
|
|
|
|
|
|
def completion_untell(self, the_input):
|
2013-03-08 21:53:35 +00:00
|
|
|
tab = self.api.current_tab()
|
2012-03-30 23:24:37 +00:00
|
|
|
if not tab in self.tabs:
|
|
|
|
return the_input.auto_completion([], '')
|
2014-09-17 16:51:56 +00:00
|
|
|
return the_input.auto_completion(list(self.tabs[tab]), '', quotify=False)
|
2012-03-30 23:24:37 +00:00
|
|
|
|