view Slash.lua @ 0:df29f8179b76

initial import
author ovolkov
date Wed, 12 Nov 2014 08:48:32 +0300
parents
children
line wrap: on
line source
local aName, aEnv = ...

local strchar = string.char
local strbyte = string.byte
local random = random
local strsub = strsub
local tonumber = tonumber

local function UniqSlashID(base, maxNumber)
	local clear = true
	for idx = 1, maxNumber do
		if _G["SLASH_" .. base .. idx] then clear = false break end
	end
	if SlashCmdList[base] then clear = false end
	if clear then return base end
	return UniqSlashID(base .. (strchar(random(strbyte('a'), strbyte('z')))), maxNumber)
end

local slashID

slashID=UniqSlashID("LFGActivityFilter", 1)
_G["SLASH_" .. slashID .. "1"] = "/lfgaf"
SlashCmdList[slashID] = function(activities)
	wipe(aEnv.LFGFilter_Allow_Activity)
	local count = 0
	for activity in string.gmatch(activities, "[^ ]+") do
		local activity_id = tonumber(activity)
		local activity_name
		if activity_id then activity_name = C_LFGList.GetActivityInfo(activity_id) end
		if activity_name then
			print("Adding wanted activity to filter: ", activity_name)
			aEnv.LFGFilter_Allow_Activity[activity_id] = true
			count = count + 1
		else
			print("Can't parse activity ID or it doesn't match known activity: ", activity_id)
		end
	end
        aEnv.LFGFilter_Allow_Activity.count = count
	if count > 0 then
		print("Activities in filter: ", count)
	else
		print("Filters removed.")
	end
end

slashID=UniqSlashID("LFGActivityList", 1)
_G["SLASH_" .. slashID .. "1"] = "/lfgal"
SlashCmdList[slashID] = function()
	for activity_id = 1, 10000 do
		local activity_name = C_LFGList.GetActivityInfo(activity_id)
		if activity_name then
			print(activity_id, activity_name)
		end
	end
end