annotate src/plugins/plugin_misc_text_commands.py @ 921:8dd168c7741c

plugin text commands: refactoring: - commands can now return a deferred - if commands return True, message is sent, else it is cancelled - the escape sequence is now '//' instead of '\/' - added software version to /whois command
author Goffi <goffi@goffi.org>
date Sat, 22 Mar 2014 13:47:33 +0100
parents 1fe00f0c9a91
children c897c8d321b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
4 # SàT plugin for managing text commands
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 771
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
10 # (at your option) any later version.
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
15 # GNU Affero General Public License for more details.
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 600
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 698
diff changeset
20 from sat.core.i18n import _
921
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
21 from sat.core.sat_main import MessageSentAndStored
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
22 from twisted.words.protocols.jabber import jid
921
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
23 from twisted.internet import defer
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
24 from twisted.python.failure import Failure
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from logging import debug, info, warning, error
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
26
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
27 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
28 "name": "Text commands",
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
29 "import_name": "TEXT-COMMANDS",
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
30 "type": "Misc",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
31 "protocols": [],
921
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
32 "dependencies": ["XEP-0045", "EXP-PARROT", "XEP-0092"],
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
33 "main": "TextCommands",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
34 "handler": "no",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
35 "description": _("""IRC like text commands""")
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
36 }
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
37
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
38
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
39 class TextCommands(object):
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
40 #FIXME: doc strings for commands have to be translatable
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
41 # plugins need a dynamic translation system (translation
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
42 # should be downloadable independently)
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
43
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def __init__(self, host):
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
45 info(_("Text commands initialization"))
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.host = host
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
47 host.trigger.add("sendMessage", self.sendMessageTrigger)
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
48
697
0c84fb112d70 core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents: 609
diff changeset
49 def sendMessageTrigger(self, mess_data, treatments, profile):
921
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
50 """ Install SendMessage command hook """
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
51 treatments.addCallback(self._sendMessageCmdHook, profile)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
52 return True
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
53
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
54 def _sendMessageCmdHook(self, mess_data, profile):
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
55 """ Check text commands in message, and react consequently
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
56 msg starting with / are potential command. If a command is found, it is executed, else message is sent normally
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
57 msg starting with // are escaped: they are sent with a single /
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
58 commands can abord message sending (if they return anything evaluating to False), or continue it (if they return True), eventually after modifying the message
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
59 an "unparsed" key is added to message, containing part of the message not yet parsed
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
60 commands can be deferred or not
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
61
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
62 """
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
63 msg = mess_data["message"]
921
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
64 try:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
65 if msg[:2] == '//':
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
66 # we have a double '/', it's the escape sequence
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
67 mess_data["message"] = msg[1:]
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
68 return mess_data
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
69 if msg[0] != '/':
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
70 return mess_data
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
71 except IndexError:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
72 return mess_data
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
73
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
74 # we have a command
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
75 d = None
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
76 command = msg[1:].partition(' ')[0].lower()
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
77 if command.isalpha():
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
78 # looks like an actual command, we try to call the corresponding method
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
79 def retHandling(ret):
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
80 """ Handle command return value:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
81 if ret is True, normally send message (possibly modified by command)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
82 else, abord message sending
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
83
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
84 """
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
85 if ret:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
86 return mess_data
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
87 else:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
88 return Failure(MessageSentAndStored("text commands took over", mess_data))
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
89
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
90 try:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
91 mess_data["unparsed"] = msg[1 + len(command):] # part not yet parsed of the message
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
92 d = defer.maybeDeferred(getattr(self, "cmd_%s" % command), mess_data, profile)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
93 d.addCallback(retHandling)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
94 except AttributeError:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
95 pass
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
96
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
97 return d or mess_data # if a command is detected, we should have a deferred, else be send the message normally
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
98
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
99 def _getRoomJID(self, arg, service_jid):
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
100 """Return a room jid with a shortcut
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
101 @param arg: argument: can be a full room jid (e.g.: sat@chat.jabberfr.org)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
102 or a shortcut (e.g.: sat or sat@ for sat on current service)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
103 @param service_jid: jid of the current service (e.g.: chat.jabberfr.org)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
104 """
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
105 nb_arobas = arg.count('@')
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
106 if nb_arobas == 1:
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
107 if arg[-1] != '@':
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
108 return jid.JID(arg)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
109 return jid.JID(arg + service_jid)
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
110 return jid.JID(u"%s@%s" % (arg, service_jid))
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
111
523
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
112 def _feedBack(self, message, mess_data, profile):
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
113 """Give a message back to the user"""
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
114 if mess_data["type"] == 'groupchat':
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
115 _from = mess_data["to"].userhostJID()
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
116 else:
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
117 _from = self.host.getJidNStream(profile)[0]
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
118
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
119 self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile)
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
120
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
121 def cmd_nick(self, mess_data, profile):
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
122 """change nickname"""
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
123 debug("Catched nick command")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
124
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
125 if mess_data['type'] != "groupchat":
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
126 #/nick command does nothing if we are not on a group chat
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
127 info("Ignoring /nick command on a non groupchat message")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
128
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
129 return True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
130
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
131 nick = mess_data["unparsed"].strip()
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
132 room = mess_data["to"]
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
133
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
134 self.host.plugins["XEP-0045"].nick(room, nick, profile)
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
135
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
136 return False
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
137
509
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
138 def cmd_join(self, mess_data, profile):
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
139 """join a new room (on the same service if full jid is not specified)"""
509
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
140 debug("Catched join command")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
141
509
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
142 if mess_data['type'] != "groupchat":
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
143 #/leave command does nothing if we are not on a group chat
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
144 info("Ignoring /join command on a non groupchat message")
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
145 return True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
146
509
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
147 if mess_data["unparsed"].strip():
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
148 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
149 nick = (self.host.plugins["XEP-0045"].getRoomNick(mess_data["to"].userhost(), profile) or
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
150 self.host.getClient(profile).jid.user)
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
151 self.host.plugins["XEP-0045"].join(room, nick, {}, profile)
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
152
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
153 return False
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
154
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
155 def cmd_leave(self, mess_data, profile):
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
156 """quit a room"""
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
157 debug("Catched leave command")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
158
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
159 if mess_data['type'] != "groupchat":
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
160 #/leave command does nothing if we are not on a group chat
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
161 info("Ignoring /leave command on a non groupchat message")
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
162 return True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
163
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
164 if mess_data["unparsed"].strip():
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
165 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
166 else:
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
167 room = mess_data["to"]
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
168
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
169 self.host.plugins["XEP-0045"].leave(room, profile)
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
170
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
171 return False
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
172
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
173 def cmd_part(self, mess_data, profile):
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
174 """just a synonym of /leave"""
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
175 return self.cmd_leave(mess_data, profile)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
176
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
177 def cmd_title(self, mess_data, profile):
523
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
178 """change room's subject"""
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
179 debug("Catched title command")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
180
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
181 if mess_data['type'] != "groupchat":
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
182 #/leave command does nothing if we are not on a group chat
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
183 info("Ignoring /title command on a non groupchat message")
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
184 return True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
185
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
186 subject = mess_data["unparsed"].strip()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
187
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
188 if subject:
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
189 room = mess_data["to"]
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
190 self.host.plugins["XEP-0045"].subject(room, subject, profile)
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
191
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
192 return False
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
193
565
7573897831ee plugin text commands: added /topic as a synonym of /title
Goffi <goffi@goffi.org>
parents: 535
diff changeset
194 def cmd_topic(self, mess_data, profile):
7573897831ee plugin text commands: added /topic as a synonym of /title
Goffi <goffi@goffi.org>
parents: 535
diff changeset
195 """just a synonym of /title"""
7573897831ee plugin text commands: added /topic as a synonym of /title
Goffi <goffi@goffi.org>
parents: 535
diff changeset
196 return self.cmd_title(mess_data, profile)
7573897831ee plugin text commands: added /topic as a synonym of /title
Goffi <goffi@goffi.org>
parents: 535
diff changeset
197
527
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
198 def cmd_parrot(self, mess_data, profile):
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
199 """activate Parrot mode between 2 entities, in both directions."""
535
790be337cc41 bridge: fixed D-Bus warning in frontend side of bridge
Goffi <goffi@goffi.org>
parents: 527
diff changeset
200 #TODO: these commands must not be hardcoded, an interface should be made
790be337cc41 bridge: fixed D-Bus warning in frontend side of bridge
Goffi <goffi@goffi.org>
parents: 527
diff changeset
201 # to allow plugins to register simple commands like this.
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
202
527
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
203 debug("Catched parrot command")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
204
527
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
205 try:
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
206 link_left_jid = jid.JID(mess_data["unparsed"].strip())
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
207 if not link_left_jid.user or not link_left_jid.host:
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
208 raise jid.InvalidFormat
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
209 except jid.InvalidFormat:
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
210 self._feedBack("Can't activate Parrot mode for invalid jid", mess_data, profile)
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
211 return False
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
212
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
213 link_right_jid = mess_data['to']
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
214
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
215 self.host.plugins["EXP-PARROT"].addParrot(link_left_jid, link_right_jid, profile)
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
216 self.host.plugins["EXP-PARROT"].addParrot(link_right_jid, link_left_jid, profile)
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
217
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
218 self._feedBack("Parrot mode activated for %s" % (unicode(link_left_jid), ), mess_data, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
219
527
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
220 return False
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
221
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
222 def cmd_unparrot(self, mess_data, profile):
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
223 """remove Parrot mode between 2 entities, in both directions."""
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
224 debug("Catched unparrot command")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
225
527
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
226 try:
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
227 link_left_jid = jid.JID(mess_data["unparsed"].strip())
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
228 if not link_left_jid.user or not link_left_jid.host:
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
229 raise jid.InvalidFormat
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
230 except jid.InvalidFormat:
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
231 self._feedBack("Can't deactivate Parrot mode for invalid jid", mess_data, profile)
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
232 return False
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
233
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
234 link_right_jid = mess_data['to']
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
235
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
236 self.host.plugins["EXP-PARROT"].removeParrot(link_left_jid, profile)
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
237 self.host.plugins["EXP-PARROT"].removeParrot(link_right_jid, profile)
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
238
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
239 self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
240
527
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
241 return False
9a3913fb0a6c plugin text commands: added /parrot and /unparrot commands to use Parrot plugin
Goffi <goffi@goffi.org>
parents: 523
diff changeset
242
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
243 def cmd_whois(self, mess_data, profile):
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
244 """show informations on entity"""
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
245 debug("Catched whois command")
698
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
246
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
247 entity = mess_data["unparsed"].strip()
698
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
248
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
249 if mess_data['type'] == "groupchat":
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
250 room = mess_data["to"]
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
251 if self.host.plugins["XEP-0045"].isNickInRoom(room, entity, profile):
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
252 entity = u"%s/%s" % (room, entity)
698
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
253
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
254 if not entity:
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
255 target_jid = mess_data["to"]
698
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
256 else:
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
257 try:
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
258 target_jid = jid.JID(entity)
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
259 if not target_jid.user or not target_jid.host:
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
260 raise jid.InvalidFormat
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
261 except (jid.InvalidFormat, RuntimeError):
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
262 self._feedBack(_("Invalid jid, can't whois"), mess_data, profile)
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
263 return False
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
264
921
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
265 if not target_jid.resource:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
266 target_jid.resource = self.host.memory.getLastResource(target_jid, profile)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
267
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
268 whois_msg = [_(u"whois for %(jid)s") % {'jid': target_jid}]
698
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
269
921
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
270 # version
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
271 def versionCb(version_data):
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
272 name, version, os = version_data
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
273 if name:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
274 whois_msg.append(_("Client name: %s") % name)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
275 if version:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
276 whois_msg.append(_("Client version: %s") % version)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
277 if os:
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
278 whois_msg.append(_("Operating system: %s") % os)
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
279
921
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
280 d = self.host.plugins['XEP-0092'].getVersion(target_jid, profile)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
281 d.addCallback(versionCb)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
282
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
283 #TODO: add informations here (vcard, etc)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
284
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
285 def feedBack(ignore):
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
286 self._feedBack(u"\n".join(whois_msg), mess_data, profile)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
287 return False
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
288
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
289 d.addCallback(feedBack)
8dd168c7741c plugin text commands: refactoring:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
290 return d
600
c5451501465b plugin text commands: basic /whois command (just show jid so far)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
291
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
292 def cmd_help(self, mess_data, profile):
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
293 """show help on available commands"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
294 commands = filter(lambda method: method.startswith('cmd_'), dir(self))
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
295 longuest = max([len(command) for command in commands])
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
296 help_cmds = []
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
297
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
298 for command in commands:
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
299 method = getattr(self, command)
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
300 try:
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
301 help_str = method.__doc__.split('\n')[0]
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
302 except AttributeError:
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
303 help_str = ''
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
304 spaces = (longuest - len(command)) * ' '
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
305 help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str))
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
306
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
307 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds), )
523
24c0d51449e7 plugin text commands: added _feedback method to send an answer to user
Goffi <goffi@goffi.org>
parents: 519
diff changeset
308 self._feedBack(help_mess, mess_data, profile)