From da828b0ff6852ebf54129b8396cc1f4d28908969 Mon Sep 17 00:00:00 2001 From: F16Gaming Date: Tue, 18 Dec 2012 01:49:56 +0100 Subject: [PATCH] New feature and optimizations Added new feature: FactsManager Changed ChatManager to use a better system for RAW-type messages --- ChatManager.lua | 15 +++- Command.lua | 3 + CommandManager.lua | 51 ++++++++++++- FactsLoader.xml | 24 ++++++ FactsManager.lua | 158 +++++++++++++++++++++++++++++++++++++++ facts/cat.lua | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++++ load.xml | 3 +- 7 files changed, 457 insertions(+), 6 deletions(-) create mode 100644 FactsLoader.xml create mode 100644 FactsManager.lua create mode 100644 facts/cat.lua diff --git a/ChatManager.lua b/ChatManager.lua index cc0d2cb..f076fa6 100644 --- a/ChatManager.lua +++ b/ChatManager.lua @@ -60,6 +60,10 @@ C.ChatManager = { CHAT_MSG_SAY = "WHISPER", CHAT_MSG_WHISPER = "WHISPER", CHAT_MSG_YELL = "WHISPER" + }, + SpecialOutput = { + Raw = 1, + RawTable = 2 } } @@ -111,6 +115,7 @@ end -- @param target Player or channel index to send message to. -- @param isBN Is this message targeted to a BNet friend? -- @param smartSay Fallback to SAY instead of local logging if not in group +-- @param raw If true, do not escape pipe characters -- function CM:SendMessage(msg, channel, target, isBN, smartSay, raw) isBN = isBN or false @@ -227,7 +232,7 @@ function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN, pID end local player = PM:GetOrCreatePlayer(sender, realm) local result, arg, errArg, extra = CCM:HandleCommand(cmd, t, sourceChannel, player, bnetInfo) - local raw = (extra and type(errArg) == "table") or (errArg and type(arg) == "table") or (arg and type(arg ~= "table")) + local raw = (extra and type(errArg) == "table") or (errArg and type(arg) == "table") or (arg and type(arg) ~= "table") if isBN then target = pID sender = pID @@ -249,7 +254,7 @@ function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN, pID self:SendMessage(s, channel, target, isBN, nil, raw) end end - elseif result == "RAW_TABLE_OUTPUT" then + elseif result == self.SpecialOutput.RawTable then if type(arg) ~= "table" then error("Received RAW_TABLE_OUTPUT request, but arg was of type '" .. type(arg) .. "', expected 'table', aborting...") return @@ -257,6 +262,12 @@ function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN, pID for _,v in ipairs(arg) do self:SendMessage(tostring(v), channel, target, isBN, nil, raw) end + elseif result == self.SpecialOutput.Raw then + if type(arg) ~= "string" then + error("Received RAW_OUTPUT request, but arg was of type '" .. type(arg) .."', expected 'string', aborting...") + return + end + self:SendMessage(arg, channel, target, isBN, nil, raw) else local s = l[result] if type(arg) == "table" then diff --git a/Command.lua b/Command.lua index f118be4..3319523 100644 --- a/Command.lua +++ b/Command.lua @@ -59,6 +59,7 @@ local AC local DM local SM local IM +local FM local CDM local CRM local RCM @@ -83,6 +84,7 @@ function C:Init() DM = self.DeathManager SM = self.SummonManager IM = self.InviteManager + FM = self.FactsManager CDM = self.DuelManager CRM = self.RoleManager RCM = self.ReadyCheckManager @@ -126,6 +128,7 @@ function C:LoadSavedVars() DM:Init() SM:Init() IM:Init() + FM:Init() CDM:Init() CRM:Init() RCM:Init() diff --git a/CommandManager.lua b/CommandManager.lua index 9837b27..0741392 100644 --- a/CommandManager.lua +++ b/CommandManager.lua @@ -73,6 +73,7 @@ local AM = C.AuthManager local DM = C.DeathManager local SM = C.SummonManager local IM = C.InviteManager +local FM = C.FactsManager local CDM = C.DuelManager local CRM = C.RoleManager local RCM = C.ReadyCheckManager @@ -242,7 +243,7 @@ CM:Register({"commands", "cmds", "cmdlist", "listcmds", "listcommands", "command all = args[1] == "all" end local cmds = CM:GetCommands(all) - return "RAW_TABLE_OUTPUT", CES:Fit(cmds, 240, ", ") -- Max length is 255, "[Command] " takes up 10. This leaves us with 5 characters grace. + return Chat.SpecialOutput.RawTable, CES:Fit(cmds, 240, ", ") -- Max length is 255, "[Command] " takes up 10. This leaves us with 5 characters grace. end, "CM_COMMANDS_HELP") CM:Register({"version", "ver", "v"}, PM.Access.Groups.User.Level, function(args, sender, isChat, bnetInfo) @@ -1200,7 +1201,6 @@ CM:Register({"emote", "em", "e"}, PM.Access.Groups.User.Level, function(args, se if #args < 1 then return false, "CM_EMOTE_USAGE" end - return EM:DoEmote(args[1]) end, "CM_EMOTE_HELP") @@ -1209,6 +1209,49 @@ CM:Register({"sit"}, PM.Access.Groups.User.Level, function(args, sender, isChat, return EM:DoEmote(EM.Emotes.Sit) end, "CM_SIT_HELP") +CM:Register({"fact", "facts"}, PM.Access.Groups.User.Level, function(args, sender, isChat, bnetInfo) + if #args < 1 then + return false, "CM_FACT_USAGE" + end + return FM:AnnounceFact(args[1]) +end, "CM_FACT_HELP") + +-- Alias for !fact cat +CM:Register({"cat", "c", "meow"}, PM.Access.Groups.User.Level, function(args, sender, isChat, bnetInfo) + return FM:AnnounceFact("cat") +end, "CM_CAT_HELP") + +CM:Register({"factsettings", "factsetting", "factset"}, PM.Access.Groups.Admin.Level, function(args, sender, isChat, bnetInfo) + if #args < 1 then + if FM:IsEnabled() then + return "CM_FACTSETTINGS_ENABLED" + end + return "CM_FACTSETTINGS_DISABLED" + end + local option = args[1]:lower() + if option:match("^no") then -- NoDupe + if sub:match("^[eay]") then -- Enable NoDupe + return FM:EnableNoDupe() + elseif sub:match("^[dnc]") then -- Disable NoDupe + return FM:DisableNoDupe() + elseif sub:match("^t") then -- Toggle NoDupe + return FM:ToggleNoDupe() + else + if FM:IsNoDupeEnabled() then + return "CM_FACTSETTINGS_NODUPE_ENABLED" + end + return "CM_FACTSETTINGS_NODUPE_DISABLED" + end + elseif option:match("^[eay]") then -- Enable + return FM:Enable() + elseif option:match("^[dnc][^o]") then -- Disable + return FM:Disable() + elseif option:match("^t") then -- Toggle + return FM:Toggle() + end + return false, "CM_FACTSETTINGS_USAGE" +end, "CM_FACTSETTINGS_HELP") + for i,v in ipairs(CM.Slash) do _G["SLASH_" .. C.Name:upper() .. i] = "/" .. v end @@ -1236,10 +1279,12 @@ SlashCmdList[C.Name:upper()] = function(msg, editBox) C.Logger:Normal(s) end end - elseif result == "RAW_TABLE_OUTPUT" then + elseif result == Chat.SpecialOutput.RawTable then for _,v in ipairs(arg) do C.Logger:Normal(tostring(v)) end + elseif result == Chat.SpecialOutput.Raw then + C.Logger:Normal(tostring(arg)) else local s = l[result] if type(arg) == "table" then diff --git a/FactsLoader.xml b/FactsLoader.xml new file mode 100644 index 0000000..e59c8b9 --- /dev/null +++ b/FactsLoader.xml @@ -0,0 +1,24 @@ + + + +