diff --git a/ChatManager.lua b/ChatManager.lua index 214b3e1..f6c9592 100644 --- a/ChatManager.lua +++ b/ChatManager.lua @@ -35,7 +35,22 @@ C.ChatManager = { LocalOnly = false }, LastChannel = nil, - LastTarget = nil + LastTarget = nil, + RespondChannel = { + CHAT_MSG_BATTLEGROUND = "BATTLEGROUND", + CHAT_MSG_BATTLEGROUND_LEADER = "BATTLEGROUND", + CHAT_MSG_CHANNEL = "CHANNEL", + CHAT_MSG_GUILD = "WHISPER", + CHAT_MSG_OFFICER = "WHISPER", + CHAT_MSG_PARTY = "PARTY", + CHAT_MSG_PARTY_LEADER = "PARTY", + CHAT_MSG_RAID = "RAID", + CHAT_MSG_RAID_LEADER = "RAID", + CHAT_MSG_RAID_WARNING = "RAID_WARNING", + CHAT_MSG_SAY = "WHISPER", + CHAT_MSG_WHISPER = "WHISPER", + CHAT_MSG_YELL = "WHISPER" + } } local CM = C.ChatManager @@ -45,11 +60,38 @@ local AC = C.AddonComm local CCM = C.CommandManager local CES = C.Extensions.String +--- Initialize ChatManager. +-- +function CM:Init() + self:LoadSavedVars() +end + +--- Load saved variables. +-- +function CM:LoadSavedVars() + if type(C.Settings.CHAT) ~= "table" then + C.Settings.CHAT = {} + end + self.Settings = C.Settings.CHAT + if type(self.Settings.CMD_CHAR) ~= "string" then + self.Settings.CMD_CHAR = self.Default.CmdChar + end + if type(self.Settings.LOCAL_ONLY) ~= "boolean" then + self.Settings.LOCAL_ONLY = self.Default.LocalOnly + end +end + --- Get the channel to be used as a response channel based on event name. -- @param event Full name of the event. -- @return The channel to be used as response channel. -- function CM:GetRespondChannelByEvent(event) + if self.RespondChannel[event] then + return self.RespondChannel[event] + end + return "SAY" + + --[[ local respondChannel = "SAY" if event == "CHAT_MSG_BATTLEGROUND" then respondChannel = "BATTLEGROUND" @@ -83,27 +125,7 @@ function CM:GetRespondChannelByEvent(event) respondChannel = "YELL" end return respondChannel -end - ---- Initialize ChatManager. --- -function CM:Init() - self:LoadSavedVars() -end - ---- Load saved variables. --- -function CM:LoadSavedVars() - if type(C.Settings.CHAT) ~= "table" then - C.Settings.CHAT = {} - end - self.Settings = C.Settings.CHAT - if type(self.Settings.CMD_CHAR) ~= "string" then - self.Settings.CMD_CHAR = self.Default.CmdChar - end - if type(self.Settings.LOCAL_ONLY) ~= "boolean" then - self.Settings.LOCAL_ONLY = self.Default.LocalOnly - end + --]] end --- Send a chat message. @@ -112,9 +134,10 @@ end -- @param channel The channel to send to. -- @param target Player or channel index to send message to. -- -function CM:SendMessage(msg, channel, target) +function CM:SendMessage(msg, channel, target, isBN) + isBN = isBN or false if not self.Settings.LOCAL_ONLY then - msg = ("[%s] %s"):format(C.Name, msg) + msg = ("[%s] %s"):format(C.Name, tostring(msg)) if channel == "SMART" then if GT:IsRaid() then channel = "RAID" @@ -122,9 +145,19 @@ function CM:SendMessage(msg, channel, target) channel = "PARTY" else C.Logger:Normal(msg) + return + end + elseif channel == "RAID_WARNING" then + if not GT:IsRaidLeaderOrAssistant() then + self:SendMessage(msg, "SMART", target, isBN) + return end end - SendChatMessage(msg, channel, nil, target) + if isBN then + BNSendWhisper(target, msg) + else + SendChatMessage(msg, channel, nil, target) + end else C.Logger:Normal(msg) end @@ -154,6 +187,15 @@ function CM:IsCommand(msg) return CES:StartsWith(msg, self.Settings.CMD_CHAR) end +function CM:SetCmdChar(char) + if type(char) ~= "string" then + return false, "Command char has to be of type string." + end + char = char:lower() + self.Settings.CMD_CHAR = char + return "Successfully set the command char to: " .. char +end + --- Handle a chat message. -- @param msg The message to handle. -- @param sender Player object of the player who sent the message. @@ -161,10 +203,10 @@ end -- @param target Player or channel index. -- @param isBN True if battle.net message, false or nil otherwise. -- -function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN) +function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN, pID) isBN = isBN or false + pID = pID or nil target = target or sender - if isBN then return end local raw = msg msg = CES:Trim(msg) local args = self:ParseMessage(msg) @@ -183,18 +225,21 @@ function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN) table.insert(t, args[i]) end end - local player = PM:GetOrCreatePlayer(sender) local result, err = CCM:HandleCommand(cmd, t, true, player) + if isBN then + target = pID + sender = pID + end if result then if type(result) == "table" then - for _,v in pairs(result) do - self:SendMessage(tostring(v), channel, target) + for _,v in ipairs(result) do + self:SendMessage(tostring(v), channel, target, isBN) end else - self:SendMessage(tostring(result), channel, target) + self:SendMessage(tostring(result), channel, target, isBN) end else - self:SendMessage(tostring(err), "WHISPER", sender) + self:SendMessage(tostring(err), "WHISPER", sender, isBN) end end diff --git a/Command.lua b/Command.lua index 2481902..e58e9f5 100644 --- a/Command.lua +++ b/Command.lua @@ -32,7 +32,7 @@ Command = { Name = "Command", Version = GetAddOnMetadata("Command", "Version"), - VersionNum = 5, -- Increment on every release + VersionNum = 6, -- Increment on every release VersionChecked = false, -- Prevent spam of "New Version" notice Loaded = false, VarVersion = 2, diff --git a/CommandManager.lua b/CommandManager.lua index 0058193..48859a5 100644 --- a/CommandManager.lua +++ b/CommandManager.lua @@ -40,14 +40,14 @@ local QM = C.QueueManager local RM = C.RollManager local LM = C.LootManager local GT = C.GroupTools +local Chat local CES = C.Extensions.String local CET = C.Extensions.Table --- Initialize CommandManager. --- NOTE: Unused. -- function CM:Init() - + Chat = C.ChatManager end --- Register a new command. @@ -179,6 +179,21 @@ CM:Register({"version", "ver", "v"}, PM.Access.Groups.User.Level, function(args, return C.Version end, "Print the version of Command") +CM:Register({"set", "s"}, PM.Access.Groups.Admin.Level, function(args, sender, isChat) + local usage = "Usage: set cmdchar" + if #args <= 0 then + return false, usage + end + args[1] = args[1]:lower() + if args[1]:match("^c") then -- Command Char setting + if #args < 2 then + return false, "No command character specified." + end + return Chat:SetCmdChar(args[2]) + end + return false, usage +end, "Control the settings of Command.") + CM:Register({"lock", "lockdown"}, PM.Access.Groups.Admin.Level, function(args, sender, isChat) if type(args[1]) == "string" then return PM:SetLocked(PM:GetOrCreatePlayer(args[1]), true) @@ -530,6 +545,9 @@ CM:Register({"readycheck", "rc"}, PM.Access.Groups.Op.Level, function(args, send end, "Respond to ready check or initate a new one.") CM:Register({"loot", "l"}, PM.Access.Groups.Op.Level, function(args, sender, isChat) + if GT:IsLFGGroup() then + return false, "Cannot use loot command in LFG group." + end local usage = "Usage: loot <type||threshold||master||pass>" if #args <= 0 then return false, usage @@ -631,6 +649,18 @@ CM:Register({"roll", "r"}, PM.Access.Groups.Op.Level, function(args, sender, isC return false, "Usage: roll [start||stop||pass||time||do||set]" end, "Provides tools for managing or starting/stopping rolls.") +CM:Register({"raidwarning", "rw", "raid_warning"}, PM.Access.Groups.User.Level, function(args, sender, isChat) + if not GT:IsRaid() then + return false, "Cannot send raid warning when not in a raid group." + elseif not GT:IsRaidLeaderOrAssistant() then + return false, "Cannot send raid warning: Not raid leader or assistant." + elseif #args <= 0 then + return false, "Usage: raidwarning <message>" + end + Chat:SendMessage(args[1], "RAID_WARNING") + return "Sent raid warning." +end, "Sends a raid warning.") + for i,v in ipairs(CM.Slash) do _G["SLASH_" .. C.Name:upper() .. i] = "/" .. v end diff --git a/Events_Chat.lua b/Events_Chat.lua index 93feea9..1fa26d7 100644 --- a/Events_Chat.lua +++ b/Events_Chat.lua @@ -50,18 +50,41 @@ function C.Events.CHAT_MSG_BATTLEGROUND_LEADER(self, event, ...) CM:HandleMessage(msg, sender, chan) end -function T.Events.CHAT_MSG_BN_CONVERSATION(self, event, ...) +function C.Events.CHAT_MSG_BN_CONVERSATION(self, event, ...) end +--]] -function T.Events.CHAT_MSG_BN_WHISPER(self, event, ...) +--- Event handler for CHAT_MSG_BN_WHISPER. +-- @name Command.Events.CHAT_MSG_BN_WHISPER +-- @param self Reference to Command object. +-- @param event Full name of event. +-- @param ... Event arguments. +-- +function C.Events.CHAT_MSG_BN_WHISPER(self, event, ...) + local chan = "BNET" + local msg = (select(1, ...)) + local id = (select(13, ...)) + local _, name, client, realm, _, faction, _, _, _, _, _, _, _, _ = BNGetToonInfo(id) + if not name or client:lower() ~= "wow" then return end + if faction == 0 then faction = "horde" elseif faction == 1 then faction = "alliance" end + if realm:lower() == GetRealmName():lower() and faction == (select(1, UnitFactionGroup("player"))):lower() then + CM:HandleMessage(msg, name, chan, id, chan, true, id) + end end +--[[ +--- Event handler for CHAT_MSG_CHANNEL. +-- @name Command.Events.CHAT_MSG_CHANNEL +-- @param self Reference to Command object. +-- @param event Full name of event. +-- @param ... Event arguments. +-- function C.Events.CHAT_MSG_CHANNEL(self, event, ...) local chan = CM:GetRespondChannelByEvent(event) local msg = (select(1, ...)) local sender = (select(2, ...)) local target = (select(8, ...)) - CM:HandleMessage(msg, sender, chan, target) + CM:HandleMessage(msg, sender, chan, nil, "CHANNEL") end --]] @@ -156,14 +179,18 @@ function C.Events.CHAT_MSG_RAID_WARNING(self, event, ...) CM:HandleMessage(msg, sender, chan, nil, "RAID") end ---[[ +--- Event handler for CHAT_MSG_SAY. +-- @name Command.Events.CHAT_MSG_SAY +-- @param self Reference to Command object. +-- @param event Full name of event. +-- @param ... Event arguments. +-- function C.Events.CHAT_MSG_SAY(self, event, ...) local chan = CM:GetRespondChannelByEvent(event) local msg = (select(1, ...)) local sender = (select(2, ...)) CM:HandleMessage(msg, sender, chan) end ---]] --- Event handler for CHAT_MSG_WHISPER. -- @name Command.Events.CHAT_MSG_WHISPER @@ -179,11 +206,15 @@ function C.Events.CHAT_MSG_WHISPER(self, event, ...) CM:HandleMessage(msg, sender, chan, target, "WHISPER") end ---[[ +--- Event handler for CHAT_MSG_YELL. +-- @name Command.Events.CHAT_MSG_YELL +-- @param self Reference to Command object. +-- @param event Full name of event. +-- @param ... Event arguments. +-- function C.Events.CHAT_MSG_YELL(self, event, ...) local chan = CM:GetRespondChannelByEvent(event) local msg = (select(1, ...)) local sender = (select(2, ...)) CM:HandleMessage(msg, sender, chan) end ---]] diff --git a/GroupTools.lua b/GroupTools.lua index dc5d658..1e41ab5 100644 --- a/GroupTools.lua +++ b/GroupTools.lua @@ -44,7 +44,11 @@ end -- @return True if the player is in an LFG group, false otherwise. -- function GT:IsLFGGroup() - return (select(1, GetLFGMode())) == "lfgparty" + local status, _ = GetLFGMode() + if status == "abandonedInDungeon" or status == "lfgparty" then + return true + end + return false end --- Check if player is in a raid.