diff --git a/BusyAndAway.toc b/BusyAndAway.toc
index e8c5944..79f433d 100644
--- a/BusyAndAway.toc
+++ b/BusyAndAway.toc
@@ -1,8 +1,9 @@
-## Interface: 50400
+## Interface: 60000
## Title: Busy and Away
## Notes: Restores your DND message when flagged AFK.
## Author: Niketa-Moonrunner (US)
## Version: @project-version@
-## SavedVariables: BAA_DNDMSG, BAA_FLAGTYPE
+## SavedVariables: BusyAndAwayDB
-Core.lua
\ No newline at end of file
+Core.lua
+Options.lua
diff --git a/Core.lua b/Core.lua
index c58ae90..2fbbf1e 100644
--- a/Core.lua
+++ b/Core.lua
@@ -1,83 +1,94 @@
--- __________ Busy and Away by Niketa-Moonrunner (US) / http://niketa.net / addons@niketa.net __________ --
+-- Event Frame
+local events = CreateFrame("Frame")
+ events:RegisterEvent("ADDON_LOADED")
+ events:RegisterEvent("PLAYER_FLAGS_CHANGED")
+ events:RegisterEvent("CHAT_MSG_BN_WHISPER")
+ events:SetScript("OnEvent", function(self, event, ...)
+ return self[event] and self[event](self, event, ...)
+ end)
-SLASH_BUSYANDAWAY1 = "/baa"
+-- My Lazy Functions
+local function Set(var, val)
+ if BusyAndAwayDB["settings"][var] then
+ BusyAndAwayDB["settings"][var] = val
+ else
+ BusyAndAwayDB[var] = val
+ end
+end
-function SlashCmdList.BUSYANDAWAY(msg, editbox)
- local cmd, arg = msg:match("^(%S*)%s*(.-)$")
-
- if cmd == "enable" then
- BAA_FLAGTYPE = 1
- print("|cffffff00Busy and Away:|r Your AFK message will be set to your DND message. Upon returning your DND message will still be restored.")
- elseif cmd == "disable" then
- BAA_FLAGTYPE = 2
- print("|cffffff00Busy and Away:|r Your AFK message will no longer be set to your DND message.")
- elseif cmd == "clear" then
- if UnitIsDND("Player") then
- ChatFrame1EditBox:SetText("/busy")
- ChatEdit_SendText(ChatFrame1EditBox)
- end
- BAA_DNDMSG = nil
-
- print("|cffffff00Busy and Away:|r Your DND message has been cleared.")
+local function Grab(var)
+ if BusyAndAwayDB["settings"][var] then
+ return BusyAndAwayDB["settings"][var]
else
- print("|cffffff00Busy and Away")
- print("To manually clear your DND message, use the command \"/baa clear\".")
- print("To set your AFK message to your busy message, use the command \"/baa enable\". Keep in mind that doing this only makes your AFK message match your DND message. When you come back from AFK, your DND will still be restored. To disable, use \"/baa disable\".")
+ return BusyAndAwayDB[var]
end
end
-local f = CreateFrame("Frame")
+-- Hijack Blizz DND slash commands.
+local SetPlayerDND = SlashCmdList["CHAT_DND"]
-f:RegisterEvent("ADDON_LOADED")
-f:RegisterEvent("PLAYER_ENTERING_WORLD")
-f:RegisterEvent("CHAT_MSG_SYSTEM")
-f:RegisterEvent("PLAYER_FLAGS_CHANGED")
+SLASH_BUSYANDAWAYA1, SLASH_BUSYANDAWAYA2 = "/busy", "/dnd"
-local flag
+function SlashCmdList.BUSYANDAWAYA(msg)
+ Set("playermsg", msg)
+ SetPlayerDND(Grab("playermsg"))
+end
+
+-- Event Handlers
+function events:ADDON_LOADED()
+ -- Create or clear DB.
+ if not BusyAndAwayDB or (not UnitIsDND("player") and not UnitIsAFK("player")) then
+ local away = BusyAndAwayDB and BusyAndAwayDB.settings.awaymsg or 1
+ local bnaway = BusyAndAwayDB and BusyAndAwayDB.settings.bnawaymsg or 0
+ local bnbusy = BusyAndAwayDB and BusyAndAwayDB.settings.bnbusymsg or 0
+ BusyAndAwayDB = {settings = {awaymsg = away, bnawaymsg = bnaway, bnbusymsg = bnbusy}}
+ end
+end
-f:SetScript("OnEvent", function(self, event, ...)
- if event == "ADDON_LOADED" then
- local addon = ...
- if addon == "BusyAndAway" then
- print("|cffffff00Busy and Away:|r Use the command \"/baa\" for help and to set your preferences.")
-
- if not BAA_FLAGTYPE then
- BAA_FLAGTYPE = 1
-
- elseif BAA_FLAGTYPE == 1 then
- print("|cffffff00Busy and Away:|r Your AFK message will be set to your DND message. Upon returning your DND message will still be restored.")
+function events:PLAYER_FLAGS_CHANGED()
+ local dnd = UnitIsDND("player")
+ local afk = UnitIsAFK("player")
+
+ if dnd then
+ Set("busy", 1)
+ elseif Grab("busy") and afk and Grab("playermsg") then -- Set AFK message to player's DND message.
+ if Grab("awaymsg") ~= 0 and Grab("playermsg") ~= "" then
+ if not Grab("away") then
+ SendChatMessage("", "AFK")
end
+ Set("away", 1)
+ SendChatMessage(Grab("playermsg"), "AFK")
+ else
+ Set("away", 1)
end
- elseif event == "PLAYER_ENTERING_WORLD" then
- if not UnitIsDND("player") and BAA_DNDMSG then
- BAA_DNDMSG = nil
- end
- elseif event == "CHAT_MSG_SYSTEM" then
- local msg = ...
-
- if msg:find("You are now Busy:") then
- BAA_DNDMSG = msg:match(":%s(.*)")
+ elseif not afk and not dnd then
+ if Grab("busy") and Grab("away") then -- Restore DND message.
+ Set("away", nil)
+ SendChatMessage(Grab("playermsg"), "DND")
+ elseif Grab("busy") then -- Cleared DND status.
+ Set("busy", nil)
+ Set("playermsg", nil)
end
- elseif event == "PLAYER_FLAGS_CHANGED" then
- if UnitIsAFK("player") and BAA_DNDMSG then
- if BAA_FLAGTYPE == 1 then
- -- Need to /afk first to clear the afk and reset with the message.
- ChatFrame1EditBox:SetText("/afk")
- ChatEdit_SendText(ChatFrame1EditBox)
-
- ChatFrame1EditBox:SetText("/afk "..BAA_DNDMSG)
- ChatEdit_SendText(ChatFrame1EditBox)
- end
-
- flag = true
- elseif not UnitIsAFK("player") and not UnitIsDND("player") and BAA_DNDMSG then
- if flag then
- ChatFrame1EditBox:SetText("/busy "..BAA_DNDMSG)
- ChatEdit_SendText(ChatFrame1EditBox)
- flag = nil
+ end
+end
+
+function events:CHAT_MSG_BN_WHISPER(...)
+ if Grab("playermsg") then
+ if UnitIsDND("player") and Grab("bnbusymsg") ~= 0 then
+ BNSendWhisper(select(14, ...), "does not wish to be disturbed: " .. (Grab("playermsg") ~= "" and Grab("playermsg") or "DND"))
+ elseif UnitIsAFK("player") and Grab("bnawaymsg") ~= 0 then
+ if Grab("awaymsg") ~= 0 and Grab("playermsg") ~= "" then
+ BNSendWhisper(select(14, ...), "is Away: " .. Grab("playermsg"))
+ if not Grab("away") then
+ SendChatMessage("", "AFK")
+ end
+ Set("away", 1)
+ SendChatMessage(Grab("playermsg"), "AFK")
else
- BAA_DNDMSG = nil
+ BNSendWhisper(select(14, ...), "is Away: AFK")
+ Set("away", 1)
+ SendChatMessage("", "AFK")
end
end
end
-end)
\ No newline at end of file
+end
diff --git a/Options.lua b/Options.lua
new file mode 100644
index 0000000..87fcfbf
--- /dev/null
+++ b/Options.lua
@@ -0,0 +1,108 @@
+-- Create options panel.
+local addon = {}
+addon.panel = CreateFrame("Frame", nil, UIParent)
+addon.panel:Hide()
+addon.panel.name = "Busy and Away"
+
+addon.childpanel = CreateFrame("Frame", nil, addon.panel)
+addon.childpanel.name = "Help"
+addon.childpanel.parent = addon.panel.name
+
+-- Create addon slash command.
+SLASH_BUSYANDAWAYB1 = "/baa"
+
+function SlashCmdList.BUSYANDAWAYB(msg)
+ if msg == "help" then
+ InterfaceOptionsFrame_OpenToCategory(addon.childpanel)
+ InterfaceOptionsFrame_OpenToCategory(addon.childpanel)
+ else
+ InterfaceOptionsFrame_OpenToCategory(addon.panel)
+ InterfaceOptionsFrame_OpenToCategory(addon.panel)
+ end
+end
+
+-- Main Panel
+local title = addon.panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
+ title:SetText("Busy and Away")
+ title:SetPoint("TOPLEFT", 20, -15)
+
+local settings = addon.panel:CreateFontString(nil, "OVERLAY", "GameFontNormal")
+ settings:SetText("Settings")
+ settings:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -15)
+
+local awaymsg = CreateFrame("CheckButton", nil, addon.panel, "OptionsBaseCheckButtonTemplate")
+ awaymsg:SetPoint("TOPLEFT", settings, "BOTTOMLEFT", 0, -10)
+ awaymsg:SetScript("OnClick", function(self)
+ if self:GetChecked() then
+ BusyAndAwayDB["settings"]["awaymsg"] = 1
+ else
+ BusyAndAwayDB["settings"]["awaymsg"] = 0
+ end
+ end)
+ awaymsg:SetScript("OnShow", function(self)
+ if BusyAndAwayDB["settings"]["awaymsg"] ~= 0 then
+ self:SetChecked()
+ end
+ end)
+
+local awaymsglbl = awaymsg:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
+ awaymsglbl:SetText("Set AFK message to DND message")
+ awaymsglbl:SetPoint("LEFT", awaymsg, "RIGHT", 5, 1)
+
+local bnawaymsg = CreateFrame("CheckButton", nil, addon.panel, "OptionsBaseCheckButtonTemplate")
+ bnawaymsg:SetPoint("TOPLEFT", awaymsg, "BOTTOMLEFT", 0, -5)
+ bnawaymsg:SetScript("OnClick", function(self)
+ if self:GetChecked() then
+ BusyAndAwayDB["settings"]["bnawaymsg"] = 1
+ else
+ BusyAndAwayDB["settings"]["bnawaymsg"] = 0
+ end
+ end)
+ bnawaymsg:SetScript("OnShow", function(self)
+ if BusyAndAwayDB["settings"]["bnawaymsg"] ~= 0 then
+ self:SetChecked()
+ end
+ end)
+
+local bnawaymsglbl = bnawaymsg:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
+ bnawaymsglbl:SetText("Send AFK reply to BN whispers")
+ bnawaymsglbl:SetPoint("LEFT", bnawaymsg, "RIGHT", 5, 1)
+
+local bnbusymsg = CreateFrame("CheckButton", nil, addon.panel, "OptionsBaseCheckButtonTemplate")
+ bnbusymsg:SetPoint("TOPLEFT", bnawaymsg, "BOTTOMLEFT", 0, -5)
+ bnbusymsg:SetScript("OnClick", function(self)
+ if self:GetChecked() then
+ BusyAndAwayDB["settings"]["bnbusymsg"] = 1
+ else
+ BusyAndAwayDB["settings"]["bnbusymsg"] = 0
+ end
+ end)
+ bnbusymsg:SetScript("OnShow", function(self)
+ if BusyAndAwayDB["settings"]["bnbusymsg"] ~= 0 then
+ self:SetChecked()
+ end
+ end)
+
+local bnbusymsglbl = bnbusymsg:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
+ bnbusymsglbl:SetText("Send DND reply to BN whispers")
+ bnbusymsglbl:SetPoint("LEFT", bnbusymsg, "RIGHT", 5, 1)
+
+-- Help Panel
+local childtitle = addon.childpanel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
+ childtitle:SetText("Busy and Away")
+ childtitle:SetPoint("TOPLEFT", 20, -15)
+
+local help = addon.childpanel:CreateFontString(nil, "OVERLAY", "GameFontNormal")
+ help:SetText("Help")
+ help:SetPoint("TOPLEFT", childtitle, "BOTTOMLEFT", 0, -15)
+
+local text = addon.childpanel:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
+ text:SetText("At the moment this addon is pretty straight forward and I don't anticipate anyone really having any questions. That being said, if you need assistance contact me via the addon page on Curse or WoW Interface or email me at addons@niketa.net.")
+ text:SetPoint("TOPLEFT", help, "BOTTOMLEFT", 0, -10)
+ text:SetJustifyH("LEFT")
+ text:CanWordWrap(true)
+ text:SetWidth(580)
+
+
+InterfaceOptions_AddCategory(addon.panel)
+InterfaceOptions_AddCategory(addon.childpanel)