From b00d2fd2bc6172ce2b442147f2a0fab5640cc9ca Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 26 Aug 2016 22:07:57 +0200 Subject: Fix #3204 (write a /server_part plugin) --- plugins/server_part.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 plugins/server_part.py (limited to 'plugins') diff --git a/plugins/server_part.py b/plugins/server_part.py new file mode 100644 index 00000000..878001e7 --- /dev/null +++ b/plugins/server_part.py @@ -0,0 +1,62 @@ +""" +This plugin adds a ``/server_part`` command to leave all rooms +on a server. + +Command +------- + +.. glossary:: + + /server_part + **Usage:** ``/server_part [ [message]]`` + + Leave all rooms on ````, if not provided and the current + tab is a MUC tab, it will leave all rooms on the current server. + ``[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 + +class Plugin(BasePlugin): + def init(self): + self.api.add_command('server_part', self.command_server_part, + usage='[ [message]]', + short='Leave all the rooms on a server', + help='Leave all the rooms on a sever.', + completion=self.completion_server_part) + + @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: + jid = safeJID(current_tab.name).bare + 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): + if tab.name.endswith(jid): + 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: + serv = safeJID(tab.name).server + serv_list.add(serv) + return Completion(the_input.new_completion, sorted(serv_list), 1, ' ') -- cgit v1.2.3