.BANCHO. Kick all clients when using !kick, don't kick FokaBot with !kick command
This commit is contained in:
		
							
								
								
									
										2
									
								
								common
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								common
									
									
									
									
									
								
							 Submodule common updated: 3288420cd8...64445ae546
									
								
							@@ -119,15 +119,18 @@ def kickAll(fro, chan, message):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def kick(fro, chan, message):
 | 
					def kick(fro, chan, message):
 | 
				
			||||||
	# Get parameters
 | 
						# Get parameters
 | 
				
			||||||
	target = message[0].replace("_", " ")
 | 
						target = message[0].lower().replace("_", " ")
 | 
				
			||||||
 | 
						if target == "fokabot":
 | 
				
			||||||
 | 
							return "Nope."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Get target token and make sure is connected
 | 
						# Get target token and make sure is connected
 | 
				
			||||||
	targetToken = glob.tokens.getTokenFromUsername(target)
 | 
						tokens = glob.tokens.getTokenFromUsername(target, all=True)
 | 
				
			||||||
	if targetToken is None:
 | 
						if len(tokens) == 0:
 | 
				
			||||||
		return "{} is not online".format(target)
 | 
							return "{} is not online".format(target)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Kick user
 | 
						# Kick users
 | 
				
			||||||
	targetToken.kick()
 | 
						for i in tokens:
 | 
				
			||||||
 | 
							i.kick()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Bot response
 | 
						# Bot response
 | 
				
			||||||
	return "{} has been kicked from the server.".format(target)
 | 
						return "{} has been kicked from the server.".format(target)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -113,9 +113,7 @@ def partChannel(userID = 0, channel = "", token = None, toIRC = True, kick = Fal
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		# Delete temporary channel if everyone left
 | 
							# Delete temporary channel if everyone left
 | 
				
			||||||
		if "chat/{}".format(channelObject.name) in glob.streams.streams:
 | 
							if "chat/{}".format(channelObject.name) in glob.streams.streams:
 | 
				
			||||||
			sas = len(glob.streams.streams["chat/{}".format(channelObject.name)].clients)
 | 
								if channelObject.temp == True and len(glob.streams.streams["chat/{}".format(channelObject.name)].clients) - 1 == 0:
 | 
				
			||||||
			print(str(sas - 1))
 | 
					 | 
				
			||||||
			if channelObject.temp == True and sas - 1 == 0:
 | 
					 | 
				
			||||||
				glob.channels.removeChannel(channelObject.name)
 | 
									glob.channels.removeChannel(channelObject.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# Force close tab if needed
 | 
							# Force close tab if needed
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,25 +54,34 @@ class tokenList:
 | 
				
			|||||||
		# Get userID associated to that token
 | 
							# Get userID associated to that token
 | 
				
			||||||
		return self.tokens[token].userID
 | 
							return self.tokens[token].userID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def getTokenFromUserID(self, userID, ignoreIRC=False):
 | 
						def getTokenFromUserID(self, userID, ignoreIRC=False, all=False):
 | 
				
			||||||
		"""
 | 
							"""
 | 
				
			||||||
		Get token from a user ID
 | 
							Get token from a user ID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		:param userID: user ID to find
 | 
							:param userID: user ID to find
 | 
				
			||||||
		:param ignoreIRC: if True, consider bancho clients only and skip IRC clients
 | 
							:param ignoreIRC: if True, consider bancho clients only and skip IRC clients
 | 
				
			||||||
 | 
							:param all: if True, return a list with all clients that match given username, otherwise return
 | 
				
			||||||
 | 
										only the first occurrence.
 | 
				
			||||||
		:return: False if not found, token object if found
 | 
							:return: False if not found, token object if found
 | 
				
			||||||
		"""
 | 
							"""
 | 
				
			||||||
		# Make sure the token exists
 | 
							# Make sure the token exists
 | 
				
			||||||
 | 
							ret = []
 | 
				
			||||||
		for _, value in self.tokens.items():
 | 
							for _, value in self.tokens.items():
 | 
				
			||||||
			if value.userID == userID:
 | 
								if value.userID == userID:
 | 
				
			||||||
				if ignoreIRC and value.irc:
 | 
									if ignoreIRC and value.irc:
 | 
				
			||||||
					continue
 | 
										continue
 | 
				
			||||||
 | 
									if all:
 | 
				
			||||||
 | 
										ret.append(value)
 | 
				
			||||||
 | 
									else:
 | 
				
			||||||
					return value
 | 
										return value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# Return none if not found
 | 
							# Return full list or None if not found
 | 
				
			||||||
 | 
							if all:
 | 
				
			||||||
 | 
								return ret
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
			return None
 | 
								return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def getTokenFromUsername(self, username, ignoreIRC=False, safe=False):
 | 
						def getTokenFromUsername(self, username, ignoreIRC=False, safe=False, all=False):
 | 
				
			||||||
		"""
 | 
							"""
 | 
				
			||||||
		Get an osuToken object from an username
 | 
							Get an osuToken object from an username
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -80,19 +89,28 @@ class tokenList:
 | 
				
			|||||||
		:param ignoreIRC: if True, consider bancho clients only and skip IRC clients
 | 
							:param ignoreIRC: if True, consider bancho clients only and skip IRC clients
 | 
				
			||||||
		:param safe: 	if True, username is a safe username,
 | 
							:param safe: 	if True, username is a safe username,
 | 
				
			||||||
						compare it with token's safe username rather than normal username
 | 
											compare it with token's safe username rather than normal username
 | 
				
			||||||
 | 
							:param all: if True, return a list with all clients that match given username, otherwise return
 | 
				
			||||||
 | 
										only the first occurrence.
 | 
				
			||||||
		:return: osuToken object or None
 | 
							:return: osuToken object or None
 | 
				
			||||||
		"""
 | 
							"""
 | 
				
			||||||
		# lowercase
 | 
							# lowercase
 | 
				
			||||||
		who = username.lower() if not safe else username
 | 
							who = username.lower() if not safe else username
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# Make sure the token exists
 | 
							# Make sure the token exists
 | 
				
			||||||
 | 
							ret = []
 | 
				
			||||||
		for _, value in self.tokens.items():
 | 
							for _, value in self.tokens.items():
 | 
				
			||||||
			if (not safe and value.username.lower() == who) or (safe and value.safeUsername == who):
 | 
								if (not safe and value.username.lower() == who) or (safe and value.safeUsername == who):
 | 
				
			||||||
				if ignoreIRC and value.irc:
 | 
									if ignoreIRC and value.irc:
 | 
				
			||||||
					continue
 | 
										continue
 | 
				
			||||||
 | 
									if all:
 | 
				
			||||||
 | 
										ret.append(value)
 | 
				
			||||||
 | 
									else:
 | 
				
			||||||
					return value
 | 
										return value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# Return none if not found
 | 
							# Return full list or None if not found
 | 
				
			||||||
 | 
							if all:
 | 
				
			||||||
 | 
								return ret
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
			return None
 | 
								return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def deleteOldTokens(self, userID):
 | 
						def deleteOldTokens(self, userID):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user