annotate src/plugins/plugin_misc_text_commands.py @ 519:b7577230a7c8

reverted bad commit
author Goffi <goffi@goffi.org>
date Sun, 21 Oct 2012 12:55:27 +0200
parents 75216d94a89d
children 24c0d51449e7
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
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SàT plugin for managing text commands
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org)
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
7
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
12
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
17
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
21
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
22 from twisted.words.protocols.jabber import jid
506
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
23 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
24
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
25 PLUGIN_INFO = {
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
26 "name": "Text commands",
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
27 "import_name": "text-commands",
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
28 "type": "Misc",
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
29 "protocols": [],
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
30 "dependencies": ["XEP-0045"],
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
31 "main": "TextCommands",
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
32 "handler": "no",
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
33 "description": _("""IRC like text commands""")
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
34 }
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
35
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
36 class TextCommands():
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
37 #FIXME: doc strings for commands have to be translatable
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
38 # plugins need a dynamic translation system (translation
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
39 # 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
40
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
41 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
42 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
43 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
44 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
45
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
46 def sendMessageTrigger(self, mess_data, profile):
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
47 """ Check text commands in message, and react consequently """
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
48 msg = mess_data["message"]
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
49 if msg:
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
50 if msg[0] == '/':
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
51 command = msg[1:].partition(' ')[0].lower()
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
52 if command.isalpha():
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
53 # looks like an actual command, we try to call the corresponding method
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
54 try:
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
55 mess_data["unparsed"] = msg[1+len(command):] #part not yet parsed of the message
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
56 return getattr(self,"cmd_%s" % command)(mess_data,profile)
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
57 except AttributeError:
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
58 pass
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
59 elif msg[0] == '\\': #we have escape char
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
60 try:
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
61 if msg[1] in ('/','\\'): # we have '\/' or '\\', we escape to '/' or '\'
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
62 mess_data["message"] = msg[1:]
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
63 except IndexError:
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
64 pass
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
65 return True
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
66
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
67 def _getRoomJID(self, arg, service_jid):
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
68 """Return a room jid with a shortcut
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
69 @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
70 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
71 @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
72 """
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
73 nb_arobas = arg.count('@')
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
74 if nb_arobas == 1:
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
75 if arg[-1] !='@':
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
76 return jid.JID(arg)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
77 return jid.JID(arg+service_jid)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
78 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
79
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
80 def cmd_nick(self, mess_data, profile):
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
81 """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
82 debug("Catched nick command")
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
83
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
84 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
85 #/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
86 info("Ignoring /nick command on a non groupchat message")
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
87
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
88 return True
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
89
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
90 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
91 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
92
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.host.plugins["XEP-0045"].nick(room,nick,profile)
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
94
2e43c74815ad plugin text commands: Text commands is a new plugin that bring IRC-like commands
Goffi <goffi@goffi.org>
parents:
diff changeset
95 return False
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
96
509
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
97 def cmd_join(self, mess_data, profile):
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
98 """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
99 debug("Catched join command")
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
100
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
101 if mess_data['type'] != "groupchat":
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
102 #/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
103 info("Ignoring /join command on a non groupchat message")
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
104 return True
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
105
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
106 if mess_data["unparsed"].strip():
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
107 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
108 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
109 self.host.getClient(profile).jid.user)
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
110 self.host.plugins["XEP-0045"].join(room, nick, {}, profile)
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
111
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
112 return False
64ff046dc201 plugin text commands: added /join command
Goffi <goffi@goffi.org>
parents: 508
diff changeset
113
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
114 def cmd_leave(self, mess_data, profile):
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
115 """quit a room"""
508
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
116 debug("Catched leave command")
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
117
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
118 if mess_data['type'] != "groupchat":
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
119 #/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
120 info("Ignoring /leave command on a non groupchat message")
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
121 return True
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
122
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
123 if mess_data["unparsed"].strip():
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
124 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
125 else:
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
126 room = mess_data["to"]
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
127
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
128 self.host.plugins["XEP-0045"].leave(room,profile)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
129
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
130 return False
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
131
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
132 def cmd_part(self, mess_data, profile):
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
133 """just a synonym of /leave"""
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
134 return self.cmd_leave(mess_data, profile)
7c6609dddb2c plugin text commands: /leave management:
Goffi <goffi@goffi.org>
parents: 506
diff changeset
135
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
136 def cmd_title(self, mess_data, profile):
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
137 """Change room's subject"""
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
138 debug("Catched title command")
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
139
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
140 if mess_data['type'] != "groupchat":
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
141 #/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
142 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
143 return True
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
144
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
145 subject = mess_data["unparsed"].strip()
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
146
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
147 if subject:
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
148 room = mess_data["to"]
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
149 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
150
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
151 return False
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
152
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
153 def cmd_help(self, mess_data, profile):
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
154 """show help on available commands"""
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
155 commands=filter(lambda method: method.startswith('cmd_'), dir(self))
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
156 longuest = max([len(command) for command in commands])
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
157 help_cmds = []
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
158
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
159 for command in commands:
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
160 method = getattr(self, command)
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
161 try:
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
162 help_str = method.__doc__.split('\n')[0]
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
163 except AttributeError:
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
164 help_str = ''
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
165 spaces = (longuest - len(command)) * ' '
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
166 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
167
519
b7577230a7c8 reverted bad commit
Goffi <goffi@goffi.org>
parents: 518
diff changeset
168 if mess_data["type"] == 'groupchat':
b7577230a7c8 reverted bad commit
Goffi <goffi@goffi.org>
parents: 518
diff changeset
169 _from = mess_data["to"].userhostJID()
b7577230a7c8 reverted bad commit
Goffi <goffi@goffi.org>
parents: 518
diff changeset
170 else:
b7577230a7c8 reverted bad commit
Goffi <goffi@goffi.org>
parents: 518
diff changeset
171 _from = self.host.getJidNStream(profile)[0]
b7577230a7c8 reverted bad commit
Goffi <goffi@goffi.org>
parents: 518
diff changeset
172
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
173 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),)
519
b7577230a7c8 reverted bad commit
Goffi <goffi@goffi.org>
parents: 518
diff changeset
174
b7577230a7c8 reverted bad commit
Goffi <goffi@goffi.org>
parents: 518
diff changeset
175 self.host.bridge.newMessage(unicode(mess_data["to"]), help_mess, mess_data['type'], unicode(_from), {}, profile=profile)
b7577230a7c8 reverted bad commit
Goffi <goffi@goffi.org>
parents: 518
diff changeset
176
517
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
177
59b32c04e105 plugin text commands: added /help command
Goffi <goffi@goffi.org>
parents: 515
diff changeset
178