Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion AutoFlood.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end

--- Event handler function
--
function AutoFlood_OnEvent(self, event)
function AutoFlood_OnEvent(self, event, ...)
-- Init saved variables
if event == "VARIABLES_LOADED" then

Expand All @@ -50,6 +50,7 @@ function AutoFlood_OnEvent(self, event)
message = "AutoFlood " .. version,
channel = "say",
rate = 60,
toggleOnAFK = false,
}, oldConfig, AF_characterConfig or {})

-- Erase old configuration
Expand All @@ -61,6 +62,11 @@ function AutoFlood_OnEvent(self, event)
local s = string.gsub(AUTOFLOOD_LOAD, "VERSION", version)
DEFAULT_CHAT_FRAME:AddMessage(s, 1, 1, 1)
end

if event == "PLAYER_FLAGS_CHANGED" then
local unit = ...
AutoFloodOnAFK(event, unit)
end
end

--- Enable flood!
Expand All @@ -69,6 +75,7 @@ function AutoFlood_On()
isFloodActive = true
AutoFlood_Info()
AutoFlood_Frame.timeSinceLastUpdate = AF_characterConfig.rate
AutoFloodAFKRegisterEvent()
end

--- Stop flood
Expand Down Expand Up @@ -105,10 +112,14 @@ function AutoFlood_Info()
end

local s = AUTOFLOOD_STATS
local toggleOnAFKState = string.gsub(tostring(AF_characterConfig.toggleOnAFK), "true", AUTOFLOOD_STATE_ENABLED)
local toggleOnAFKState = string.gsub(toggleOnAFKState, "false", AUTOFLOOD_STATE_DISABLED)
s = string.gsub(s, "MESSAGE", AF_characterConfig.message)
s = string.gsub(s, "CHANNEL", AF_characterConfig.channel)
s = string.gsub(s, "RATE", AF_characterConfig.rate)
a = string.gsub(AUTOFLOOD_TOGGLE_ON_AFK, "STATE", toggleOnAFKState)
DEFAULT_CHAT_FRAME:AddMessage(s, 1, 1, 1)
DEFAULT_CHAT_FRAME:AddMessage(a, 1, 1, 1)
end

--- Set the message to send.
Expand Down Expand Up @@ -176,6 +187,31 @@ function AutoFlood_SetChannel(channel)
end
end

function AutoFloodAFK_Toggle(disableOnAFK)
if disableOnAFK == "on" or disableOnAFK == "true" == disableOnAFK == "t" then
AF_characterConfig.toggleOnAFK = true
else
if AF_characterConfig.toggleOnAFK == false then
AF_characterConfig.toggleOnAFK = true
end
end
AutoFloodAFKRegisterEvent()
end

function AutoFloodAFKRegisterEvent()
if AF_characterConfig.toggleOnAFK then
AutoFlood_Frame:RegisterEvent("PLAYER_FLAGS_CHANGED")
else
AutoFlood_Frame:UnregisterEvent("PLAYER_FLAGS_CHANGED")
end
end

function AutoFloodOnAFK(event, unit)
if unit ~= "player" then return end
if not UnitIsAFK("player") then return end
AutoFlood_Off()
end

-- ===========================================
-- Slash command aliases
-- ===========================================
Expand Down Expand Up @@ -213,6 +249,10 @@ SlashCmdList["AUTOFLOODSETRATE"] = AutoFlood_SetRate
-- Display the parameters in chat window
SlashCmdList["AUTOFLOODINFO"] = AutoFlood_Info

-- /floodafk [on|off]
-- Toggle flood disable on afk
SlashCmdList["AUTOFLOODAFK"] = AutoFloodAFK_Toggle

-- /floodhelp
-- Display help in chat window
SlashCmdList["AUTOFLOODHELP"] = function()
Expand All @@ -237,3 +277,4 @@ SLASH_AUTOFLOODINFO2 = "/floodconfig"

SLASH_AUTOFLOODHELP1 = "/floodhelp"
SLASH_AUTOFLOODHELP2 = "/floodman"
SLASH_AUTOFLOODAFK1 = "/floodafk"
6 changes: 6 additions & 0 deletions localization.en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ AUTOFLOOD_INACTIVE = "AutoFlood is disabled."
AUTOFLOOD_ERR_CHAN = "The channel /CHANNEL doesn't exist."
AUTOFLOOD_ERR_RATE = "You can't send messages less than every RATE seconds."

AUTOFLOOD_TOGGLE_ON_AFK = "Toggle on AFK is: STATE"

AUTOFLOOD_STATE_DISABLED = "disabled"
AUTOFLOOD_STATE_ENABLED = "enabled"

AUTOFLOOD_HELP = {
"===================== Auto Flood =====================",
"/flood [on|off] : Start / stops sending the message.",
Expand All @@ -24,4 +29,5 @@ AUTOFLOOD_HELP = {
"/floodrate <duration> : Sets the period (in seconds).",
"/floodinfo : Displays parameters.",
"/floodhelp : Displays this help message.",
"/floodafk [on|off] : Start/stop disable sending the message on AFK",
}
5 changes: 5 additions & 0 deletions localization.fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ if (GetLocale() == "frFR") then
AUTOFLOOD_ERR_CHAN = "Le canal /CHANNEL est invalide."
AUTOFLOOD_ERR_RATE = "Vous ne pouvez pas envoyer de messages à moins de RATE secondes d'intervalle."

AUTOFLOOD_TOGGLE_ON_AFK = "Toggle on AFK is: STATE"

AUTOFLOOD_STATE_DISABLED = "disabled"
AUTOFLOOD_STATE_ENABLED = "enabled"

AUTOFLOOD_HELP = {
"===================== Auto Flood =====================",
"/flood [on|off] : Démarre / arrête l'envoi du message.",
Expand Down