local loaded = CreateFrame("FRAME", "Loaded") |
local messages = CreateFrame("FRAME", "Messages") |
|
loaded:RegisterEvent("ADDON_LOADED") |
messages:RegisterEvent("CHAT_MSG_WHISPER") |
messages:RegisterEvent("CHAT_MSG_PARTY") |
messages:RegisterEvent("CHAT_MSG_PARTY_LEADER") |
|
local Player = UnitName("player") |
|
if Defaults == nil then |
Defaults = |
{ |
Prefix = "!", |
Debug = false, |
} |
end |
|
local C = |
{ |
Player = "player", |
W = "whisper", |
|
Addon = { |
Author = GetAddOnMetadata("_GautrReply", "author"), |
Version = GetAddOnMetadata("_GautrReply", "version"), |
Notes = GetAddOnMetadata("_GautrReply", "notes"), |
Title = GetAddOnMetadata("_GautrReply", "title"), |
Prefix = "|cffffd700_GautrReply|r: ", |
}, |
Command = { |
Percent = { |
Current = "percentcurrent", |
Left = "percent", |
CurrentTwo = "%current", |
LeftTwo = "%", |
}, |
Experience = { |
Current = "expcurrent", |
Left = "exp", |
}, |
Bars = { |
Current = "barscurrent", |
Left = "bars", |
}, |
Help = { |
Text = "help", |
}, |
Position = { |
Text = "position", |
}, |
}, |
} |
|
local function messagesHandler(self, event, msg, sender) |
local coordX, coordY = GetPlayerMapPosition(Player) |
|
local Messages = |
{ |
Percent = { |
Current = (format("Currently at: %d%s", (floor(UnitXP(Player) / UnitXPMax(Player) * 100)), "%")), |
Left = (format("%d%s Left to Level", (100 - floor(UnitXP(Player) / UnitXPMax(Player) * 100)), "%")), |
}, |
Experience = { |
Current = (format("Current Experience: %d / %d", (UnitXP(Player)), (UnitXPMax(Player)))), |
Left = (format("Experience Left to Level: %d / %d ", (UnitXPMax(Player) - UnitXP(Player)), UnitXPMax(Player))), |
}, |
Bars = { |
Current = (format("%s %d/20", "Bars ", (math.floor(20*UnitXP(Player)/UnitXPMax(Player)+0.5)))), |
Left = (format("%s %d", "Bars Left", (20 - math.floor(20*UnitXP(Player)/UnitXPMax(Player)+0.5)))), |
}, |
Help = { |
Text = (format("%s%s%s", "Type ", Defaults.Prefix, " followed by any of the following commands 'bars, barscurrent, exp, expcurrent, position, percent, percentcurrent")), |
}, |
Position = { |
Text = (format("I'm in %s @ %d,%d", GetRealZoneText(), (coordX*100 ), (coordY*100))) |
}, |
} |
|
if Defaults.Debug then |
print("Event: "..event) |
print("Player: "..sender) |
print("Message: "..msg) |
else |
if msg:lower():match(Defaults.Prefix .. C.Command.Percent.Current) or |
msg:lower():match(Defaults.Prefix .. C.Command.Percent.CurrentTwo then |
if sender ~= Player then wSend(Messages.Percent.Current, sender) |
else print(C.Addon.Prefix .. Messages.Percent.Current) end |
|
elseif msg:lower():match(Defaults.Prefix .. C.Command.Percent.Left) or |
msg:lower():match(Defaults.Prefix .. C.Command.Percent.LeftTwo then |
if sender ~= Player then wSend(Messages.Percent.Left, sender) |
else print(C.Addon.Prefix .. Messages.Percent.Left) end |
|
elseif msg:lower():match(Defaults.Prefix .. C.Command.Experience.Current) then |
if sender ~= Player then wSend(Messages.Experience.Current, sender) |
else print(C.Addon.Prefix .. Messages.Experience.Current) end |
|
elseif msg:lower():match(Defaults.Prefix .. C.Command.Experience.Left) then |
if sender ~= Player then wSend(Messages.Experience.Left, sender) |
else print(C.Addon.Prefix .. Messages.Experience.Left) end |
|
elseif msg:lower():match(Defaults.Prefix .. C.Command.Bars.Current) then |
if sender ~= Player then wSend(Messages.Bars.Current, sender) |
else print(C.Addon.Prefix .. Messages.Bars.Current) end |
|
elseif msg:lower():match(Defaults.Prefix .. C.Command.Bars.Left) then |
if sender ~= Player then wSend(Messages.Bars.Left, sender) |
else print(C.Addon.Prefix .. Messages.Bars.Left) end |
|
elseif msg:lower():match(Defaults.Prefix .. C.Command.Help.Text) then |
if sender ~= Player then wSend(Messages.Help.Text, sender) |
else print(C.Addon.Prefix .. Messages.Help.Text) end |
|
elseif msg:lower():match(Defaults.Prefix .. C.Command.Position.Text) then |
if sender ~= Player then wSend(Messages.Position.Text, sender) |
else print(C.Addon.Prefix .. Messages.Position.Text) end |
end |
end |
end |
|
SLASH_GAUTRREPLY1, SLASH_GAUTRREPLY2, SLASH_GAUTRREPLY3 = '/gautr', '/gr', '/gautrreply'; |
|
local function handler(msg, editbox) |
local command, rest = msg:match("^(%S*)%s*(.-)$"); |
if command == "prefix" then |
if rest == "" then |
print("|cffffd700" .. C.Addon.Title .. "|r: Type a symbol, the default is '|cffffd700!|r'. Currently it is "..Defaults.Prefix); |
elseif rest ~= nil then |
Defaults.Prefix = rest |
end |
elseif command == "debug" then |
if rest == "" then |
local check = Defaults.Debug and "ON" or "OFF" |
print("|cffffd700" .. C.Addon.Title .. "|r: Type '/gr debug on' to turn on, off to turn off... Its currently " .. tostring(check)) |
elseif rest == "on" then |
Defaults.Debug = true |
local check = Defaults.Debug and "ON" or "OFF" |
print("|cffffd700" .. C.Addon.Title .. "|r: Debug is now " .. tostring(check)) |
elseif rest == "off" then |
Defaults.Debug = false |
local check = Defaults.Debug and "ON" or "OFF" |
print("|cffffd700" .. C.Addon.Title .. "|r: Debug is now " .. tostring(check)) |
end |
elseif command == "test" then |
wSend("!pos", Player); |
else |
print("|cffffd700" .. C.Addon.Title .. "|r: Type '/gr', '/gautr' or '/gautrreply' and either prefix or debug for info"); |
end |
end |
SlashCmdList["GAUTRREPLY"] = handler; |
|
function loaded:OnEvent(event, arg1) |
local addonName = "_GautrReply" |
Defaults.Debug = false |
if event == "ADDON_LOADED" and arg1 == addonName then |
print("|cffffd700".. arg1 .. " ".. C.Addon.Version .."|r".. " by " .. "|cffffd700" .. C.Addon.Author .. "|r"); |
end |
end |
|
local filterStrings = { |
C.Command.Help.Text, |
C.Command.Experience.Left, |
C.Command.Experience.Current, |
C.Command.Position.Text, |
C.Command.Percent.Left, |
C.Command.Percent.Current, |
C.Command.Bars.Left, |
C.Command.Bars.Current, |
} |
|
function wSend(wMsg, wTarget) |
SendChatMessage(wMsg, C.W, nil, wTarget) |
end |
|
--[[ Modified Decount code, Credits goes to Tekkub ]]-- |
local function filter(self, event, msg) |
for _,str in pairs(filterStrings) do |
if msg:lower():match(Defaults.Prefix..str) then |
if Defaults.Debug then |
print("Filtered Incoming Command: " .. "|cffffd700" ..str:upper().."|r in |cffffd700" .. event.."|r") |
end |
return true end |
end |
end |
|
--for _,event in pairs{"CHAT_MSG_WHISPER", "CHAT_MSG_PARTY", "CHAT_MSG_PARTY_LEADER"} do |
for _,event in pairs{"CHAT_MSG_WHISPER"} do |
ChatFrame_AddMessageEventFilter(event, filter) |
end |
|
loaded:SetScript("OnEvent", loaded.OnEvent); |
messages:SetScript("OnEvent", messagesHandler); |