comparison src/plugins/plugin_misc_text_commands.py @ 508:7c6609dddb2c

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
author Goffi <goffi@goffi.org>
date Fri, 28 Sep 2012 00:31:10 +0200
parents 2e43c74815ad
children 64ff046dc201
comparison
equal deleted inserted replaced
507:f98bef71a918 508:7c6609dddb2c
17 17
18 You should have received a copy of the GNU Affero General Public License 18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 from twisted.words.protocols.jabber import jid
22 from logging import debug, info, warning, error 23 from logging import debug, info, warning, error
23 24
24 PLUGIN_INFO = { 25 PLUGIN_INFO = {
25 "name": "Text commands", 26 "name": "Text commands",
26 "import_name": "text-commands", 27 "import_name": "text-commands",
58 mess_data["message"] = msg[1:] 59 mess_data["message"] = msg[1:]
59 except IndexError: 60 except IndexError:
60 pass 61 pass
61 return True 62 return True
62 63
64 def _getRoomJID(self, arg, service_jid):
65 """Return a room jid with a shortcut
66 @param arg: argument: can be a full room jid (e.g.: sat@chat.jabberfr.org)
67 or a shortcut (e.g.: sat or sat@ for sat on current service)
68 @param service_jid: jid of the current service (e.g.: chat.jabberfr.org)
69 """
70 nb_arobas = arg.count('@')
71 if nb_arobas == 1:
72 if arg[-1] !='@':
73 return jid.JID(arg)
74 return jid.JID(arg+service_jid)
75 return jid.JID(u"%s@%s" % (arg, service_jid))
63 76
64 def cmd_nick(self, mess_data, profile): 77 def cmd_nick(self, mess_data, profile):
65 debug("Catched nick command") 78 debug("Catched nick command")
66 79
67 if mess_data['type'] != "groupchat": 80 if mess_data['type'] != "groupchat":
74 room = mess_data["to"] 87 room = mess_data["to"]
75 88
76 self.host.plugins["XEP-0045"].nick(room,nick,profile) 89 self.host.plugins["XEP-0045"].nick(room,nick,profile)
77 90
78 return False 91 return False
92
93 def cmd_leave(self, mess_data, profile):
94 debug("Catched leave command")
95
96 if mess_data['type'] != "groupchat":
97 #/leave command does nothing if we are not on a group chat
98 info("Ignoring /leave command on a non groupchat message")
99 return True
100
101 if mess_data["unparsed"].strip():
102 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
103 else:
104 room = mess_data["to"]
105
106 self.host.plugins["XEP-0045"].leave(room,profile)
107
108 return False
109
110 def cmd_part(self, mess_data, profile):
111 """just a synonym of /leave"""
112 return self.cmd_leave(mess_data, profile)
113