1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Provides an actual implementation for the standard commands.
18 """
19
20 from time import localtime, strftime
21 from datetime import date
22
23 import dialogs
24 from common import gajim
25 from common import helpers
26 from common.exceptions import GajimGeneralException
27 from common.logger import Constants
28
29 from ..errors import CommandError
30 from ..framework import CommandContainer, command, doc
31 from ..mapping import generate_usage
32
33 from hosts import *
34 import execute
41 """
42 This command container contains standard commands which are common
43 to all - chat, private chat, group chat.
44 """
45
46 AUTOMATIC = True
47 HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands
48
49 @command
50 @doc(_("Clear the text window"))
52 self.conv_textview.clear()
53
54 @command
55 @doc(_("Hide the chat buttons"))
59
60 @command(overlap=True)
61 @doc(_("Show help on a given command or a list of available commands if -a is given"))
62 - def help(self, command=None, all=False):
86
87 @command(raw=True)
88 @doc(_("Send a message to the contact"))
89 - def say(self, message):
91
92 @command(raw=True)
93 @doc(_("Send action (in the third person) to the current chat"))
94 - def me(self, action):
95 self.send("/me %s" % action)
96
97 @command('lastlog', overlap=True)
98 @doc(_("Show logged messages which mention given text"))
99 - def grep(self, text, limit=None):
100 results = gajim.logger.get_search_results_for_query(self.contact.jid,
101 text, self.account)
102
103 if not results:
104 raise CommandError(_("%s: Nothing found") % text)
105
106 if limit:
107 try:
108 results = results[len(results) - int(limit):]
109 except ValueError:
110 raise CommandError(_("Limit must be an integer"))
111
112 for row in results:
113 contact, time, kind, show, message, subject = row
114
115 if not contact:
116 if kind == lc.KIND_CHAT_MSG_SENT:
117 contact = gajim.nicks[self.account]
118 else:
119 contact = self.contact.name
120
121 time_obj = localtime(time)
122 date_obj = date.fromtimestamp(time)
123 date_ = strftime('%Y-%m-%d', time_obj)
124 time_ = strftime('%H:%M:%S', time_obj)
125
126 if date_obj == date.today():
127 formatted = "[%s] %s: %s" % (time_, contact, message)
128 else:
129 formatted = "[%s, %s] %s: %s" % (date_, time_, contact, message)
130
131 self.echo(formatted)
132
133 @command(raw=True, empty=True)
134 @doc(_("""
135 Set current the status
136
137 Status can be given as one of the following values: online, away,
138 chat, xa, dnd.
139 """))
140 - def status(self, status, message):
145
146 @command(raw=True, empty=True)
147 @doc(_("Set the current status to away"))
148 - def away(self, message):
153
154 @command('back', raw=True, empty=True)
155 @doc(_("Set the current status to online"))
161
163 """
164 This command container contans standard commands, which are common
165 to a chat and a private chat only.
166 """
167
168 AUTOMATIC = True
169 HOSTS = ChatCommands, PrivateChatCommands
170
171 @command
172 @doc(_("Toggle the GPG encryption"))
175
176 @command
177 @doc(_("Send a ping to the contact"))
182
183 @command
184 @doc(_("Send DTMF sequence through an open audio session"))
185 - def dtmf(self, sequence):
195
196 @command
197 @doc(_("Toggle audio session"))
199 if not self.audio_available:
200 raise CommandError(_("Audio sessions are not available"))
201
202
203 state = self._audio_button.get_active()
204 self._audio_button.set_active(not state)
205
206 @command
207 @doc(_("Toggle video session"))
209 if not self.video_available:
210 raise CommandError(_("Video sessions are not available"))
211
212
213 state = self._video_button.get_active()
214 self._video_button.set_active(not state)
215
217 """
218 This command container contains standard commands which are unique
219 to a chat.
220 """
221
222 AUTOMATIC = True
223 HOSTS = ChatCommands,
224
226 """
227 This command container contains standard commands which are unique
228 to a private chat.
229 """
230
231 AUTOMATIC = True
232 HOSTS = PrivateChatCommands,
233
235 """
236 This command container contains standard commands which are unique
237 to a group chat.
238 """
239
240 AUTOMATIC = True
241 HOSTS = GroupChatCommands,
242
243 @command(raw=True)
244 @doc(_("Change your nickname in a group chat"))
245 - def nick(self, new_nick):
252
253 @command('query', raw=True)
254 @doc(_("Open a private chat window with a specified occupant"))
255 - def chat(self, nick):
261
262 @command('msg', raw=True)
263 @doc(_("Open a private chat window with a specified occupant and send him a message"))
264 - def message(self, nick, a_message):
270
271 @command(raw=True, empty=True)
272 @doc(_("Display or change a group chat topic"))
273 - def topic(self, new_topic):
278
279 @command(raw=True, empty=True)
280 @doc(_("Invite a user to a room for a reason"))
281 - def invite(self, jid, reason):
282 self.connection.send_invite(self.room_jid, jid, reason)
283 return _("Invited %s to %s") % (jid, self.room_jid)
284
285 @command(raw=True, empty=True)
286 @doc(_("Join a group chat given by a jid, optionally using given nickname"))
287 - def join(self, jid, nick):
301
302 @command('part', 'close', raw=True, empty=True)
303 @doc(_("Leave the groupchat, optionally giving a reason, and close tab or window"))
304 - def leave(self, reason):
305 self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND, reason)
306
307 @command(raw=True, empty=True)
308 @doc(_("""
309 Ban user by a nick or a jid from a groupchat
310
311 If given nickname is not found it will be treated as a jid.
312 """))
313 - def ban(self, who, reason):
318
319 @command(raw=True, empty=True)
320 @doc(_("Kick user by a nick from a groupchat"))
321 - def kick(self, who, reason):
325
326 @command
327 @doc(_("Display names of all group chat occupants"))
328 - def names(self, verbose=False):
347
348 @command('ignore', raw=True)
349 @doc(_("Forbid an occupant to send you public or private messages"))
352
353 @command('unignore', raw=True)
354 @doc(_("Allow an occupant to send you public or private messages"))
357