Skip to content

Commit

Permalink
Pull inbound comms and chat output into own files
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkub committed Nov 1, 2016
1 parent ea92a1b commit bbc367c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 32 deletions.
37 changes: 7 additions & 30 deletions Quecho.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ ns.quests = setmetatable({}, {__index = function (t,i)
end})


local f = CreateFrame("Frame")


local function OnLoad()
RegisterAddonMessagePrefix("Quecho")
RegisterAddonMessagePrefix("Quecho2")
RegisterAddonMessagePrefix("Quecho3")
RegisterAddonMessagePrefix("Quecho4")

ns.RegisterCallback("CHAT_MSG_ADDON", ns.CHAT_MSG_ADDON)
end
ns.RegisterCallback("_THIS_ADDON_LOADED", OnLoad)


---------------------------
-- Reset timer --
---------------------------
Expand Down Expand Up @@ -50,25 +36,16 @@ end
-- Event Handlers --
------------------------------

local myname = UnitName("player").. "-".. GetRealmName():gsub(" ", "")
function ns.CHAT_MSG_ADDON(self, event, prefix, msg, channel, sender)
if sender == myname then return end

if prefix == "Quecho" then
local _, _, objective, progress = msg:find("([^:]+):? %(?([^)]+)%)?")

local now = GetTime()
sendtimes[sender..objective] = now
ns.StartTimer(now + DELAY + 0.1, ExpireObjectives)

ns.quests[sender][objective] = progress
function OnPartyProgress(self, message, sender, objective, progress)
local now = GetTime()
sendtimes[sender..objective] = now
ns.StartTimer(now + DELAY + 0.1, ExpireObjectives)

ns.Update()
ns.quests[sender][objective] = progress

elseif prefix == "Quecho2" then ns.Printf("%s turned in %s ", sender, msg)
elseif prefix == "Quecho3" then ns.Printf("%s accepted %s ", sender, msg)
elseif prefix == "Quecho4" then ns.Printf("%s abandoned %s ", sender, msg) end
ns.Update()
end
ns.RegisterCallback("_PARTY_PROGRESS", OnPartyProgress)


-- function Quecho_DebugComm()
Expand Down
6 changes: 4 additions & 2 deletions Quecho.toc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ externals\memoizing_table.lua
externals\print.lua
externals\timer.lua

constants.lua

services\inbound_comms.lua
services\log_scanner.lua
services\log_update_proxy.lua
services\outbound_comms.lua
services\party_printout.lua
services\progess_bar_quests.lua
services\ui_info_listener.lua


Quecho.lua
Tracker.lua

init.lua
File renamed without changes.
36 changes: 36 additions & 0 deletions services/inbound_comms.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

local myname, ns = ...


local OBJECTIVE_PROGRESS = "([^:]+):? %(?([^)]+)%)?"
local MESSAGES = {
[ns.COMM_TOKEN_ABANDON] = "_PARTY_ABANDON",
[ns.COMM_TOKEN_ACCEPT] = "_PARTY_ACCEPT",
[ns.COMM_TOKEN_TURNIN] = "_PARTY_TURNIN",
}


local player_name = UnitName("player").. "-".. GetRealmName():gsub(" ", "")
function OnAddonChatMsg(self, event, prefix, msg, channel, sender)
if sender == player_name then return end

if MESSAGES[prefix] then
return ns.SendMessage(MESSAGES[prefix], sender, msg)
end

if prefix == ns.COMM_TOKEN_PROGRESS then
local _, _, objective, progress = msg:find(OBJECTIVE_PROGRESS)
ns.SendMessage("_PARTY_PROGRESS", sender, objective, progress)
end
end


local function OnLoad()
RegisterAddonMessagePrefix(ns.COMM_TOKEN_ABANDON)
RegisterAddonMessagePrefix(ns.COMM_TOKEN_ACCEPT)
RegisterAddonMessagePrefix(ns.COMM_TOKEN_PROGRESS)
RegisterAddonMessagePrefix(ns.COMM_TOKEN_TURNIN)

ns.RegisterCallback("CHAT_MSG_ADDON", OnAddonChatMsg)
end
ns.RegisterCallback("_THIS_ADDON_LOADED", OnLoad)
19 changes: 19 additions & 0 deletions services/party_printout.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

local myname, ns = ...


local FORMATS = {
_PARTY_ABANDON = "%s abandoned %s",
_PARTY_ACCEPT = "%s accepted %s",
_PARTY_TURNIN = "%s turned in %s",
}


function OnPartyAction(self, message, sender, msg)
ns.Printf(FORMATS[message], sender, msg)
end


ns.RegisterCallback("_PARTY_ABANDON", OnPartyAction)
ns.RegisterCallback("_PARTY_ACCEPT", OnPartyAction)
ns.RegisterCallback("_PARTY_TURNIN", OnPartyAction)

0 comments on commit bbc367c

Please sign in to comment.