2016-08-26 20:07:57 +00:00
|
|
|
"""
|
|
|
|
This plugin adds a ``/server_part`` command to leave all rooms
|
|
|
|
on a server.
|
|
|
|
|
|
|
|
Command
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
|
|
|
/server_part
|
|
|
|
**Usage:** ``/server_part [<server> [message]]``
|
|
|
|
|
|
|
|
Leave all rooms on ``<server>``, if not provided and the current
|
2016-10-03 22:26:54 +00:00
|
|
|
tab is a chatroom tab, it will leave all rooms on the current server.
|
2016-08-26 20:07:57 +00:00
|
|
|
``[message]`` can indicate a quit message.
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
from poezio.plugin import BasePlugin
|
|
|
|
from poezio.tabs import MucTab
|
|
|
|
from poezio.decorators import command_args_parser
|
|
|
|
from poezio.common import safeJID
|
|
|
|
from poezio.core.structs import Completion
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2016-08-26 20:07:57 +00:00
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
2018-08-15 11:13:17 +00:00
|
|
|
self.api.add_command(
|
|
|
|
'server_part',
|
|
|
|
self.command_server_part,
|
|
|
|
usage='[<server> [message]]',
|
|
|
|
short='Leave all the rooms on a server',
|
|
|
|
help='Leave all the rooms on a sever.',
|
|
|
|
completion=self.completion_server_part)
|
2016-08-26 20:07:57 +00:00
|
|
|
|
|
|
|
@command_args_parser.quoted(0, 2, defaults=[])
|
|
|
|
def command_server_part(self, args):
|
|
|
|
current_tab = self.api.current_tab()
|
|
|
|
if not args and not isinstance(current_tab, MucTab):
|
|
|
|
return self.core.command_help('server_part')
|
|
|
|
elif not args:
|
2019-04-28 00:02:49 +00:00
|
|
|
jid = current_tab.jid.bare
|
2016-08-26 20:07:57 +00:00
|
|
|
message = None
|
|
|
|
elif len(args) == 1:
|
|
|
|
jid = safeJID(args[0]).domain
|
|
|
|
if not jid:
|
|
|
|
return self.core.command_help('server_part')
|
|
|
|
message = None
|
|
|
|
else:
|
|
|
|
jid = safeJID(args[0]).domain
|
|
|
|
if not jid:
|
|
|
|
return self.core.command_help('server_part')
|
|
|
|
message = args[1]
|
|
|
|
|
|
|
|
for tab in self.core.get_tabs(MucTab):
|
2019-04-08 12:49:57 +00:00
|
|
|
if tab.name.endswith(jid):
|
2016-08-26 20:07:57 +00:00
|
|
|
tab.command_part(message)
|
|
|
|
|
|
|
|
def completion_server_part(self, the_input):
|
|
|
|
serv_list = set()
|
|
|
|
for tab in self.core.get_tabs(MucTab):
|
|
|
|
if tab.joined:
|
2019-04-28 00:02:49 +00:00
|
|
|
serv = tab.jid.server
|
2016-08-26 20:07:57 +00:00
|
|
|
serv_list.add(serv)
|
|
|
|
return Completion(the_input.new_completion, sorted(serv_list), 1, ' ')
|