* New groupchat "/" commands interpretation.
* Added help for all "/" commands (in groupchat) * Added "/join" to commands
This commit is contained in:
parent
dd67ba1006
commit
ed135f3207
|
@ -596,9 +596,11 @@ class SubscriptionRequestWindow:
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
|
||||||
class JoinGroupchatWindow:
|
class JoinGroupchatWindow:
|
||||||
def __init__(self, plugin, account, server = '', room = ''):
|
def __init__(self, plugin, account, server = '', room = '', nick = ''):
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
self.account = account
|
self.account = account
|
||||||
|
if nick == '':
|
||||||
|
nick = gajim.nicks[self.account]
|
||||||
if gajim.connections[account].connected < 2:
|
if gajim.connections[account].connected < 2:
|
||||||
ErrorDialog(_('You are not connected to the server'),
|
ErrorDialog(_('You are not connected to the server'),
|
||||||
_('You can not join a group chat unless you are connected.')).get_response()
|
_('You can not join a group chat unless you are connected.')).get_response()
|
||||||
|
@ -608,7 +610,7 @@ _('You can not join a group chat unless you are connected.')).get_response()
|
||||||
self.window = self.xml.get_widget('join_groupchat_window')
|
self.window = self.xml.get_widget('join_groupchat_window')
|
||||||
self.xml.get_widget('server_entry').set_text(server)
|
self.xml.get_widget('server_entry').set_text(server)
|
||||||
self.xml.get_widget('room_entry').set_text(room)
|
self.xml.get_widget('room_entry').set_text(room)
|
||||||
self.xml.get_widget('nickname_entry').set_text(gajim.nicks[self.account])
|
self.xml.get_widget('nickname_entry').set_text(nick)
|
||||||
self.xml.signal_autoconnect(self)
|
self.xml.signal_autoconnect(self)
|
||||||
self.plugin.windows[account]['join_gc'] = self #now add us to open windows
|
self.plugin.windows[account]['join_gc'] = self #now add us to open windows
|
||||||
our_jid = gajim.config.get_per('accounts', self.account, 'name') + '@' + \
|
our_jid = gajim.config.get_per('accounts', self.account, 'name') + '@' + \
|
||||||
|
|
|
@ -49,8 +49,8 @@ class GroupchatWindow(chat.Chat):
|
||||||
chat.Chat.__init__(self, plugin, account, 'groupchat_window')
|
chat.Chat.__init__(self, plugin, account, 'groupchat_window')
|
||||||
|
|
||||||
# alphanum sorted
|
# alphanum sorted
|
||||||
self.muc_cmds = ['ban', 'chat', 'clear', 'close', 'compact', 'invite',
|
self.muc_cmds = ['ban', 'chat', 'query', 'clear', 'close', 'compact', 'help', 'invite',
|
||||||
'kick', 'leave', 'me', 'msg', 'nick', 'part', 'topic']
|
'join', 'kick', 'leave', 'me', 'msg', 'nick', 'part', 'topic']
|
||||||
|
|
||||||
self.nicks = {} # our nick for each groupchat we are in
|
self.nicks = {} # our nick for each groupchat we are in
|
||||||
self.list_treeview = {}
|
self.list_treeview = {}
|
||||||
|
@ -615,106 +615,168 @@ class GroupchatWindow(chat.Chat):
|
||||||
if message != '' or message != '\n':
|
if message != '' or message != '\n':
|
||||||
self.save_sent_message(room_jid, message)
|
self.save_sent_message(room_jid, message)
|
||||||
|
|
||||||
if message in ['/clear', '/clear ']:
|
if message.startswith('/') and not message.startswith('/me'):
|
||||||
self.on_clear(None, conversation_textview) # clear conversation
|
message = message[1:]
|
||||||
self.on_clear(None, message_textview) # clear message textview too
|
message_array = message.split(' ',1)
|
||||||
return
|
command = message_array.pop(0).lower()
|
||||||
|
if command == 'clear':
|
||||||
elif message in ('/compact', '/compact '):
|
self.on_clear(None, conversation_textview)
|
||||||
# toggle compact
|
self.on_clear(None, message_textview)
|
||||||
self.set_compact_view(not self.compact_view_current_state)
|
elif command == 'compact':
|
||||||
self.on_clear(None, message_textview)
|
self.set_compact_view(not self.compact_view_current_state)
|
||||||
return
|
self.on_clear(None, message_textview)
|
||||||
|
elif command == 'nick':
|
||||||
elif message.startswith('/nick '):
|
# example: /nick foo
|
||||||
new_nick = message[6:].strip() # 6 is len('/nick ')
|
if len(message_array):
|
||||||
if len(new_nick.split()) == 1: #dont accept /nick foo bar
|
gajim.connections[self.account].change_gc_nick(room_jid,
|
||||||
gajim.connections[self.account].change_gc_nick(room_jid,
|
nick)
|
||||||
new_nick)
|
else:
|
||||||
return # don't print the command
|
self.get_command_help(command)
|
||||||
|
elif command == 'query' or command == 'chat':
|
||||||
elif message.startswith('/chat '):#eg. /chat fooman
|
# example: /query foo
|
||||||
to_whom_nick = message[6:].strip() # 6 is len('/nick ')
|
if len(message_array):
|
||||||
if len(to_whom_nick.split()) == 1: #dont accept /chat foo bar
|
nick = message_array.pop(0)
|
||||||
nicks = self.get_nick_list(room_jid)
|
nicks = self.get_nick_list(room_jid)
|
||||||
if to_whom_nick in nicks:
|
if nick in nicks:
|
||||||
self.on_send_pm(nick=to_whom_nick)
|
self.on_send_pm(nick=nick)
|
||||||
return # don't print the command
|
else:
|
||||||
|
self.print_conversation('Nick not found: %s'%nick, room_jid)
|
||||||
elif message.startswith('/msg '): #eg. /msg fooman hello man what's up
|
else:
|
||||||
text_after_msg_command = message[5:].strip() # 5 is len('/msg ')
|
self.get_command_help(command)
|
||||||
splitted_text_after_msg_command = text_after_msg_command.split()
|
elif command == 'msg':
|
||||||
if len(splitted_text_after_msg_command) >= 2: #dont accept /msg foo
|
# example: /msg foo Hey, what's up?
|
||||||
nicks = self.get_nick_list(room_jid)
|
if len(message_array):
|
||||||
to_whom_nick = splitted_text_after_msg_command[0]
|
message_array = message_array[0].split()
|
||||||
if to_whom_nick in nicks:
|
nick = message_array.pop(0)
|
||||||
message = ' '.join(splitted_text_after_msg_command[1:])
|
room_nicks = self.get_nick_list(room_jid)
|
||||||
self.on_send_pm(nick=to_whom_nick, msg=message)
|
if nick in room_nicks:
|
||||||
return # don't print the command
|
privmsg = ' '.join(message_array)
|
||||||
|
self.on_send_pm(nick=nick, msg=privmsg)
|
||||||
elif message.startswith('/topic'):
|
else:
|
||||||
# eg. /topic Peace allover!
|
self.print_conversation('Nick not found: %s'%nick, room_jid)
|
||||||
# or /topic to get the subject printed
|
else:
|
||||||
after_command = message[6:] # 6 is len('/topic')
|
self.get_command_help(command)
|
||||||
splitted_arg = after_command.split()
|
elif command == 'topic':
|
||||||
if len(message) > 6 and not message[6].isspace():
|
# example: /topic : print topic
|
||||||
# he wrote /topicA so do not accept that
|
# /topic foo : change topic to foo
|
||||||
return
|
if len(message_array):
|
||||||
if len(splitted_arg): # we set subject
|
new_topic = message_array.pop(0)
|
||||||
new_subj = ' '.join(splitted_arg).strip()
|
gajim.connections[self.account].send_gc_subject(room_jid, new_topic)
|
||||||
gajim.connections[self.account].send_gc_subject(room_jid,
|
else:
|
||||||
new_subj)
|
self.print_conversation(self.subjects[room_jid], room_jid)
|
||||||
|
elif command == 'invite':
|
||||||
|
# example: /invite user@example.com reason
|
||||||
|
if len(message_array):
|
||||||
|
message_array = message_array[0].split()
|
||||||
|
invitee = message_array.pop(0)
|
||||||
|
if invitee.find('@') >= 0:
|
||||||
|
reason = ' '.join(message_array)
|
||||||
|
gajim.connections[self.account].send_invite(room_jid, invitee, reason)
|
||||||
|
self.print_conversation('invited %s.'%invitee, room_jid)
|
||||||
|
else:
|
||||||
|
self.print_conversation('%s doesn\'t appear to be a JID'%invitee, room_jid)
|
||||||
|
else:
|
||||||
|
self.get_command_help(command)
|
||||||
|
elif command == 'join':
|
||||||
|
# example: /join room@conference.example.com/nick
|
||||||
|
if len(message_array):
|
||||||
|
message_array = message_array[0]
|
||||||
|
if message_array.find('@') >= 0:
|
||||||
|
room, servernick = message_array.split('@')
|
||||||
|
if servernick.find('/') >= 0:
|
||||||
|
server, nick = servernick.split('/',1)
|
||||||
|
else:
|
||||||
|
server = servernick
|
||||||
|
nick = ''
|
||||||
|
if self.plugin.windows[self.account].has_key('join_gc'):
|
||||||
|
self.plugin.windows[self.account]['join_gc'].window.present()
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.plugin.windows[self.account]['join_gc'] = dialogs.JoinGroupchatWindow(self.plugin, self.account, server=server, room=room, nick=nick)
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.print_conversation('%s doesn\'t appear to be a JID'%message_array, room_jid)
|
||||||
|
else:
|
||||||
|
self.get_command_help(command)
|
||||||
|
elif command == 'leave' or command == 'part' or command == 'close':
|
||||||
|
# FIXME: This doesn't work, we don't leave the room. ick.
|
||||||
|
self.remove_tab(room_jid)
|
||||||
|
elif command == 'ban':
|
||||||
|
if len(message_array):
|
||||||
|
message_array = message_array[0].split()
|
||||||
|
nick = message_array.pop(0)
|
||||||
|
room_nicks = self.get_nick_list(room_jid)
|
||||||
|
reason = ' '.join(message_array)
|
||||||
|
if nick in room_nicks:
|
||||||
|
ban_jid = gajim.construct_fjid(room_jid, nick)
|
||||||
|
gajim.connections[self.account].gc_set_affiliation(room_jid, ban_jid, 'outcast', reason)
|
||||||
|
elif nick.find('@') >= 0:
|
||||||
|
gajim.connections[self.account].gc_set_affiliation(room_jid, nick, 'outcast', reason)
|
||||||
|
else:
|
||||||
|
self.print_conversation('Nick not found: %s'%nick, room_jid)
|
||||||
|
else:
|
||||||
|
self.get_command_help(command)
|
||||||
|
elif command == 'kick':
|
||||||
|
if len(message_array):
|
||||||
|
message_array = message_array[0].split()
|
||||||
|
nick = message_array.pop(0)
|
||||||
|
room_nicks = self.get_nick_list(room_jid)
|
||||||
|
reason = ' '.join(message_array)
|
||||||
|
if nick in room_nicks:
|
||||||
|
gajim.connections[self.account].gc_set_role(room_jid, nick, 'none', reason)
|
||||||
|
else:
|
||||||
|
self.print_conversation('Nick not found: %s'%nick, room_jid)
|
||||||
|
else:
|
||||||
|
self.get_command_help(command)
|
||||||
|
elif command == 'help':
|
||||||
|
if len(message_array):
|
||||||
|
subcommand = message_array.pop(0)
|
||||||
|
self.get_command_help(subcommand)
|
||||||
|
else:
|
||||||
|
self.get_command_help(command)
|
||||||
|
elif command == 'me':
|
||||||
|
if len(message_array):
|
||||||
|
gajim.connections[self.account].send_gc_message(room_jid, '/'+message)
|
||||||
|
else:
|
||||||
|
self.get_command_help(command)
|
||||||
else:
|
else:
|
||||||
# print it as green text
|
self.print_conversation('No such command: /%s'%command, room_jid)
|
||||||
self.print_conversation(self.subjects[room_jid], room_jid)
|
|
||||||
return # don't print the command
|
return # don't print the command
|
||||||
|
|
||||||
elif message.startswith('/invite'):
|
|
||||||
# /invite JID reason
|
|
||||||
after_command = message[7:] # 7 is len('/invite')
|
|
||||||
splitted_arg = after_command.split()
|
|
||||||
if len(splitted_arg):
|
|
||||||
jid_to_invite = splitted_arg[0]
|
|
||||||
reason = ' '.join(splitted_arg[1:])
|
|
||||||
gajim.connections[self.account].send_invite(room_jid,
|
|
||||||
jid_to_invite, reason)
|
|
||||||
return # don't print the command
|
|
||||||
|
|
||||||
#FIXME: we lack /join to adhere to JEP
|
|
||||||
|
|
||||||
elif message.startswith('/leave') or message.startswith('/part')\
|
|
||||||
or message.startswith('/close'):
|
|
||||||
# close current tab
|
|
||||||
#FIXME: accept optional reason (pas in status msg for this room)
|
|
||||||
# see JEP
|
|
||||||
room_jid = self.get_active_jid()
|
|
||||||
self.remove_tab(room_jid)
|
|
||||||
return # don't print the command
|
|
||||||
|
|
||||||
elif message.startswith('/ban '): #eg. /ban fooman he was a bad boy
|
|
||||||
text_after_ban_command = message[5:].strip() # 5 is len('/ban ')
|
|
||||||
splitted_text_after_ban_command = text_after_ban_command.split()
|
|
||||||
if len(splitted_text_after_ban_command) == 1:
|
|
||||||
# reason is optional so accept just nick
|
|
||||||
nick_to_ban = splitted_text_after_ban_command[0]
|
|
||||||
if nick_to_ban in nicks:
|
|
||||||
fjid = gajim.construct_fjid(room_jid, nick_to_ban)
|
|
||||||
gajim.connections[self.account].gc_set_affiliation(room_jid,
|
|
||||||
fjid, 'outcast')
|
|
||||||
elif len(splitted_text_after_ban_command) >= 2:
|
|
||||||
# a reason was given
|
|
||||||
nick_to_ban = splitted_text_after_ban_command[0]
|
|
||||||
if nick_to_ban in nicks:
|
|
||||||
reason = splitted_text_after_msg_command[1:]
|
|
||||||
fjid = gajim.construct_fjid(room_jid, nick_to_ban)
|
|
||||||
gajim.connections[self.account].gc_set_affiliation(room_jid,
|
|
||||||
fjid, 'outcast', reason)
|
|
||||||
return # don't print the command
|
|
||||||
|
|
||||||
gajim.connections[self.account].send_gc_message(room_jid, message)
|
gajim.connections[self.account].send_gc_message(room_jid, message)
|
||||||
message_buffer.set_text('')
|
|
||||||
message_textview.grab_focus()
|
message_textview.grab_focus()
|
||||||
|
|
||||||
|
def get_command_help(self, command):
|
||||||
|
room_jid = self.get_active_jid()
|
||||||
|
if command == 'help':
|
||||||
|
self.print_conversation('Commands: %s'%self.muc_cmds, room_jid)
|
||||||
|
elif command == 'ban':
|
||||||
|
self.print_conversation('Usage: /%s <nick|JID> [reason], bans the JID from the room. A nick may be used if present. If user is currently in the room, he/she/it will also be kicked. Does NOT support spaces in nick.'%command, room_jid)
|
||||||
|
elif command == 'chat' or command == 'query':
|
||||||
|
self.print_conversation('Usage: /%s <nick>, opens a private chat window to the specified user.'%command, room_jid)
|
||||||
|
elif command == 'clear':
|
||||||
|
self.print_conversation('Usage: /%s, clears the text window.'%command, room_jid)
|
||||||
|
elif command == 'close' or command == 'leave' or command == 'part':
|
||||||
|
self.print_conversation('Usage: /%s, closes the current window or tab.'%command, room_jid)
|
||||||
|
elif command == 'compact':
|
||||||
|
self.print_conversation('Usage: /%s, sets the groupchat window to compact mode.'%command, room_jid)
|
||||||
|
elif command == 'invite':
|
||||||
|
self.print_conversation('Usage: /%s <JID> [reason], invites JID to the current room with optional reason.'%command, room_jid)
|
||||||
|
elif command == 'join':
|
||||||
|
self.print_conversation('Usage: /%s <room>@<server>[/nick], offers to join room@server optionally using nick.'%command, room_jid)
|
||||||
|
elif command == 'kick':
|
||||||
|
self.print_conversation('Usage: /%s <nick> [reason], removes the user specified by nick from the room with optional reason. Does NOT support spaces in nick.'%command, room_jid)
|
||||||
|
elif command == 'me':
|
||||||
|
self.print_conversation('Usage: /%s <action>, sends the action to the current room. Use third person (e.g. /%s explodes)'%(command,command), room_jid)
|
||||||
|
elif command == 'msg':
|
||||||
|
self.print_conversation('Usage: /%s <nick> [message], opens a private message window and sends message to nick.'%command, room_jid)
|
||||||
|
elif command == 'nick':
|
||||||
|
self.print_conversation('Usage: /%s <nick>, changes your nickname.'%command, room_jid)
|
||||||
|
elif command == 'topic':
|
||||||
|
self.print_conversation('Usage: /%s [topic], displays the current room topic or changes it if specified.'%command, room_jid)
|
||||||
|
else:
|
||||||
|
self.print_conversation('No help info for /%s'%command, room_jid)
|
||||||
|
|
||||||
def print_conversation(self, text, room_jid, contact = '', tim = None):
|
def print_conversation(self, text, room_jid, contact = '', tim = None):
|
||||||
"""Print a line in the conversation:
|
"""Print a line in the conversation:
|
||||||
if contact is set: it's a message from someone
|
if contact is set: it's a message from someone
|
||||||
|
|
Loading…
Reference in New Issue