2010-03-18 07:29:44 +01:00
|
|
|
# Copyright (C) 2009-2010 Alexander Cherniuk <ts33kr@gmail.com>
|
2009-09-12 15:51:21 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""
|
2009-10-02 22:57:11 +02:00
|
|
|
Provides an actual implementation for the standard commands.
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
|
|
|
|
2009-11-19 06:39:04 +01:00
|
|
|
from time import localtime, strftime
|
|
|
|
from datetime import date
|
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import dialogs
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import helpers
|
2018-09-13 23:56:12 +02:00
|
|
|
from gajim.common.i18n import _
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common.exceptions import GajimGeneralException
|
2018-04-23 18:32:01 +02:00
|
|
|
from gajim.common.const import KindConstant
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.command_system.errors import CommandError
|
|
|
|
from gajim.command_system.framework import CommandContainer, command, doc
|
|
|
|
from gajim.command_system.mapping import generate_usage
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.command_system.implementation.hosts import ChatCommands, PrivateChatCommands, GroupChatCommands
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
class StandardCommonCommands(CommandContainer):
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
2010-02-26 11:35:09 +01:00
|
|
|
This command container contains standard commands which are common
|
|
|
|
to all - chat, private chat, group chat.
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
|
|
|
|
2010-08-05 20:47:46 +02:00
|
|
|
AUTOMATIC = True
|
2010-08-04 10:08:24 +02:00
|
|
|
HOSTS = ChatCommands, PrivateChatCommands, GroupChatCommands
|
2009-10-02 22:57:11 +02:00
|
|
|
|
2009-09-17 03:38:39 +02:00
|
|
|
@command(overlap=True)
|
2010-08-05 13:06:36 +02:00
|
|
|
@doc(_("Show help on a given command or a list of available commands if -a is given"))
|
2009-09-12 15:51:21 +02:00
|
|
|
def help(self, command=None, all=False):
|
|
|
|
if command:
|
2009-10-02 22:57:11 +02:00
|
|
|
command = self.get_command(command)
|
|
|
|
|
|
|
|
documentation = _(command.extract_documentation())
|
|
|
|
usage = generate_usage(command)
|
|
|
|
|
2009-10-04 18:56:07 +02:00
|
|
|
text = []
|
2009-10-02 22:57:11 +02:00
|
|
|
|
|
|
|
if documentation:
|
2009-10-04 18:56:07 +02:00
|
|
|
text.append(documentation)
|
2009-10-02 22:57:11 +02:00
|
|
|
if command.usage:
|
2009-10-04 18:56:07 +02:00
|
|
|
text.append(usage)
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2009-10-04 18:56:07 +02:00
|
|
|
return '\n\n'.join(text)
|
2009-09-12 15:51:21 +02:00
|
|
|
elif all:
|
|
|
|
for command in self.list_commands():
|
|
|
|
names = ', '.join(command.names)
|
|
|
|
description = command.extract_description()
|
|
|
|
|
|
|
|
self.echo("%s - %s" % (names, description))
|
|
|
|
else:
|
2009-10-02 22:57:11 +02:00
|
|
|
help = self.get_command('help')
|
|
|
|
self.echo(help(self, 'help'))
|
2009-09-12 15:51:21 +02:00
|
|
|
|
|
|
|
@command(raw=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Send a message to the contact"))
|
2009-09-12 15:51:21 +02:00
|
|
|
def say(self, message):
|
|
|
|
self.send(message)
|
|
|
|
|
|
|
|
@command(raw=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Send action (in the third person) to the current chat"))
|
2009-09-12 15:51:21 +02:00
|
|
|
def me(self, action):
|
|
|
|
self.send("/me %s" % action)
|
|
|
|
|
2009-11-19 06:39:04 +01:00
|
|
|
@command('lastlog', overlap=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Show logged messages which mention given text"))
|
2009-11-19 06:39:04 +01:00
|
|
|
def grep(self, text, limit=None):
|
2017-08-13 13:18:56 +02:00
|
|
|
results = app.logger.search_log(self.account, self.contact.jid, text)
|
2009-11-19 06:39:04 +01:00
|
|
|
|
|
|
|
if not results:
|
|
|
|
raise CommandError(_("%s: Nothing found") % text)
|
|
|
|
|
|
|
|
if limit:
|
|
|
|
try:
|
|
|
|
results = results[len(results) - int(limit):]
|
|
|
|
except ValueError:
|
|
|
|
raise CommandError(_("Limit must be an integer"))
|
|
|
|
|
|
|
|
for row in results:
|
2017-03-23 22:56:54 +01:00
|
|
|
contact = row.contact_name
|
2009-11-19 06:39:04 +01:00
|
|
|
if not contact:
|
2017-03-23 22:56:54 +01:00
|
|
|
if row.kind == KindConstant.CHAT_MSG_SENT:
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.nicks[self.account]
|
2009-11-19 06:39:04 +01:00
|
|
|
else:
|
|
|
|
contact = self.contact.name
|
|
|
|
|
2017-03-23 22:56:54 +01:00
|
|
|
time_obj = localtime(row.time)
|
|
|
|
date_obj = date.fromtimestamp(row.time)
|
2009-11-19 06:39:04 +01:00
|
|
|
date_ = strftime('%Y-%m-%d', time_obj)
|
|
|
|
time_ = strftime('%H:%M:%S', time_obj)
|
|
|
|
|
|
|
|
if date_obj == date.today():
|
2017-03-23 22:56:54 +01:00
|
|
|
formatted = "[%s] %s: %s" % (time_, contact, row.message)
|
2009-11-19 06:39:04 +01:00
|
|
|
else:
|
2017-03-23 22:56:54 +01:00
|
|
|
formatted = "[%s, %s] %s: %s" % (date_, time_, contact, row.message)
|
2009-11-19 06:39:04 +01:00
|
|
|
|
|
|
|
self.echo(formatted)
|
|
|
|
|
2009-12-22 20:31:11 +01:00
|
|
|
@command(raw=True, empty=True)
|
2013-08-14 14:56:15 +02:00
|
|
|
#Do not translate online, away, chat, xa, dnd
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("""
|
2012-07-28 20:46:11 +02:00
|
|
|
Set the current status
|
2009-12-22 20:31:11 +01:00
|
|
|
|
2012-09-23 21:59:26 +02:00
|
|
|
Status can be given as one of the following values:
|
|
|
|
online, away, chat, xa, dnd.
|
2009-12-22 20:31:11 +01:00
|
|
|
"""))
|
|
|
|
def status(self, status, message):
|
|
|
|
if status not in ('online', 'away', 'chat', 'xa', 'dnd'):
|
|
|
|
raise CommandError("Invalid status given")
|
2017-08-13 13:18:56 +02:00
|
|
|
for connection in app.connections.values():
|
|
|
|
if not app.config.get_per('accounts', connection.name,
|
2012-02-14 21:49:48 +01:00
|
|
|
'sync_with_global_status'):
|
|
|
|
continue
|
2012-02-15 20:22:46 +01:00
|
|
|
if connection.connected < 2:
|
2012-02-14 21:49:48 +01:00
|
|
|
continue
|
2009-12-22 20:31:11 +01:00
|
|
|
connection.change_status(status, message)
|
|
|
|
|
|
|
|
@command(raw=True, empty=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Set the current status to away"))
|
2009-12-22 20:31:11 +01:00
|
|
|
def away(self, message):
|
|
|
|
if not message:
|
|
|
|
message = _("Away")
|
2012-02-14 21:49:48 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
for connection in app.connections.values():
|
|
|
|
if not app.config.get_per('accounts', connection.name,
|
2012-02-14 21:49:48 +01:00
|
|
|
'sync_with_global_status'):
|
|
|
|
continue
|
2012-02-15 20:22:46 +01:00
|
|
|
if connection.connected < 2:
|
2012-02-14 21:49:48 +01:00
|
|
|
continue
|
2009-12-22 20:31:11 +01:00
|
|
|
connection.change_status('away', message)
|
|
|
|
|
|
|
|
@command('back', raw=True, empty=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Set the current status to online"))
|
2009-12-22 20:31:11 +01:00
|
|
|
def online(self, message):
|
|
|
|
if not message:
|
|
|
|
message = _("Available")
|
2012-02-14 21:49:48 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
for connection in app.connections.values():
|
|
|
|
if not app.config.get_per('accounts', connection.name,
|
2012-02-14 21:49:48 +01:00
|
|
|
'sync_with_global_status'):
|
|
|
|
continue
|
2012-02-15 20:22:46 +01:00
|
|
|
if connection.connected < 2:
|
2012-02-14 21:49:48 +01:00
|
|
|
continue
|
2009-12-22 20:31:11 +01:00
|
|
|
connection.change_status('online', message)
|
|
|
|
|
2010-03-18 09:45:56 +01:00
|
|
|
class StandardCommonChatCommands(CommandContainer):
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
2018-06-22 00:47:29 +02:00
|
|
|
This command container contains standard commands, which are common
|
2010-03-18 09:45:56 +01:00
|
|
|
to a chat and a private chat only.
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
|
|
|
|
2010-08-05 20:47:46 +02:00
|
|
|
AUTOMATIC = True
|
2010-08-04 10:08:24 +02:00
|
|
|
HOSTS = ChatCommands, PrivateChatCommands
|
2010-03-18 09:45:56 +01:00
|
|
|
|
2011-11-29 11:55:06 +01:00
|
|
|
@command
|
|
|
|
@doc(_("Clear the text window"))
|
|
|
|
def clear(self):
|
|
|
|
self.conv_textview.clear()
|
|
|
|
|
2009-09-12 15:51:21 +02:00
|
|
|
@command
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Send a ping to the contact"))
|
2009-09-12 15:51:21 +02:00
|
|
|
def ping(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
if self.account == app.ZEROCONF_ACC_NAME:
|
2009-09-12 22:22:50 +02:00
|
|
|
raise CommandError(_('Command is not supported for zeroconf accounts'))
|
2018-06-24 23:22:49 +02:00
|
|
|
app.connections[self.account].get_module('Ping').send_ping(self.contact)
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2010-01-10 07:42:08 +01:00
|
|
|
@command
|
2010-08-07 16:26:12 +02:00
|
|
|
@doc(_("Send DTMF sequence through an open audio session"))
|
|
|
|
def dtmf(self, sequence):
|
2009-11-13 22:58:02 +01:00
|
|
|
if not self.audio_sid:
|
2010-08-07 16:26:12 +02:00
|
|
|
raise CommandError(_("No open audio sessions with the contact"))
|
|
|
|
for tone in sequence:
|
|
|
|
if not (tone in ("*", "#") or tone.isdigit()):
|
|
|
|
raise CommandError(_("%s is not a valid tone") % tone)
|
|
|
|
gjs = self.connection.get_jingle_session
|
|
|
|
session = gjs(self.full_jid, self.audio_sid)
|
|
|
|
content = session.get_content("audio")
|
|
|
|
content.batch_dtmf(sequence)
|
2009-11-13 22:58:02 +01:00
|
|
|
|
2010-01-10 07:42:08 +01:00
|
|
|
@command
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Toggle audio session"))
|
2009-11-10 22:06:59 +01:00
|
|
|
def audio(self):
|
2010-03-21 21:45:45 +01:00
|
|
|
if not self.audio_available:
|
|
|
|
raise CommandError(_("Audio sessions are not available"))
|
2010-08-07 16:37:14 +02:00
|
|
|
# An audio session is toggled by inverting the state of the
|
|
|
|
# appropriate button.
|
|
|
|
state = self._audio_button.get_active()
|
|
|
|
self._audio_button.set_active(not state)
|
2009-11-10 22:06:59 +01:00
|
|
|
|
2010-01-10 07:42:08 +01:00
|
|
|
@command
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Toggle video session"))
|
2009-11-10 22:06:59 +01:00
|
|
|
def video(self):
|
2010-03-21 21:45:45 +01:00
|
|
|
if not self.video_available:
|
2009-11-10 22:06:59 +01:00
|
|
|
raise CommandError(_("Video sessions are not available"))
|
2010-08-07 16:37:14 +02:00
|
|
|
# A video session is toggled by inverting the state of the
|
|
|
|
# appropriate button.
|
|
|
|
state = self._video_button.get_active()
|
|
|
|
self._video_button.set_active(not state)
|
2009-11-10 22:06:59 +01:00
|
|
|
|
2012-04-09 13:38:28 +02:00
|
|
|
@command(raw=True)
|
2018-07-11 22:15:56 +02:00
|
|
|
@doc(_("Send a message to the contact that will attract their attention"))
|
2012-04-09 13:38:28 +02:00
|
|
|
def attention(self, message):
|
|
|
|
self.send_message(message, process_commands=False, attention=True)
|
|
|
|
|
2010-03-18 09:45:56 +01:00
|
|
|
class StandardChatCommands(CommandContainer):
|
|
|
|
"""
|
|
|
|
This command container contains standard commands which are unique
|
|
|
|
to a chat.
|
|
|
|
"""
|
|
|
|
|
2010-08-05 20:47:46 +02:00
|
|
|
AUTOMATIC = True
|
2010-08-07 15:38:05 +02:00
|
|
|
HOSTS = ChatCommands,
|
2010-03-18 09:45:56 +01:00
|
|
|
|
2009-10-02 22:57:11 +02:00
|
|
|
class StandardPrivateChatCommands(CommandContainer):
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
2010-03-18 09:45:56 +01:00
|
|
|
This command container contains standard commands which are unique
|
|
|
|
to a private chat.
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
|
|
|
|
2010-08-05 20:47:46 +02:00
|
|
|
AUTOMATIC = True
|
2010-08-07 15:38:05 +02:00
|
|
|
HOSTS = PrivateChatCommands,
|
2009-09-12 15:51:21 +02:00
|
|
|
|
2010-03-18 09:45:56 +01:00
|
|
|
class StandardGroupChatCommands(CommandContainer):
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
2010-03-18 09:45:56 +01:00
|
|
|
This command container contains standard commands which are unique
|
|
|
|
to a group chat.
|
2009-09-12 15:51:21 +02:00
|
|
|
"""
|
|
|
|
|
2010-08-05 20:47:46 +02:00
|
|
|
AUTOMATIC = True
|
2010-08-07 15:38:05 +02:00
|
|
|
HOSTS = GroupChatCommands,
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2011-11-29 11:55:06 +01:00
|
|
|
@command
|
|
|
|
@doc(_("Clear the text window"))
|
|
|
|
def clear(self):
|
|
|
|
self.conv_textview.clear()
|
|
|
|
self.gc_count_nicknames_colors = -1
|
|
|
|
self.gc_custom_colors = {}
|
|
|
|
|
2009-09-13 16:43:44 +02:00
|
|
|
@command(raw=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Change your nickname in a group chat"))
|
2009-09-13 16:43:44 +02:00
|
|
|
def nick(self, new_nick):
|
|
|
|
try:
|
|
|
|
new_nick = helpers.parse_resource(new_nick)
|
|
|
|
except Exception:
|
|
|
|
raise CommandError(_("Invalid nickname"))
|
|
|
|
self.connection.join_gc(new_nick, self.room_jid, None, change_nick=True)
|
2009-09-15 21:59:48 +02:00
|
|
|
self.new_nick = new_nick
|
2009-09-13 16:43:44 +02:00
|
|
|
|
|
|
|
@command('query', raw=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Open a private chat window with a specified occupant"))
|
2009-09-13 16:43:44 +02:00
|
|
|
def chat(self, nick):
|
2017-08-13 13:18:56 +02:00
|
|
|
nicks = app.contacts.get_nick_list(self.account, self.room_jid)
|
2009-09-13 16:43:44 +02:00
|
|
|
if nick in nicks:
|
|
|
|
self.on_send_pm(nick=nick)
|
|
|
|
else:
|
|
|
|
raise CommandError(_("Nickname not found"))
|
|
|
|
|
2009-09-17 03:38:39 +02:00
|
|
|
@command('msg', raw=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Open a private chat window with a specified occupant and send him a message"))
|
2009-09-17 03:38:39 +02:00
|
|
|
def message(self, nick, a_message):
|
2017-08-13 13:18:56 +02:00
|
|
|
nicks = app.contacts.get_nick_list(self.account, self.room_jid)
|
2009-09-13 16:43:44 +02:00
|
|
|
if nick in nicks:
|
|
|
|
self.on_send_pm(nick=nick, msg=a_message)
|
|
|
|
else:
|
|
|
|
raise CommandError(_("Nickname not found"))
|
|
|
|
|
|
|
|
@command(raw=True, empty=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Display or change a group chat topic"))
|
2009-09-13 16:43:44 +02:00
|
|
|
def topic(self, new_topic):
|
|
|
|
if new_topic:
|
2018-07-21 12:21:48 +02:00
|
|
|
self.connection.get_module('MUC').set_subject(
|
|
|
|
self.room_jid, new_topic)
|
2009-09-13 16:43:44 +02:00
|
|
|
else:
|
|
|
|
return self.subject
|
|
|
|
|
2009-09-17 03:38:39 +02:00
|
|
|
@command(raw=True, empty=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Invite a user to a room for a reason"))
|
2009-09-17 03:38:39 +02:00
|
|
|
def invite(self, jid, reason):
|
2018-07-16 23:22:33 +02:00
|
|
|
self.connection.get_module('MUC').invite(self.room_jid, jid, reason)
|
2017-09-19 12:45:02 +02:00
|
|
|
return _("Invited %(jid)s to %(room_jid)s") % {'jid': jid,
|
|
|
|
'room_jid': self.room_jid}
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2009-09-17 03:38:39 +02:00
|
|
|
@command(raw=True, empty=True)
|
2018-03-25 16:26:29 +02:00
|
|
|
@doc(_("Join a group chat given by a JID"))
|
2017-11-25 15:33:54 +01:00
|
|
|
def join(self, jid):
|
2009-09-13 16:43:44 +02:00
|
|
|
if '@' not in jid:
|
2017-08-13 13:18:56 +02:00
|
|
|
jid = jid + '@' + app.get_server_from_jid(self.room_jid)
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2017-11-25 15:33:54 +01:00
|
|
|
app.interface.join_gc_minimal(self.account, room_jid=jid)
|
2009-09-13 16:43:44 +02:00
|
|
|
|
|
|
|
@command('part', 'close', raw=True, empty=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Leave the groupchat, optionally giving a reason, and close tab or window"))
|
2009-09-13 16:43:44 +02:00
|
|
|
def leave(self, reason):
|
|
|
|
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND, reason)
|
|
|
|
|
2009-10-05 11:55:34 +02:00
|
|
|
@command(raw=True, empty=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("""
|
2018-03-25 16:26:29 +02:00
|
|
|
Ban user by a nick or a JID from a groupchat
|
2009-10-04 19:43:51 +02:00
|
|
|
|
2018-03-25 16:26:29 +02:00
|
|
|
If given nickname is not found it will be treated as a JID.
|
2009-10-04 19:43:51 +02:00
|
|
|
"""))
|
2018-07-21 12:21:48 +02:00
|
|
|
def ban(self, who, reason=''):
|
2017-08-13 13:18:56 +02:00
|
|
|
if who in app.contacts.get_nick_list(self.account, self.room_jid):
|
|
|
|
contact = app.contacts.get_gc_contact(self.account, self.room_jid, who)
|
2009-09-13 16:43:44 +02:00
|
|
|
who = contact.jid
|
2018-07-21 12:21:48 +02:00
|
|
|
self.connection.get_module('MUC').set_affiliation(
|
|
|
|
self.room_jid,
|
|
|
|
{who: {'affiliation': 'outcast',
|
|
|
|
'reason': reason}})
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2009-09-17 03:38:39 +02:00
|
|
|
@command(raw=True, empty=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Kick user by a nick from a groupchat"))
|
2009-09-17 03:38:39 +02:00
|
|
|
def kick(self, who, reason):
|
2017-08-13 13:18:56 +02:00
|
|
|
if not who in app.contacts.get_nick_list(self.account, self.room_jid):
|
2009-09-13 16:43:44 +02:00
|
|
|
raise CommandError(_("Nickname not found"))
|
2018-07-21 12:21:48 +02:00
|
|
|
self.connection.get_module('MUC').set_role(
|
|
|
|
self.room_jid, who, 'none', reason or str())
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2012-08-11 12:59:05 +02:00
|
|
|
@command(raw=True)
|
2013-08-14 14:56:15 +02:00
|
|
|
#Do not translate moderator, participant, visitor, none
|
2012-08-11 12:59:05 +02:00
|
|
|
@doc(_("""Set occupant role in group chat.
|
|
|
|
Role can be given as one of the following values:
|
|
|
|
moderator, participant, visitor, none"""))
|
|
|
|
def role(self, who, role):
|
|
|
|
if role not in ('moderator', 'participant', 'visitor', 'none'):
|
|
|
|
raise CommandError(_("Invalid role given"))
|
2017-08-13 13:18:56 +02:00
|
|
|
if not who in app.contacts.get_nick_list(self.account, self.room_jid):
|
2012-08-11 12:59:05 +02:00
|
|
|
raise CommandError(_("Nickname not found"))
|
2018-07-21 12:21:48 +02:00
|
|
|
self.connection.get_module('MUC').set_role(self.room_jid, who, role)
|
2012-08-11 12:59:05 +02:00
|
|
|
|
|
|
|
@command(raw=True)
|
2013-08-14 14:56:15 +02:00
|
|
|
#Do not translate owner, admin, member, outcast, none
|
2012-08-11 12:59:05 +02:00
|
|
|
@doc(_("""Set occupant affiliation in group chat.
|
|
|
|
Affiliation can be given as one of the following values:
|
|
|
|
owner, admin, member, outcast, none"""))
|
|
|
|
def affiliate(self, who, affiliation):
|
|
|
|
if affiliation not in ('owner', 'admin', 'member', 'outcast', 'none'):
|
|
|
|
raise CommandError(_("Invalid affiliation given"))
|
2018-07-21 12:21:48 +02:00
|
|
|
if who not in app.contacts.get_nick_list(self.account, self.room_jid):
|
2012-08-11 12:59:05 +02:00
|
|
|
raise CommandError(_("Nickname not found"))
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_gc_contact(self.account, self.room_jid, who)
|
2018-07-21 12:21:48 +02:00
|
|
|
|
|
|
|
self.connection.get_module('MUC').set_affiliation(
|
|
|
|
self.room_jid,
|
|
|
|
{contact.jid: {'affiliation': affiliation}})
|
2012-08-11 12:59:05 +02:00
|
|
|
|
2009-09-13 16:43:44 +02:00
|
|
|
@command
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Display names of all group chat occupants"))
|
2009-09-13 16:43:44 +02:00
|
|
|
def names(self, verbose=False):
|
2017-08-13 13:18:56 +02:00
|
|
|
ggc = app.contacts.get_gc_contact
|
|
|
|
gnl = app.contacts.get_nick_list
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2010-08-07 15:38:05 +02:00
|
|
|
get_contact = lambda nick: ggc(self.account, self.room_jid, nick)
|
|
|
|
get_role = lambda nick: get_contact(nick).role
|
|
|
|
nicks = gnl(self.account, self.room_jid)
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2010-08-07 15:38:05 +02:00
|
|
|
nicks = sorted(nicks)
|
|
|
|
nicks = sorted(nicks, key=get_role)
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2010-08-07 15:38:05 +02:00
|
|
|
if not verbose:
|
|
|
|
return ", ".join(nicks)
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2010-08-07 15:38:05 +02:00
|
|
|
for nick in nicks:
|
|
|
|
contact = get_contact(nick)
|
|
|
|
role = helpers.get_uf_role(contact.role)
|
|
|
|
affiliation = helpers.get_uf_affiliation(contact.affiliation)
|
|
|
|
self.echo("%s - %s - %s" % (nick, role, affiliation))
|
2009-09-13 16:43:44 +02:00
|
|
|
|
2009-10-04 21:11:19 +02:00
|
|
|
@command('ignore', raw=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Forbid an occupant to send you public or private messages"))
|
2009-09-13 16:43:44 +02:00
|
|
|
def block(self, who):
|
|
|
|
self.on_block(None, who)
|
|
|
|
|
2009-10-04 21:11:19 +02:00
|
|
|
@command('unignore', raw=True)
|
2010-03-19 02:22:17 +01:00
|
|
|
@doc(_("Allow an occupant to send you public or private messages"))
|
2009-09-13 16:43:44 +02:00
|
|
|
def unblock(self, who):
|
2011-11-29 11:55:06 +01:00
|
|
|
self.on_unblock(None, who)
|
2014-08-22 15:44:07 +02:00
|
|
|
|
|
|
|
@command
|
|
|
|
@doc(_("Send a ping to the contact"))
|
|
|
|
def ping(self, nick):
|
2017-08-13 13:18:56 +02:00
|
|
|
if self.account == app.ZEROCONF_ACC_NAME:
|
2014-08-22 15:44:07 +02:00
|
|
|
raise CommandError(_('Command is not supported for zeroconf accounts'))
|
2017-08-13 13:18:56 +02:00
|
|
|
gc_c = app.contacts.get_gc_contact(self.account, self.room_jid, nick)
|
2018-06-24 23:22:49 +02:00
|
|
|
app.connections[self.account].get_module('Ping').send_ping(gc_c)
|
2014-08-22 15:44:07 +02:00
|
|
|
|