Quantcast

+ .keys & .allkeys chat cmds

Jesse Manelius [03-06-18 - 18:54]
+ .keys & .allkeys chat cmds
+ /iks (i)gnore, (w)hitelist, (h)elp, (d)elete
+ tint rows based on faction
maybe some other fixes?
Filename
iKeystones.lua
iKeystones.toc
diff --git a/iKeystones.lua b/iKeystones.lua
index 2e6231e..b92f316 100644
--- a/iKeystones.lua
+++ b/iKeystones.lua
@@ -7,6 +7,19 @@ addon:RegisterEvent('CHALLENGE_MODE_MAPS_UPDATE')
 addon:RegisterEvent('PLAYER_LOGIN')
 addon:RegisterEvent('BAG_UPDATE')
 addon:RegisterEvent('CHALLENGE_MODE_KEYSTONE_RECEPTABLE_OPEN')
+
+--Chat events
+addon:RegisterEvent('CHAT_MSG_INSTANCE')
+addon:RegisterEvent('CHAT_MSG_INSTANCE_LEADER')
+addon:RegisterEvent('CHAT_MSG_PARTY')
+addon:RegisterEvent('CHAT_MSG_PARTY_LEADER')
+addon:RegisterEvent('CHAT_MSG_RAID')
+addon:RegisterEvent('CHAT_MSG_RAID_LEADER')
+addon:RegisterEvent('CHAT_MSG_GUILD')
+addon:RegisterEvent('CHAT_MSG_GUILD_LEADER')
+addon:RegisterEvent('CHAT_MSG_OFFICER')
+
+
 local iKS = {}
 iKS.frames = {}
 local player = UnitGUID('player')
@@ -128,7 +141,7 @@ iKS.affixCycles = {
 	{5,14,10}, -- Teeming, Quaking, Fortified
 	{6,4,9}, -- Raging, Necrotic, Tyrannical
 	{7,2,10}, -- Bolstering, Skittish, Fortified
-	{5,4,9}, -- Teeming, Necrotic, Tyrannical
+	{5,3,9}, -- Teeming, Volanic, Tyrannical
 	{8,12,10}, -- Sanguine, Grievous, Fortified
 	{7,13,9}, -- Bolstering, Explosive, Tyrannical
 	{11,14,10}, -- Bursting, Quaking, Fortified
@@ -207,7 +220,7 @@ function iKS:weeklyReset()
 end
 function iKS:createPlayer()
 	if player and not iKeystonesDB[player] then
-		if UnitLevel('player') >= 110 then
+		if UnitLevel('player') >= 110 and not iKeystonesConfig.ignoreList[player] then
 			iKeystonesDB[player] = {
 				name = UnitName('player'),
 				server = GetRealmName(),
@@ -215,12 +228,15 @@ function iKS:createPlayer()
 				maxCompleted = 0,
 				key = {},
 				canLoot = false,
+				faction = UnitFactionGroup('player'),
 			}
 			return true
 		else
 			return false
 		end
 	elseif player and iKeystonesDB[player] then
+		iKeystonesDB[player].name = UnitName('player') -- fix for name changing
+		iKeystonesDB[player].faction = UnitFactionGroup('player') -- faction change (tbh i think guid would change) and update old DB
 		return true
 	else
 		return false
@@ -349,6 +365,55 @@ function iKS:printKeystones()
 		print(str)
 	end
 end
+function iKS:PasteKeysToChat(all,channel)
+	if all then -- All keys for this faction
+		local i = 0
+		local str = ''
+		local faction = UnitFactionGroup('player')
+		local msgs = {}
+		for guid,data in pairs(iKeystonesDB) do
+			if i == 3 then
+				SendChatMessage(str, channel)
+				str = ''
+				i = 0
+			end
+			if data.faction == faction then
+				if i > 0 then
+					str = str .. ' - '
+				end
+				local itemLink = ''
+				if data.key.map then
+					itemLink = string.format('%s (%s)', iKS:getZoneInfo(data.key.map), data.key.level)
+				else
+					itemLink = UNKNOWN
+				end
+				str = str..string.format('%s: %s', data.name, itemLink)
+				i = i + 1
+			end
+		end
+		SendChatMessage(str, channel)
+	else -- Only this char
+		local data = iKeystonesDB[player]
+		if data then
+			if data.key.map then
+				itemLink = string.format('%s|Hkeystone:%d:%d:%d:%d:%d|h[%s (%s)]|h|r', iKS:getItemColor(data.key.level), data.key.map, data.key.level, data.key.affix4, data.key.affix7, data.key.affix10,iKS:getZoneInfo(data.key.map), data.key.level)
+			else
+				itemLink = UNKNOWN
+			end
+			SendChatMessage(itemLink, channel)
+		end
+	end
+end
+function iKS:help()
+	print([[iKeystones:
+/iks reset - reset all characters
+/iks start (s) - start dungeon
+/iks next (n) - print affixes for next reset
+/iks ignore (i) - ignore this character
+/iks whitelist (w) - enable tracking for this character (remove ignore)
+/iks help (h) - show this help
+/iks delete (d) characterName serverName - delete specific character]])
+end
 function addon:PLAYER_LOGIN()
 	player = UnitGUID('player')
 	C_ChallengeMode.RequestMapInfo()
@@ -377,6 +442,9 @@ function addon:ADDON_LOADED(addonName)
 		addon:UnregisterEvent('ADDON_LOADED')
 		iKeystonesDB = iKeystonesDB or {}
 		iKeystonesConfig = iKeystonesConfig or {}
+		if not iKeystonesConfig.ignoreList then
+			iKeystonesConfig.ignoreList = {}
+		end
 		if not iKeystonesConfig.aff then
 			iKeystonesConfig.aff = {
 				aff4 = {
@@ -417,6 +485,43 @@ function addon:QUEST_LOG_UPDATE()
 		addon:UnregisterEvent('QUEST_LOG_UPDATE')
 	end
 end
+local function ChatHandling(msg, channel)
+	if msg and (string.lower(msg) == '.allkeys' or string.lower(msg) == '.keys') then
+		if string.lower(msg) == '.allkeys' then
+			iKS:PasteKeysToChat(true,channel)
+		else
+			iKS:PasteKeysToChat(false,channel)
+		end
+	end
+end
+function addon:CHAT_MSG_GUILD(msg)
+	ChatHandling(msg, 'guild')
+end
+function addon:CHAT_MSG_GUILD_LEADER(msg)
+	ChatHandling(msg, 'guild')
+end
+function addon:CHAT_MSG_OFFICER(msg)
+	ChatHandling(msg, 'officer')
+end
+function addon:CHAT_MSG_INSTANCE(msg)
+	ChatHandling(msg, 'instance')
+end
+function addon:CHAT_MSG_INSTANCE_LEADER(msg)
+	ChatHandling(msg, 'instance')
+end
+function addon:CHAT_MSG_PARTY(msg)
+	ChatHandling(msg, 'party')
+end
+function addon:CHAT_MSG_PARTY_LEADER(msg)
+	ChatHandling(msg, 'party')
+end
+function addon:CHAT_MSG_RAID(msg)
+	ChatHandling(msg, 'raid')
+end
+function addon:CHAT_MSG_RAID_LEADER(msg)
+	ChatHandling(msg, 'raid')
+end
+
 function addon:CHALLENGE_MODE_KEYSTONE_RECEPTABLE_OPEN()
 	local _, _, _, _, _, _, _, mapID = GetInstanceInfo()
 	if iKS.mapID and iKS.keystonesToMapIDs[iKS.mapID] == mapID then
@@ -429,7 +534,6 @@ function addon:CHALLENGE_MODE_KEYSTONE_RECEPTABLE_OPEN()
 		end)
 	end
 end
-
 local function chatFiltering(self, event, msg, ...)
 	if event == 'CHAT_MSG_LOOT' then
 		local linkStart = msg:find('Hitem:138019')
@@ -480,7 +584,7 @@ ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_LEADER", chatFiltering)
 ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", chatFiltering)
 ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER", chatFiltering)
 ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", chatFiltering)
-ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER", chatFiltering)
+ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", chatFiltering)
 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", chatFiltering)
 ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", chatFiltering)
 ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_WHISPER", chatFiltering)
@@ -567,6 +671,19 @@ function iKS:createNewLine()
 	f.ap.text:SetText(#iKS.frames == 1 and 'AP' or '')
 	f.ap.text:Show()
 end
+local function reColor(f, faction)
+	local r,g,b = .1,.1,.1
+	if faction and faction == 'Horde' then
+		r = .20
+	elseif faction and faction == 'Alliance' then
+		b = .20
+	end
+	f.name:SetBackdropColor(r,g,b,.9)
+	f.key:SetBackdropColor(r,g,b,.9)
+	f.max:SetBackdropColor(r,g,b,.9)
+	f.ilvl:SetBackdropColor(r,g,b,.9)
+	f.ap:SetBackdropColor(r,g,b,.9)
+end
 function iKS:createMainWindow()
 	if not iKS.anchor then
 		iKS.anchor = CreateFrame('frame', nil, UIParent)
@@ -617,8 +734,6 @@ function iKS:createMainWindow()
 		f.aff10.text:SetPoint('CENTER', f.aff10, 'CENTER', 0,0)
 		f.aff10.text:SetText('Tyrannical')
 		--f.aff7.text:Show()
-
-
 	end
 	local i = 1
 	local maxSizes = {
@@ -651,6 +766,7 @@ function iKS:createMainWindow()
 		if f.ap.text:GetWidth() > maxSizes.ap then
 			maxSizes.ap = f.ap.text:GetWidth()
 		end
+		reColor(f, v.faction)
 		f.name:Show()
 		f.key:Show()
 		f.max:Show()
@@ -663,6 +779,14 @@ function iKS:createMainWindow()
 		f.key:SetWidth(maxSizes.key+4)
 		f.ap:SetWidth(maxSizes.ap+4)
 	end
+	for j = i+1, #iKS.frames do
+		local f = iKS.frames[j]
+		f.name:Hide()
+		f.key:Hide()
+		f.max:Hide()
+		f.ilvl:Hide()
+		f.ap:Hide()
+	end
 	local w = maxSizes.name+maxSizes.key+maxSizes.ap+100 --+max(50)+ilvl(50)
 	iKS.anchor:SetWidth(w)

@@ -717,37 +841,65 @@ ItemRefTooltip:HookScript('OnTooltipSetItem', itemRefScanning)
 SLASH_IKEYSTONES1 = "/ikeystones"
 SLASH_IKEYSTONES2 = "/iks"
 SlashCmdList["IKEYSTONES"] = function(msg)
-	if msg then
+	if msg and msg:len() > 0 then
 		msg = string.lower(msg)
-	end
-	if msg and msg == 'reset' then
-		iKeystonesDB = nil
-		iKeystonesDB = {}
-		iKS:scanInventory()
-		iKS:scanCharacterMaps()
-	elseif msg and (msg == 'start' or msg == 's') then
-		if C_ChallengeMode.GetSlottedKeystoneInfo() then
-			C_ChallengeMode.StartChallengeMode()
-		end
-	elseif msg and (msg == 'force' or msg == 'f') then
-		local _, _, _, _, _, _, _, mapID = GetInstanceInfo()
-		local bagID, slotID = iKS:scanInventory(true)
-		PickupContainerItem(bagID, slotID)
-		C_Timer.After(0.1, function()
-			if CursorHasItem() then
-				C_ChallengeMode.SlotKeystone()
+		if msg == 'reset' then
+			iKeystonesDB = nil
+			iKeystonesDB = {}
+			iKS:scanInventory()
+			iKS:scanCharacterMaps()
+		elseif msg == 'start' or msg == 's' then
+			if C_ChallengeMode.GetSlottedKeystoneInfo() then
+				C_ChallengeMode.StartChallengeMode()
 			end
-		end)
-	elseif msg and (msg == 'next' or msg == 'n') then
-		for i = 1, #iKS.affixCycles do
-			if iKS.affixCycles[i][1] == iKeystonesConfig.aff.aff4.a and iKS.affixCycles[i][2] == iKeystonesConfig.aff.aff7.a and iKS.affixCycles[i][3] == iKeystonesConfig.aff.aff10.a then
-				local nextCycle = i+1 <= #iKS.affixCycles and i+1 or 1
-				local aff1 = C_ChallengeMode.GetAffixInfo(iKS.affixCycles[nextCycle][1])
-				local aff2 = C_ChallengeMode.GetAffixInfo(iKS.affixCycles[nextCycle][2])
-				local aff3 = C_ChallengeMode.GetAffixInfo(iKS.affixCycles[nextCycle][3])
-				print(string.format('iKS: Next cycle : %s, %s, %s.',aff1, aff2, aff3))
-				break
+		elseif msg == 'force' or msg == 'f' then
+			local _, _, _, _, _, _, _, mapID = GetInstanceInfo()
+			local bagID, slotID = iKS:scanInventory(true)
+			PickupContainerItem(bagID, slotID)
+			C_Timer.After(0.1, function()
+				if CursorHasItem() then
+					C_ChallengeMode.SlotKeystone()
+				end
+			end)
+		elseif msg == 'next' or msg == 'n' then
+			for i = 1, #iKS.affixCycles do
+				if iKS.affixCycles[i][1] == iKeystonesConfig.aff.aff4.a and iKS.affixCycles[i][2] == iKeystonesConfig.aff.aff7.a and iKS.affixCycles[i][3] == iKeystonesConfig.aff.aff10.a then
+					local nextCycle = i+1 <= #iKS.affixCycles and i+1 or 1
+					local aff1 = C_ChallengeMode.GetAffixInfo(iKS.affixCycles[nextCycle][1])
+					local aff2 = C_ChallengeMode.GetAffixInfo(iKS.affixCycles[nextCycle][2])
+					local aff3 = C_ChallengeMode.GetAffixInfo(iKS.affixCycles[nextCycle][3])
+					print(string.format('iKS: Next cycle : %s, %s, %s.',aff1, aff2, aff3))
+					break
+				end
+			end
+			print(string.format('iKS: Uknown cycle, contact author'))
+		elseif msg == 'ignore' or msg == 'i' then
+			iKeystonesConfig.ignoreList[player] = true
+			iKeystonesDB[player] = nil
+			print('iKS: This character will now be ignored.')
+		elseif msg == 'whitelist' or msg == 'w' then
+			iKeystonesConfig.ignoreList[player] = nil
+			iKS:scanCharacterMaps()
+			iKS:scanInventory()
+			print('iKS: This character is now whitelisted.')
+		elseif msg == 'help' or msg == 'h' then
+			iKS:help()
+		elseif msg:match('delete') or msg:match('d') then
+			local _,char,server = msg:match("^(.*) (.*) (.*)$")
+			if not (char and server) then
+				print('iKS: ' .. msg .. ' is not a valid format, please use /iks delete characterName serverName, eg /iks delete ironi stormreaver')
+				return
 			end
+			for guid,data in pairs(iKeystonesDB) do
+				if server == string.lower(data.server) and char == string.lower(data.name) then
+					iKeystonesDB[guid] = nil
+					print('iKS: Succesfully deleted:' ..char..'-'..server..'.')
+					return
+				end
+			end
+			print('iKS: cannot find ' ..char..'-'..server..'.')
+		else
+			iKS:help()
 		end
 	else
 		iKS:printKeystones()
diff --git a/iKeystones.toc b/iKeystones.toc
index e197268..139d617 100644
--- a/iKeystones.toc
+++ b/iKeystones.toc
@@ -2,7 +2,7 @@
 ## Title: iKeystones
 ## Notes: Tracks your keystones
 ## Author: Ironi
-## Version: 1.550
+## Version: 1.56
 ## DefaultState: enabled

 ## SavedVariables: iKeystonesDB, iKeystonesConfig