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
This commit is contained in:
parent
c520325941
commit
d75b24427e
1 changed files with 35 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue