[Paco & i] support nicknames with space for /ban and /kick commands
This commit is contained in:
		
							parent
							
								
									7bfcf169e4
								
							
						
					
					
						commit
						1ff9001084
					
				
					 1 changed files with 43 additions and 19 deletions
				
			
		| 
						 | 
					@ -1584,39 +1584,65 @@ class GroupchatControl(ChatControlBase):
 | 
				
			||||||
			return True
 | 
								return True
 | 
				
			||||||
		elif command == 'ban':
 | 
							elif command == 'ban':
 | 
				
			||||||
			if len(message_array):
 | 
								if len(message_array):
 | 
				
			||||||
				message_array = message_array[0].split()
 | 
					 | 
				
			||||||
				nick = message_array.pop(0)
 | 
					 | 
				
			||||||
				room_nicks = gajim.contacts.get_nick_list(self.account,
 | 
									room_nicks = gajim.contacts.get_nick_list(self.account,
 | 
				
			||||||
					self.room_jid)
 | 
										self.room_jid)
 | 
				
			||||||
				reason = ' '.join(message_array)
 | 
									nb_match = 0
 | 
				
			||||||
				if nick in room_nicks:
 | 
									nick_ban = ''
 | 
				
			||||||
 | 
									for nick in room_nicks:
 | 
				
			||||||
 | 
										if message_array[0].startswith(nick):
 | 
				
			||||||
 | 
											nb_match += 1
 | 
				
			||||||
 | 
											nick_ban = nick
 | 
				
			||||||
 | 
											test_reason = message_array[0][len(nick) + 1:]
 | 
				
			||||||
 | 
											if len(test_reason) == 0:
 | 
				
			||||||
 | 
												reason = 'None'
 | 
				
			||||||
 | 
											else:
 | 
				
			||||||
 | 
												reason = test_reason
 | 
				
			||||||
 | 
									if nb_match == 1:
 | 
				
			||||||
					gc_contact = gajim.contacts.get_gc_contact(self.account,
 | 
										gc_contact = gajim.contacts.get_gc_contact(self.account,
 | 
				
			||||||
						self.room_jid, nick)
 | 
												self.room_jid, nick_ban)
 | 
				
			||||||
					nick = gc_contact.jid
 | 
										nick = gc_contact.jid
 | 
				
			||||||
				if nick.find('@') >= 0:
 | 
									elif nb_match > 1:
 | 
				
			||||||
 | 
										self.print_conversation(_('There is an ambiguity: %d nicks '
 | 
				
			||||||
 | 
											'match.\n Please use graphical interface ') % nb_match,
 | 
				
			||||||
 | 
											'info')
 | 
				
			||||||
 | 
										self.clear(self.msg_textview)
 | 
				
			||||||
 | 
									elif message_array[0].split()[0].find('@') > 0:
 | 
				
			||||||
					gajim.connections[self.account].gc_set_affiliation(self.room_jid,
 | 
										gajim.connections[self.account].gc_set_affiliation(self.room_jid,
 | 
				
			||||||
						nick, 'outcast', reason)
 | 
											message_array[0].split()[0], 'outcast', reason)
 | 
				
			||||||
					self.clear(self.msg_textview)
 | 
										self.clear(self.msg_textview)
 | 
				
			||||||
				else:
 | 
									else:
 | 
				
			||||||
					self.print_conversation(_('Nickname not found: %s') % nick,
 | 
										self.print_conversation(_('Nickname not found'), 'info')
 | 
				
			||||||
						'info')
 | 
					 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
				self.get_command_help(command)
 | 
									self.get_command_help(command)
 | 
				
			||||||
			return True
 | 
								return True
 | 
				
			||||||
		elif command == 'kick':
 | 
							elif command == 'kick':
 | 
				
			||||||
			if len(message_array):
 | 
								if len(message_array):
 | 
				
			||||||
				message_array = message_array[0].split()
 | 
									nick_kick = ''
 | 
				
			||||||
				nick = message_array.pop(0)
 | 
					 | 
				
			||||||
				room_nicks = gajim.contacts.get_nick_list(self.account,
 | 
									room_nicks = gajim.contacts.get_nick_list(self.account,
 | 
				
			||||||
					self.room_jid)
 | 
										self.room_jid)
 | 
				
			||||||
				reason = ' '.join(message_array)
 | 
									nb_match = 0
 | 
				
			||||||
				if nick in room_nicks:
 | 
									for nick in room_nicks:
 | 
				
			||||||
 | 
										if message_array[0].startswith(nick):
 | 
				
			||||||
 | 
											nb_match += 1
 | 
				
			||||||
 | 
											nick_kick = nick
 | 
				
			||||||
 | 
											test_reason = message_array[0][len(nick) + 1:]
 | 
				
			||||||
 | 
											if len(test_reason) == 0:
 | 
				
			||||||
 | 
												reason = 'None'
 | 
				
			||||||
 | 
											else:
 | 
				
			||||||
 | 
												reason = test_reason
 | 
				
			||||||
 | 
									if nb_match == 1:
 | 
				
			||||||
					gajim.connections[self.account].gc_set_role(self.room_jid, nick,
 | 
										gajim.connections[self.account].gc_set_role(self.room_jid, nick,
 | 
				
			||||||
						'none', reason)
 | 
											'none', reason)
 | 
				
			||||||
					self.clear(self.msg_textview)
 | 
										self.clear(self.msg_textview)
 | 
				
			||||||
 | 
									elif nb_match > 1:
 | 
				
			||||||
 | 
										self.print_conversation(_('There is an ambiguity: %d nicks '
 | 
				
			||||||
 | 
											'match.\n Please use graphical interface') % nb_match ,
 | 
				
			||||||
 | 
											'info' )
 | 
				
			||||||
 | 
										self.clear(self.msg_textview)
 | 
				
			||||||
				else:
 | 
									else:
 | 
				
			||||||
					self.print_conversation(_('Nickname not found: %s') % nick,
 | 
										# We can't do the difference between nick and reason
 | 
				
			||||||
						'info')
 | 
										# So we don't say the nick
 | 
				
			||||||
 | 
										self.print_conversation(_('Nickname not found') , 'info')
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
				self.get_command_help(command)
 | 
									self.get_command_help(command)
 | 
				
			||||||
			return True
 | 
								return True
 | 
				
			||||||
| 
						 | 
					@ -1695,8 +1721,7 @@ class GroupchatControl(ChatControlBase):
 | 
				
			||||||
			s = _('Usage: /%s <nickname|JID> [reason], bans the JID from the group'
 | 
								s = _('Usage: /%s <nickname|JID> [reason], bans the JID from the group'
 | 
				
			||||||
				' chat. The nickname of an occupant may be substituted, but not if '
 | 
									' chat. The nickname of an occupant may be substituted, but not if '
 | 
				
			||||||
				'it contains "@". If the JID is currently in the group chat, '
 | 
									'it contains "@". If the JID is currently in the group chat, '
 | 
				
			||||||
				'he/she/it will also be kicked. Does NOT support spaces in '
 | 
									'he/she/it will also be kicked.') % command
 | 
				
			||||||
				'nickname.') % command
 | 
					 | 
				
			||||||
			self.print_conversation(s, 'info')
 | 
								self.print_conversation(s, 'info')
 | 
				
			||||||
		elif command == 'chat' or command == 'query':
 | 
							elif command == 'chat' or command == 'query':
 | 
				
			||||||
			self.print_conversation(_('Usage: /%s <nickname>, opens a private chat'
 | 
								self.print_conversation(_('Usage: /%s <nickname>, opens a private chat'
 | 
				
			||||||
| 
						 | 
					@ -1721,8 +1746,7 @@ class GroupchatControl(ChatControlBase):
 | 
				
			||||||
		elif command == 'kick':
 | 
							elif command == 'kick':
 | 
				
			||||||
			self.print_conversation(_('Usage: /%s <nickname> [reason], removes '
 | 
								self.print_conversation(_('Usage: /%s <nickname> [reason], removes '
 | 
				
			||||||
				'the occupant specified by nickname from the group chat and '
 | 
									'the occupant specified by nickname from the group chat and '
 | 
				
			||||||
				'optionally displays a reason. Does NOT support spaces in '
 | 
									'optionally displays a reason.') % command, 'info')
 | 
				
			||||||
				'nickname.') % command, 'info')
 | 
					 | 
				
			||||||
		elif command == 'me':
 | 
							elif command == 'me':
 | 
				
			||||||
			self.print_conversation(_('Usage: /%(command)s <action>, sends action '
 | 
								self.print_conversation(_('Usage: /%(command)s <action>, sends action '
 | 
				
			||||||
				'to the current group chat. Use third person. (e.g. /%(command)s '
 | 
									'to the current group chat. Use third person. (e.g. /%(command)s '
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue