From 629e45fa6224c4d6b74bb8e0e2c642914c4c5b0e Mon Sep 17 00:00:00 2001 From: F16Gaming Date: Tue, 27 Mar 2012 01:26:47 +0200 Subject: [PATCH] Lots of additions, changes and fixes. Battle.Net whisper handling improved! New commands: acceptinvite, raidwarning. New subcommand: set groupinvite Added feature: Informs users who invite the player that !acceptinvite is available (default OFF, configurable delay before sending message). --- BattleNetTools.lua | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ChatManager.lua | 2 +- Command.lua | 47 ++++++++++++++- CommandManager.lua | 34 ++++++++++- Events.lua | 15 +++++ Events_Chat.lua | 11 ++-- PlayerManager.lua | 9 ++- load.xml | 1 + 8 files changed, 267 insertions(+), 14 deletions(-) create mode 100644 BattleNetTools.lua diff --git a/BattleNetTools.lua b/BattleNetTools.lua new file mode 100644 index 0000000..d3a0301 --- /dev/null +++ b/BattleNetTools.lua @@ -0,0 +1,162 @@ +--[[ + * Copyright (c) 2011 by Adam Hellberg. + * + * This file is part of Command. + * + * Command is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Command is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Command. If not, see . +--]] + +local C = Command + +C.BattleNetTools = { + +} + +local BNT = C.BattleNetTools +local CET = C.Extensions.Table + +local Friend = { + PresenceID = 0, + GivenName = "", + SurName = "", + ToonName = "", + ToonID = 0, + Client = "", + IsOnline = false, + LastOnline = 0, + IsAFK = false, + IsDND = false, + BroadcastText = "", + NoteText = "", + IsFriend = false, + BroadcastTime = 0, + Unknown = false +} + +local Toon = { + Unknown = false, + Name = "", + Client = "", + Realm = "", + RealmID = "", + Faction = -1, + FactionString = "", + Race = "", + Class = "", + Unknown2 = "", + Zone = "", + Level = 0, + GameText = "", + BroadcastText = "", + BroadcastTime = "", + Unknown3 = false, + Unknown4 = 0 +} + +local function ParseBNFriendResult(...) + local argc = select("#", ...) + if argc ~= 15 then + error("ParseBNFriendResult expected 15 arguments, got " .. argc) + return nil + end + local id, gName, sName, tName, tId, client, online, last, afk, dnd, bText, note, friend, bTime, u = ... + local f = CET:Copy(Friend) + f.PresenceID = id + f.GivenName = gName + f.SurName = sName + f.ToonName = tName + f.ToonID = tID + f.Client = client + f.IsOnline = online + f.LastOnline = last + f.IsAFK = afk + f.IsDND = dnd + f.BroadcastText = bText + f.NoteText = note + f.IsFriend = friend + f.BroadcastTime = bTime + f.Unknown = u + return f +end + +local function ParseBNToonResult(...) + local argc = select("#", ...) + if argc ~= 16 then + error("ParseBNToonResult expected 16 arguments, got " .. argc) + return nil + end + local u, name, client, realm, realmId, faction, race, class, u2, zone, lvl, text, bText, bTime, u3, u4 = ... + local t = CET:Copy(Toon) + t.Unknown = u + t.Name = name + t.Client = client + t.Realm = realm + t.RealmID = realmId + t.Faction = faction + if t.Faction == 0 then + t.FactionString = "Horde" + elseif t.Faction == 1 then + t.FactionString = "Alliance" + end + t.Race = race + t.Class = class + t.Unknown2 = u2 + t.Zone = zone + t.Level = tonumber(lvl) + t.GameText = text + t.BroadcastText = bText + t.BroadcastTime = bTime + t.Unknown3 = u3 + t.Unknown4 = u4 + return t +end + +function BNT:GetFriend(index) + if index < 1 or index > BNGetNumFriends() then + return nil + end + return ParseBNFriendResult(BNGetFriendInfo(index)) +end + +function BNT:GetFriendById(id) + return ParseBNFriendResult(BNGetFriendInfoByID(id)) +end + +function BNT:GetFriendByName(name) + local n = BNGetNumFriends() + if n <= 0 then return nil end + for i = 1, n do + local friend = ParseBNFriendResult(BNGetFriendInfo(i)) + if friend.ToonName:lower() == name:lower() then + return friend + end + end + return nil +end + +function BNT:GetToon(id) + return ParseBNToonResult(BNGetToonInfo(id)) +end + +function BNT:GetToonByName(name) + local numF = BNGetNumFriends() + if numF <= 0 then return nil end + for i = 1, numF do + for t = 1, BNGetNumFriendToons(i) do + local toon = ParseBNToonResult(BNGetFriendToonInfo(i, t)) + if toon.Name:lower() == name:lower() then return toon end + end + end + return nil +end diff --git a/ChatManager.lua b/ChatManager.lua index f6c9592..a940ca9 100644 --- a/ChatManager.lua +++ b/ChatManager.lua @@ -191,7 +191,7 @@ function CM:SetCmdChar(char) if type(char) ~= "string" then return false, "Command char has to be of type string." end - char = char:lower() + char = char:lower():sub(1, 1) self.Settings.CMD_CHAR = char return "Successfully set the command char to: " .. char end diff --git a/Command.lua b/Command.lua index e58e9f5..7900732 100644 --- a/Command.lua +++ b/Command.lua @@ -32,7 +32,7 @@ Command = { Name = "Command", Version = GetAddOnMetadata("Command", "Version"), - VersionNum = 6, -- Increment on every release + VersionNum = 7, -- Increment on every release VersionChecked = false, -- Prevent spam of "New Version" notice Loaded = false, VarVersion = 2, @@ -91,6 +91,12 @@ function C:LoadSavedVars() if type(self.Settings.ENABLED) ~= "bolean" then self.Settings.ENABLED = true end + if type(self.Settings.GROUP_INVITE_ANNOUNCE) ~= "boolean" then + self.Settings.GROUP_INVITE_ANNOUNCE = false + end + if type(self.Settings.GROUP_INVITE_ANNOUNCE_DELAY) ~= "number" then + self.Settings.GROUP_INVITE_ANNOUNCE_DELAY = 0 + end CM:Init() PM:Init() RM:Init() @@ -167,3 +173,42 @@ end function C:ToggleDebug() return self:SetDebug(not self.Settings.DEBUG) end + +function C:SetGroupInvite(enabled) + self.Settings.GROUP_INVITE_ANNOUNCE = enabled + if self.Settings.GROUP_INVITE_ANNOUNCE then + return "Group Invite (Announce) enabled." + end + return "Group Invite (Announce) disabled." +end + +function C:EnableGroupInvite() + return self:SetGroupInvite(true) +end + +function C:DisableGroupInvite() + return self:SetGroupInvite(false) +end + +function C:ToggleGroupInvite() + return self:SetGroupInvite(not self.Settings.GROUP_INVITE_ANNOUNCE) +end + +function C:SetGroupInviteDelay(time) + if type(time) ~= "number" then + return false, "Delay has to be a number." + end + time = math.ceil(time) + if time > 50 then + return false, "Delay cannot be greater than 50 seconds." + end + self.Settings.GROUP_INVITE_ANNOUNCE_DELAY = time + if self.Settings.GROUP_INVITE_ANNOUNCE_DELAY > 0 then + return "Group Invite (Announce) delay set to " .. self.Settings.GROUP_INVITE_ANNOUNCE_DELAY .. " seconds." + end + return "Group Invite (Announce) delay disabled." +end + +function C:DisableGroupInviteDelay() + return self:SetGroupInviteDelay(0) +end diff --git a/CommandManager.lua b/CommandManager.lua index 48859a5..e172353 100644 --- a/CommandManager.lua +++ b/CommandManager.lua @@ -180,7 +180,7 @@ CM:Register({"version", "ver", "v"}, PM.Access.Groups.User.Level, function(args, end, "Print the version of Command") CM:Register({"set", "s"}, PM.Access.Groups.Admin.Level, function(args, sender, isChat) - local usage = "Usage: set cmdchar" + local usage = "Usage: set cmdchar|groupinvite" if #args <= 0 then return false, usage end @@ -190,6 +190,20 @@ CM:Register({"set", "s"}, PM.Access.Groups.Admin.Level, function(args, sender, i return false, "No command character specified." end return Chat:SetCmdChar(args[2]) + elseif args[1]:match("^g") then -- Group invite (announce) + if #args < 2 then + return false, "Usage: set groupinvite enable|disable|