function module.ParseQualifier(g,N,R,s,v)s=s or{}local b=main.pd[R]local K=string.sub(N,1,1)local c=string.sub(N,2)local P=#c local x=false if K=="\064"and string.sub(c,P-1,P)then c=string.sub(c,1,P-1)end if N=="\109\101"then s[R]=true elseif N=="\097\108\108"then for N,R in pairs(main.players:GetChildren())do s[R]=true end elseif N=="\114\097\110\100\111\109"then s[(game.Players:GetChildren())[math.random(1,#game.Players:GetChildren())]]=true elseif N=="\111\116\104\101\114\115"then for N,v in pairs(main.players:GetChildren())do if v~=R then s[v]=true end end elseif N=="\097\100\109\105\110\115"or N=="\110\111\110\097\100\109\105\110\115"then for R,v in pairs(main.players:GetChildren())do local g=main.pd[v]if g and(N=="\097\100\109\105\110\115"and g.Rank>0 or N=="\110\111\110\097\100\109\105\110\115"and g.Rank==0)then s[v]=true end end elseif N=="\110\098\099"or N=="\098\099"or N=="\116\098\099"or N=="\111\098\099"or N=="\112\114\101\109\105\117\109"or N=="\112\114\101\109"then for R,v in pairs(main.players:GetChildren())do if v.MembershipType==memberships[N]then s[v]=true end end elseif N=="\102\114\105\101\110\100\115"or N=="\110\111\110\102\114\105\101\110\100\115"then for v,g in pairs(main.players:GetChildren())do if N=="\102\114\105\101\110\100\115"and b.Friends[g.Name]or N=="\110\111\110\102\114\105\101\110\100\115"and(not b.Friends[g.Name]and g~=R)then s[g]=true end end elseif N=="\114\054"or N=="\114\049\053"then for R,v in pairs(main.players:GetChildren())do local g=(main:GetModule("\099\102")):GetHumanoid(v)if g and(N=="\114\054"and g.RigType==Enum.HumanoidRigType.R6 or N=="\114\049\053"and g.RigType==Enum.HumanoidRigType.R15)then s[v]=true end end elseif N=="\114\116\104\114\111"or N=="\110\111\110\114\116\104\114\111"then for R,v in pairs(main.players:GetChildren())do local g=(main:GetModule("\099\102")):GetHumanoid(v)if g then local R=g:FindFirstChild("\066\111\100\121\084\121\112\101\083\099\097\108\101")if R and(N=="\114\116\104\114\111"and R.Value>.9 or N=="\110\111\110\114\116\104\114\111"and R.Value<=.9)then s[v]=true end end end elseif K=="\064"then local N={}local R=0 for s,v in pairs(main.settings.Ranks)do local g=tostring(v[1])local b=string.lower(v[2])if string.sub(b,1,#c)==c then N[g]=true R=R+1 end end if R>0 then for R,v in pairs(main.players:GetChildren())do local g=main.pd[v]if g and N[tostring(g.Rank)]then s[v]=true end end end elseif K=="\037"then local N={}local R=0 for s,v in pairs(main.teams:GetChildren())do local g=string.lower(v.Name)if string.sub(g,1,#c)==c then N[tostring(v.TeamColor)]=true R=R+1 end end if R>0 then for R,v in pairs(main.players:GetChildren())do if N[tostring(v.TeamColor)]then s[v]=true end end end else x=true if v then s[N]=true else for R,v in pairs(main.players:GetChildren())do local g=string.lower(v.Name)if string.sub(g,1,#N)==N then s[v]=true end end end end local p={}for N,R in pairs(s)do table.insert(p,N)end return s,p,x end function module.GetTargetPlayers(c,N,R,s,v,g,b,K)local P=R[1]local x={}local p={}local z={}local r=main.pd[N]local t=false if P and(type(P)~="\117\115\101\114\100\097\116\097"and type(P)~="\110\117\109\098\101\114")then t=true end if not t and v==main.settings.UniversalPrefix then table.insert(R,1,"\109\101")P="\109\101"t=true end if t then P:gsub("\040\091\094"..(settings.QualifierBatchKey.."\093\043\041"),function(N)table.insert(p,N)end)table.remove(R,1)end for R,s in pairs(p)do z[s]=true x=module:ParseQualifier(s,N,x)end local D={view=true,handto=true}if not D[b]then local R=0 for N,s in pairs(x)do R=R+1 end local s=true for N,R in pairs(p)do if R~="\109\101"then s=false end end local v=(main:GetModule("\099\102")):GetRankName(r.Rank)if K and R>0 then for N,R in pairs(x)do return N end elseif r.Rank<2 and not s then(main:GetModule("\099\102")):FormatAndFireError(N,"\081\117\097\108\105\102\105\101\114\076\105\109\105\116\084\111\083\101\108\102",v)x={}elseif r.Rank<3 and R>1 then(main:GetModule("\099\102")):FormatAndFireError(N,"\081\117\097\108\105\102\105\101\114\076\105\109\105\116\084\111\079\110\101\080\101\114\115\111\110",v)x={}end end if#s==0 then x={}x[N]=true end return x end return module
-- << FUNCTIONS >>
function module:ParseQualifier(q, speaker, targetPlayers, takeExactIndName)
	targetPlayers = targetPlayers or {}
	local speakerData = main.pd[speaker]
	local firstChar = string.sub(q, 1, 1)
	local remainingChars = string.sub(q, 2)
	local endLength = #remainingChars
	local individual = false

	if firstChar == "@" and string.sub(remainingChars, endLength - 1, endLength) then
		remainingChars = string.sub(remainingChars, 1, endLength - 1)
	end

	if q == "me" then
		targetPlayers[speaker] = true
	elseif q == "all" then
		for i, plr in pairs(main.players:GetChildren()) do
			targetPlayers[plr] = true
		end
	elseif q == "random" then
		targetPlayers[game.Players:GetChildren()[math.random(1, #game.Players:GetChildren())]] = true
	elseif q == "others" then
		for i, plr in pairs(main.players:GetChildren()) do
			if plr ~= speaker then
				targetPlayers[plr] = true
			end
		end
	elseif q == "admins" or q == "nonadmins" then
		for i, plr in pairs(main.players:GetChildren()) do
			local pdata = main.pd[plr]
			if pdata and ((q == "admins" and pdata.Rank > 0) or (q == "nonadmins" and pdata.Rank == 0)) then
				targetPlayers[plr] = true
			end
		end
	elseif q == "nbc" or q == "bc" or q == "tbc" or q == "obc" or q == "premium" or q == "prem" then
		for i, plr in pairs(main.players:GetChildren()) do
			if plr.MembershipType == memberships[q] then
				targetPlayers[plr] = true
			end
		end
	elseif q == "friends" or q == "nonfriends" then
		for i, plr in pairs(main.players:GetChildren()) do
			if
				(q == "friends" and speakerData.Friends[plr.Name])
				or (q == "nonfriends" and not speakerData.Friends[plr.Name] and plr ~= speaker)
			then
				targetPlayers[plr] = true
			end
		end
	elseif q == "r6" or q == "r15" then
		for i, plr in pairs(main.players:GetChildren()) do
			local humanoid = main:GetModule("cf"):GetHumanoid(plr)
			if
				humanoid
				and (
					(q == "r6" and humanoid.RigType == Enum.HumanoidRigType.R6)
					or (q == "r15" and humanoid.RigType == Enum.HumanoidRigType.R15)
				)
			then
				targetPlayers[plr] = true
			end
		end
	elseif q == "rthro" or q == "nonrthro" then
		for i, plr in pairs(main.players:GetChildren()) do
			local humanoid = main:GetModule("cf"):GetHumanoid(plr)
			if humanoid then
				local bts = humanoid:FindFirstChild("BodyTypeScale")
				if bts and ((q == "rthro" and bts.Value > 0.9) or (q == "nonrthro" and bts.Value <= 0.9)) then
					targetPlayers[plr] = true
				end
			end
		end
	elseif firstChar == "@" then -- Select Rank
		local selectedRanks = {}
		local count = 0
		for _, rankDetails in pairs(main.settings.Ranks) do
			local rankId = tostring(rankDetails[1])
			local rankName = string.lower(rankDetails[2])
			if string.sub(rankName, 1, #remainingChars) == remainingChars then
				selectedRanks[rankId] = true
				count = count + 1
			end
		end
		if count > 0 then
			for i, plr in pairs(main.players:GetChildren()) do
				local pdata = main.pd[plr]
				if pdata and selectedRanks[tostring(pdata.Rank)] then
					targetPlayers[plr] = true
				end
			end
		end
	elseif firstChar == "%" then -- Select Team
		local selectedTeams = {}
		local count = 0
		for _, team in pairs(main.teams:GetChildren()) do
			local teamName = string.lower(team.Name)
			if string.sub(teamName, 1, #remainingChars) == remainingChars then
				selectedTeams[tostring(team.TeamColor)] = true
				count = count + 1
			end
		end
		if count > 0 then
			for i, plr in pairs(main.players:GetChildren()) do
				if selectedTeams[tostring(plr.TeamColor)] then
					targetPlayers[plr] = true
				end
			end
		end
	else -- Individual
		individual = true
		if takeExactIndName then
			targetPlayers[q] = true
		else
			for i, plr in pairs(main.players:GetChildren()) do
				local plrName = string.lower(plr.Name)
				if string.sub(plrName, 1, #q) == q then
					targetPlayers[plr] = true
				end
			end
		end
	end
	local targetPlayersArray = {}
	for plr, _ in pairs(targetPlayers) do
		table.insert(targetPlayersArray, plr)
	end
	return targetPlayers, targetPlayersArray, individual
end

function module:GetTargetPlayers(speaker, args, originalArgs, commandPrefix, commandPrefixes, commandName, individual)
	local qArg = args[1]
	local targetPlayers = {}
	local qBatches = {}
	local qUsed = {}
	local speakerData = main.pd[speaker]
	local qualifierPresent = false
	if qArg and type(qArg) ~= "userdata" and type(qArg) ~= "number" then
		qualifierPresent = true
	end
	if not qualifierPresent and commandPrefix == main.settings.UniversalPrefix then
		table.insert(args, 1, "me")
		qArg = "me"
		qualifierPresent = true
	end
	if qualifierPresent then
		qArg:gsub("([^" .. settings.QualifierBatchKey .. "]+)", function(c)
			table.insert(qBatches, c)
		end)
		table.remove(args, 1)
	end
	for _, q in pairs(qBatches) do
		qUsed[q] = true
		targetPlayers = module:ParseQualifier(q, speaker, targetPlayers)
	end

	--Check if player is selecting more than 1 person and modify based on their rank
	local ignoreSingleUse = { ["view"] = true, ["handto"] = true }
	if not ignoreSingleUse[commandName] then
		local totalPlrs = 0
		for plr, _ in pairs(targetPlayers) do
			totalPlrs = totalPlrs + 1
		end
		local onlyMe = true
		for i, v in pairs(qBatches) do
			if v ~= "me" then
				onlyMe = false
			end
		end
		local speakerRankName = main:GetModule("cf"):GetRankName(speakerData.Rank)
		if individual and totalPlrs > 0 then
			for plr, _ in pairs(targetPlayers) do
				return plr
			end
		elseif speakerData.Rank < 2 and not onlyMe then
			main:GetModule("cf"):FormatAndFireError(speaker, "QualifierLimitToSelf", speakerRankName)
			targetPlayers = {}
		elseif speakerData.Rank < 3 and totalPlrs > 1 then
			main:GetModule("cf"):FormatAndFireError(speaker, "QualifierLimitToOnePerson", speakerRankName)
			targetPlayers = {}
		end
	end

	--Check Universal Prefix and adjust arguments accordingly
	--if commandPrefix == main.settings.UniversalPrefix or (main:GetModule("cf"):FindValue(commandPrefixes, main.settings.UniversalPrefix) and qArg == nil) then
	if #originalArgs == 0 then
		targetPlayers = {}
		targetPlayers[speaker] = true
	end

	return targetPlayers
end

return module
