plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:

- registerTextCommands can be called by a plugin in its __init__ method, it looks for methods starting with "cmd_" and register them as new commands
    - addWhoIsCb: add a callback to /whois command, the callback can complete whois informations
    - plugins parrot, XEP-0045 and XEP-0092 now manage their own commands
This commit is contained in:
Goffi 2014-03-24 10:57:15 +01:00
commit 8a52f6defa

View file

@ -43,6 +43,7 @@ PLUGIN_INFO = {
"type": "XEP",
"protocols": ["XEP-0045"],
"dependencies": [],
"recommendations": [C.TEXT_CMDS],
"main": "XEP_0045",
"handler": "yes",
"description": _("""Implementation of Multi-User Chat""")
@ -74,6 +75,10 @@ class XEP_0045(object):
host.bridge.addSignal("roomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile
host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile
self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True)
try:
self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
except KeyError:
info(_("Text commands not available"))
def __check_profile(self, profile):
"""check if profile is used and connected
@ -348,6 +353,85 @@ class XEP_0045(object):
self.clients[profile] = SatMUCClient(self)
return self.clients[profile]
# Text commands #
def cmd_nick(self, mess_data, profile):
"""change nickname"""
debug("Catched nick command")
if mess_data['type'] != "groupchat":
#/nick command does nothing if we are not on a group chat
info("Ignoring /nick command on a non groupchat message")
return True
nick = mess_data["unparsed"].strip()
room = mess_data["to"]
self.nick(room, nick, profile)
return False
def cmd_join(self, mess_data, profile):
"""join a new room (on the same service if full jid is not specified)"""
debug("Catched join command")
if mess_data['type'] != "groupchat":
#/leave command does nothing if we are not on a group chat
info("Ignoring /join command on a non groupchat message")
return True
if mess_data["unparsed"].strip():
room = self.host.plugins[C.TEXT_CMDS].getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
nick = (self.getRoomNick(mess_data["to"].userhost(), profile) or
self.host.getClient(profile).jid.user)
self.join(room, nick, {}, profile)
return False
def cmd_leave(self, mess_data, profile):
"""quit a room"""
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.host.plugins[C.TEXT_CMDS].getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
else:
room = mess_data["to"]
self.leave(room, profile)
return False
def cmd_part(self, mess_data, profile):
"""just a synonym of /leave"""
return self.cmd_leave(mess_data, profile)
def cmd_title(self, mess_data, profile):
"""change room's subject"""
debug("Catched title command")
if mess_data['type'] != "groupchat":
#/leave command does nothing if we are not on a group chat
info("Ignoring /title command on a non groupchat message")
return True
subject = mess_data["unparsed"].strip()
if subject:
room = mess_data["to"]
self.subject(room, subject, profile)
return False
def cmd_topic(self, mess_data, profile):
"""just a synonym of /title"""
return self.cmd_title(mess_data, profile)
class SatMUCClient (muc.MUCClient):
#implements(iwokkel.IDisco)