plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
- /parrot command add parrot link between the current entity/room and the entity given as an argument (must be a valid jid)
- similarly, /unparrot remove the 2 links between those entities.
- Parrot is a new dependency of text commands
This commit is contained in:
parent
160eee4445
commit
225d3ac5f1
2 changed files with 44 additions and 2 deletions
|
|
@ -106,7 +106,7 @@ class SatMessageProtocol(xmppim.MessageProtocol):
|
|||
|
||||
def onMessage(self, message):
|
||||
debug (_(u"got message from: %s"), message["from"])
|
||||
if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile):
|
||||
if not self.host.trigger.point("MessageReceived", message, profile=self.parent.profile):
|
||||
return
|
||||
for e in message.elements():
|
||||
if e.name == "body":
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ PLUGIN_INFO = {
|
|||
"import_name": "text-commands",
|
||||
"type": "Misc",
|
||||
"protocols": [],
|
||||
"dependencies": ["XEP-0045"],
|
||||
"dependencies": ["XEP-0045", "EXP-PARROT"],
|
||||
"main": "TextCommands",
|
||||
"handler": "no",
|
||||
"description": _("""IRC like text commands""")
|
||||
|
|
@ -159,6 +159,48 @@ class TextCommands():
|
|||
|
||||
return False
|
||||
|
||||
def cmd_parrot(self, mess_data, profile):
|
||||
"""activate Parrot mode between 2 entities, in both directions."""
|
||||
debug("Catched parrot command")
|
||||
|
||||
try:
|
||||
link_left_jid = jid.JID(mess_data["unparsed"].strip())
|
||||
if not link_left_jid.user or not link_left_jid.host:
|
||||
raise jid.InvalidFormat
|
||||
except jid.InvalidFormat:
|
||||
self._feedBack("Can't activate Parrot mode for invalid jid", mess_data, profile)
|
||||
return False
|
||||
|
||||
link_right_jid = mess_data['to']
|
||||
|
||||
self.host.plugins["EXP-PARROT"].addParrot(link_left_jid, link_right_jid, profile)
|
||||
self.host.plugins["EXP-PARROT"].addParrot(link_right_jid, link_left_jid, profile)
|
||||
|
||||
self._feedBack("Parrot mode activated for %s" % (unicode(link_left_jid),), mess_data, profile)
|
||||
|
||||
return False
|
||||
|
||||
def cmd_unparrot(self, mess_data, profile):
|
||||
"""remove Parrot mode between 2 entities, in both directions."""
|
||||
debug("Catched unparrot command")
|
||||
|
||||
try:
|
||||
link_left_jid = jid.JID(mess_data["unparsed"].strip())
|
||||
if not link_left_jid.user or not link_left_jid.host:
|
||||
raise jid.InvalidFormat
|
||||
except jid.InvalidFormat:
|
||||
self._feedBack("Can't deactivate Parrot mode for invalid jid", mess_data, profile)
|
||||
return False
|
||||
|
||||
link_right_jid = mess_data['to']
|
||||
|
||||
self.host.plugins["EXP-PARROT"].removeParrot(link_left_jid, profile)
|
||||
self.host.plugins["EXP-PARROT"].removeParrot(link_right_jid, profile)
|
||||
|
||||
self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile)
|
||||
|
||||
return False
|
||||
|
||||
def cmd_help(self, mess_data, profile):
|
||||
"""show help on available commands"""
|
||||
commands=filter(lambda method: method.startswith('cmd_'), dir(self))
|
||||
|
|
|
|||
Loading…
Reference in a new issue