From 5ce4a8fd3ad8b11bd000bcc2d1ed6f79f0d12b69 Mon Sep 17 00:00:00 2001 From: "F16Gaming (Laptop)" Date: Tue, 15 May 2012 10:44:07 +0200 Subject: [PATCH] Added help command and cleaned some code. New command: help shows help about a specific command. Moved locale settings to their own command: locale. Updated dungeon/raid difficulty commands to work better. Updated localization. Cleaned up some code. --- CommandManager.lua | 93 ++++++++++++++++++++++++++++++++++------------------ GroupTools.lua | 12 +++++++ locales/enUS.lua | 15 ++++++--- locales/svSE.lua | 78 ++++++++++++++++++++++++++++++------------- 4 files changed, 139 insertions(+), 59 deletions(-) diff --git a/CommandManager.lua b/CommandManager.lua index 6070cde..69e578a 100644 --- a/CommandManager.lua +++ b/CommandManager.lua @@ -73,7 +73,14 @@ function CM:Register(names, access, func, help) if names[1] ~= "__DEFAULT__" then names[1] = names[1]:lower() end - local entry = {Name=names[1], Access=access, Call=func, Help=help, Alias={}} + local entry = + { + Name = names[1], + Access = access, + Call = func, + Help = help or "CM_NO_HELP", + Alias = {} + } if #names > 1 then for i=2,#names do table.insert(entry.Alias, names[i]:lower()) @@ -160,6 +167,7 @@ function CM:HandleCommand(command, args, isChat, player) end --- Prints all command names together with their help messages. +-- function CM:AutoHelp() local l = L:GetActive() for k,v in pairs(self.Commands) do @@ -168,14 +176,33 @@ function CM:AutoHelp() end end -CM:Register({"__DEFAULT__", "help", "h"}, PM.Access.Local, function(args, sender, isChat) +function CM:GetHelp(cmd) + cmd = tostring(cmd):lower() + if not self:HasCommand(cmd) then return false, "CM_ERR_NOTREGGED" end + local command = self:GetCommand(cmd) + return command.Help or "CM_NO_HELP" +end + + +CM:Register({"__DEFAULT__"}, PM.Access.Local, function(args, sender, isChat) if isChat then return "CM_DEFAULT_CHAT" end CM:AutoHelp() + C.Logger:Normal(L("CM_DEFAULT_HELPCOMMAND")) return "CM_DEFAULT_END" end, "CM_DEFAULT_HELP") +CM:Register({"help", "h"}, PM.Access.Groups.User.Level, function(args, sender, isChat) + if #args <= 0 then + if isChat then + return "CM_DEFAULT_CHAT" + end + return false, "CM_HELP_USAGE" + end + return CM:GetHelp(tostring(args[1]):lower()) +end, "CM_HELP_HELP") + CM:Register({"commands", "cmds", "cmdlist", "listcmds", "listcommands", "commandlist"}, PM.Access.Groups.User.Level, function(args, sender, isChat) local all if #args > 0 then @@ -213,34 +240,36 @@ CM:Register({"set", "s"}, PM.Access.Groups.Admin.Level, function(args, sender, i return C:DisableGroupInvite() end return false, "CM_SET_GROUPINVITE_USAGE" - elseif args[1]:match("^s.*l") then -- Set locale - if #args < 2 then - return false, "CM_SET_SETLOCALE_USAGE" - end - local locale = tostring(args[2]):lower() - return L:SetLocale(locale) - elseif args[1]:match("^l") then -- Other locale settings + end + return false, "CM_SET_USAGE" +end, "CM_SET_HELP") + +CM:Register({"locale", "loc"}, PM.Access.Local, function(args, sender, isChat) + if isChat then return false, "CM_ERR_NOCHAT" end + if #args <= 0 then + return "CM_LOCALE_CURRENT", {L.Settings.LOCALE} + end + local arg = tostring(args[1]):lower() + if arg:match("^s") then -- Set if #args < 2 then - return false, "CM_SET_LOCALE_USAGE" + return false, "CM_LOCALE_SET_USAGE" end - local sub = tostring(args[2]):lower() - if sub:match("^r") or sub:match("^u.*a") then -- Reset / Use active - return L:ResetLocale() - elseif sub:match("^u.*m") then -- Use master - return L:UseMasterLocale() - elseif sub:match("^p.*i") then -- Player Independent - local enabled = tostring(args[3]):lower() - if enabled:match("^[eay]") then - return L:EnablePlayerIndependent() - elseif enabled:match("^[dn]") then - return L:DisablePlayerIndependent() - end - return L:TogglePlayerIndependent() + return L:SetLocale(tostring(args[2]):lower()) + elseif arg:match("^r") or arg:match("^u.*a") then -- Reset / Use Active + return L:ResetLocale() + elseif arg:match("^u.*m") then -- Use Master + return L:UseMasterLocale() + elseif arg:match("^p.*i") then -- Player Independent + local enabled = tostring(args[3]):lower() + if enabled:match("^[eay]") then + return L:EnablePlayerIndependent() + elseif enabled:match("^[dn]") then + return L:DisablePlayerIndependent() end - return false, "CM_SET_LOCALE_USAGE" + return L:TogglePlayerIndependent() end - return false, "CM_SET_USAGE" -end, "CM_SET_HELP") + return false, "CM_LOCALE_USAGE" +end, "CM_LOCALE_HELP") CM:Register({"mylocale", "ml"}, PM.Access.Groups.User.Level, function(args, sender, isChat) if not isChat then @@ -759,16 +788,16 @@ CM:Register({"raidwarning", "rw", "raid_warning"}, PM.Access.Groups.User.Level, return "CM_RAIDWARNING_SENT" end, "CM_RAIDWARNING_HELP") -CM:Register({"dungeondifficulty", "dd", "dungeonmode", "dm"}, PM.Access.Groups.User.Level, function(args, sender, isChat) +CM:Register({"dungeondifficulty", "dungeondiff", "dd", "dungeonmode", "dm"}, PM.Access.Groups.User.Level, function(args, sender, isChat) if #args < 1 then - return GT:GetFrindlyDungeonDifficulty() + return GT:GetDungeonDifficultyString() end local diff = args[1]:lower() if diff:match("^n") then diff = GT.Difficulty.Dungeon.Normal elseif diff:match("^h") then diff = GT.Difficulty.Dungeon.Heroic - elseif tonumber(diff) + elseif tonumber(diff) then diff = tonumber(diff) else return false, "CM_DUNGEONMODE_USAGE" @@ -776,9 +805,9 @@ CM:Register({"dungeondifficulty", "dd", "dungeonmode", "dm"}, PM.Access.Groups.U return GT:SetDungeonDifficulty(diff) end, "CM_DUNGEONMODE_HELP") -CM:Register({"raiddifficulty", "rd", "raidmode", "rm"}, PM.Access.Groups.User.Level, function(args, sender, isChat) +CM:Register({"raiddifficulty", "raiddiff", "rd", "raidmode", "rm"}, PM.Access.Groups.User.Level, function(args, sender, isChat) if #args < 1 then - return GT:GetFriendlyRaidDifficulty() + return GT:GetRaidDifficultyString() end local diff = args[1]:lower() if diff:match("^n.*1") then @@ -789,7 +818,7 @@ CM:Register({"raiddifficulty", "rd", "raidmode", "rm"}, PM.Access.Groups.User.Le diff = GT.Difficulty.Raid.Heroic10 elseif diff:match("^h.*2") then diff = GT.Difficulty.Raid.Heroic25 - elseif tonumber(diff) + elseif tonumber(diff) then diff = tonumber(diff) else return false, "CM_RAIDMODE_USAGE" diff --git a/GroupTools.lua b/GroupTools.lua index 261d1cc..a87f756 100644 --- a/GroupTools.lua +++ b/GroupTools.lua @@ -178,6 +178,10 @@ function GT:SetDungeonDifficulty(diff) return "GT_DD_SUCCESS", {self:GetFriendlyDungeonDifficulty(diff)} end +function GT:GetDungeonDifficultyString(diff) + return self.Difficulty.Dungeon[tonumber(diff) or GetDungeonDifficulty()] +end + --- Get a string representation of the dungeon difficulty. -- @param diff (number) Difficulty to parse, defaults to current difficulty. -- @return String representation of dungeon difficulty. @@ -203,6 +207,14 @@ end -- @param diff (number) Difficulty to parse, defaults to current difficulty. -- @return String representation of raid difficulty. -- +function GT:GetRaidDifficultyString(diff) + return self.Difficulty.Raid[tonumber(diff) or GetRaidDifficulty()] +end + +--- Get a string representation of the raid difficulty. +-- @param diff (number) Difficulty to parse, defaults to current difficulty. +-- @return String representation of raid difficulty. +-- function GT:GetFriendlyRaidDifficulty(diff) return L(self.Difficulty.Raid[tonumber(diff) or GetRaidDifficulty()]) end diff --git a/locales/enUS.lua b/locales/enUS.lua index 43db291..cadd148 100644 --- a/locales/enUS.lua +++ b/locales/enUS.lua @@ -89,19 +89,26 @@ local L = { CM_NO_HELP = "No help available.", CM_DEFAULT_HELP = "Prints this help message.", - CM_DEFAULT_CHAT = "Type !commands for a listing of commands available.", + CM_DEFAULT_HELPCOMMAND = "Use \"help \" to get help on a specific command.", + CM_DEFAULT_CHAT = "Type !commands for a listing of commands available. Type !help for help on a specific command.", CM_DEFAULT_END = "End of help message.", + CM_HELP_HELP = "Gets help about the addon or a specific command.", + CM_HELP_USAGE = "Usage: help ", + CM_COMMANDS_HELP = "Print all registered commands.", CM_VERSION_HELP = "Print the version of Command.", CM_VERSION = "%s", CM_SET_HELP = "Control the settings of Command.", - CM_SET_USAGE = "Usage: set cmdchar|groupinvite|setlocale|locale", + CM_SET_USAGE = "Usage: set cmdchar|groupinvite", CM_SET_GROUPINVITE_USAGE = "Usage: set groupinvite enable|disable|