From d75b24427e466477396c5a8c81b049f69046d811 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 28 Sep 2012 00:31:10 +0200 Subject: [PATCH] plugin text commands: /leave management: - _getRoomJid manage room jid argument: the argument can be full jid or a shortcut. in case of shortcut, room or room@ can be used for shortcut room@service.domain.tld where service.domain.tld is the same as the one of the room where the command is entered - /leave alone leave the current room, /leave [room] leave the given room - /part is a synonym of /leave --- src/plugins/plugin_misc_text_commands.py | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/plugins/plugin_misc_text_commands.py b/src/plugins/plugin_misc_text_commands.py index fccee594..0a3ff657 100755 --- a/src/plugins/plugin_misc_text_commands.py +++ b/src/plugins/plugin_misc_text_commands.py @@ -19,6 +19,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . """ +from twisted.words.protocols.jabber import jid from logging import debug, info, warning, error PLUGIN_INFO = { @@ -60,6 +61,18 @@ class TextCommands(): pass return True + def _getRoomJID(self, arg, service_jid): + """Return a room jid with a shortcut + @param arg: argument: can be a full room jid (e.g.: sat@chat.jabberfr.org) + or a shortcut (e.g.: sat or sat@ for sat on current service) + @param service_jid: jid of the current service (e.g.: chat.jabberfr.org) + """ + nb_arobas = arg.count('@') + if nb_arobas == 1: + if arg[-1] !='@': + return jid.JID(arg) + return jid.JID(arg+service_jid) + return jid.JID(u"%s@%s" % (arg, service_jid)) def cmd_nick(self, mess_data, profile): debug("Catched nick command") @@ -76,3 +89,25 @@ class TextCommands(): self.host.plugins["XEP-0045"].nick(room,nick,profile) return False + + def cmd_leave(self, mess_data, profile): + debug("Catched leave command") + + if mess_data['type'] != "groupchat": + #/leave command does nothing if we are not on a group chat + info("Ignoring /leave command on a non groupchat message") + return True + + if mess_data["unparsed"].strip(): + room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) + else: + room = mess_data["to"] + + self.host.plugins["XEP-0045"].leave(room,profile) + + return False + + def cmd_part(self, mess_data, profile): + """just a synonym of /leave""" + return self.cmd_leave(mess_data, profile) +