2013-05-20 21:14:37 +00:00
|
|
|
"""
|
|
|
|
The command added by this plugin sends a message to someone when he next joins.
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
2016-10-03 22:26:54 +00:00
|
|
|
This plugin defines two new commands for chatroom tabs:
|
|
|
|
:term:`/tell`, :term:`/untell`, and :term:`/list_tell`.
|
2013-05-20 21:14:37 +00:00
|
|
|
|
|
|
|
.. 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*.
|
|
|
|
|
2016-10-02 13:05:58 +00:00
|
|
|
/list_tell
|
|
|
|
**Usage:** ``/list_tell``
|
|
|
|
|
|
|
|
List all queued messages for the current chatroom.
|
|
|
|
|
2013-05-20 21:14:37 +00:00
|
|
|
"""
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.plugin import BasePlugin
|
2016-08-21 13:27:53 +00:00
|
|
|
from poezio.core.structs import Completion
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.decorators import command_args_parser
|
|
|
|
from poezio import tabs
|
2012-03-30 23:24:37 +00:00
|
|
|
|
|
|
|
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)
|
2016-10-02 13:05:58 +00:00
|
|
|
self.api.add_tab_command(tabs.MucTab, 'list_tell', self.command_list_tell,
|
|
|
|
usage='',
|
|
|
|
help='List currently queued messages')
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.add_event_handler('muc_join', self.on_join)
|
2017-11-23 18:13:58 +00:00
|
|
|
self.api.add_event_handler('muc_nickchange', self.on_join)
|
2012-03-30 23:24:37 +00:00
|
|
|
# {tab -> {nick -> [messages]}
|
|
|
|
self.tabs = {}
|
|
|
|
|
|
|
|
def on_join(self, presence, tab):
|
2017-10-08 14:36:10 +00:00
|
|
|
if tab not in self.tabs:
|
2012-03-30 23:24:37 +00:00
|
|
|
return
|
|
|
|
nick = presence['from'].resource
|
2017-10-08 14:36:10 +00:00
|
|
|
if nick not in self.tabs[tab]:
|
2012-03-30 23:24:37 +00:00
|
|
|
return
|
|
|
|
for i in self.tabs[tab][nick]:
|
|
|
|
tab.command_say("%s: %s" % (nick, i))
|
|
|
|
del self.tabs[tab][nick]
|
|
|
|
|
2016-10-02 13:05:58 +00:00
|
|
|
@command_args_parser.ignored
|
|
|
|
def command_list_tell(self):
|
|
|
|
tab = self.api.current_tab()
|
|
|
|
if not self.tabs.get(tab):
|
|
|
|
self.api.information('No message queued.', 'Info')
|
|
|
|
return
|
|
|
|
build = ['Messages queued for %s:' % tab.name]
|
|
|
|
for nick, messages in self.tabs[tab].items():
|
|
|
|
build.append(' for %s:' % nick)
|
|
|
|
for message in messages:
|
|
|
|
build.append(' - %s' % message)
|
|
|
|
self.api.information('\n'.join(build), 'Info')
|
|
|
|
|
2015-11-11 20:05:38 +00:00
|
|
|
@command_args_parser.quoted(2)
|
2012-03-30 23:24:37 +00:00
|
|
|
def command_tell(self, args):
|
|
|
|
"""/tell <nick> <message>"""
|
2015-11-11 20:05:38 +00:00
|
|
|
if args is None:
|
2016-03-31 22:24:58 +00:00
|
|
|
self.core.command.help('tell')
|
2012-03-30 23:24:37 +00:00
|
|
|
return
|
2015-11-11 20:05:38 +00:00
|
|
|
nick, msg = args
|
2013-03-08 21:53:35 +00:00
|
|
|
tab = self.api.current_tab()
|
2017-10-08 14:36:10 +00:00
|
|
|
if tab not in self.tabs:
|
2012-03-30 23:24:37 +00:00
|
|
|
self.tabs[tab] = {}
|
2017-10-08 14:36:10 +00:00
|
|
|
if nick not in self.tabs[tab]:
|
2012-03-30 23:24:37 +00:00
|
|
|
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()
|
2017-10-08 14:36:10 +00:00
|
|
|
if tab not in self.tabs:
|
2012-03-30 23:24:37 +00:00
|
|
|
return
|
|
|
|
nick = args
|
2017-10-08 14:36:10 +00:00
|
|
|
if nick not in self.tabs[tab]:
|
2012-03-30 23:24:37 +00:00
|
|
|
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()
|
2017-10-08 14:36:10 +00:00
|
|
|
if tab not in self.tabs:
|
2016-08-21 13:27:53 +00:00
|
|
|
return Completion(the_input.auto_completion, [], '')
|
|
|
|
return Completion(the_input.auto_completion, list(self.tabs[tab]), '', quotify=False)
|
2012-03-30 23:24:37 +00:00
|
|
|
|