Quantcast

Added help command and cleaned some code.

F16Gaming (Laptop) [05-15-12 - 08:44]
Added help command and cleaned some code.

New command: help <command> 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.
Filename
CommandManager.lua
GroupTools.lua
locales/enUS.lua
locales/svSE.lua
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 <command>\" to get help on a specific command.",
+	CM_DEFAULT_CHAT = "Type !commands for a listing of commands available. Type !help <command> 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 <command>",
+
 	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|<time>",
-	CM_SET_SETLOCALE_USAGE = "Usage: set setlocale <locale>",
-	CM_SET_LOCALE_USAGE = "Usage: set locale reset|usemaster",
+
+	CM_LOCALE_HELP = "Change locale settings.",
+	CM_LOCALE_USAGE ="Usage: locale [set|reset|usemaster|playerindependent]",
+	CM_LOCALE_CURRENT = "Current locale: %s.",
+	CM_LOCALE_SET_USAGE = "Usage: locale set <locale>",

 	CM_MYLOCALE_HELP = "Let's users set their own locale.",
 	CM_MYLOCALE_SET = "Successfully set your locale to %s.",
diff --git a/locales/svSE.lua b/locales/svSE.lua
index d48f72a..daee112 100644
--- a/locales/svSE.lua
+++ b/locales/svSE.lua
@@ -24,8 +24,8 @@ local L = {

 	LOCALE_NOT_LOADED = "Det specifierade språket är inte initialiserat.",
 	LOCALE_UPDATE = "Nytt språk inställt till: %s",
-	LOCALE_PI_ACTIVE = "Språkinställningar per-användare är nu aktivt.",
-	LOCALE_PI_INACTIVE = "Språkinställningar per-användare är nu inaktivt.",
+	LOCALE_PI_ACTIVE = "Språkinställning per-användare är nu aktivt.",
+	LOCALE_PI_INACTIVE = "Språkinställning per-användare är nu inaktivt.",

 	-------------
 	-- General --
@@ -89,19 +89,26 @@ local L = {
 	CM_NO_HELP = "Ingen hjälp tillgänglig.",

 	CM_DEFAULT_HELP = "Visar det här hjälpmeddelandet.",
-	CM_DEFAULT_CHAT = "Skriv !commands för en lista över kommandon.",
+	CM_DEFAULT_HELPCOMMAND = "Use \"help <command>\" to get help on a specific command.",
+	CM_DEFAULT_CHAT = "Skriv !commands för en lista över kommandon. Skriv !help <command> för hjälp med ett specifikt kommando.",
 	CM_DEFAULT_END = "Slut på hjälpmeddelandet.",

+	CM_HELP_HELP = "Gets help about the addon or a specific command.",
+	CM_HELP_USAGE = "Användning: help <command>",
+
 	CM_COMMANDS_HELP = "Visa alla registrerade kommandon.",

 	CM_VERSION_HELP = "Visa versionen av Command",
 	CM_VERSION = "%s",

 	CM_SET_HELP = "Ändra inställningarna i Command.",
-	CM_SET_USAGE = "Användning: set cmdchar|groupinvite|setlocale|locale",
+	CM_SET_USAGE = "Användning: set cmdchar|groupinvite",
 	CM_SET_GROUPINVITE_USAGE = "Användning: set groupinvite enable|disable|<tid>",
-	CM_SET_SETLOCALE_USAGE = "Användning: set setlocale <språk>",
-	CM_SET_LOCALE_USAGE = "Användning: set locale reset|usemaster",
+
+	CM_LOCALE_HELP = "Change locale settings.",
+	CM_LOCALE_USAGE ="Användning: locale [set|reset|usemaster|playerindependent]",
+	CM_LOCALE_CURRENT = "Current locale: %s.",
+	CM_LOCALE_SET_USAGE = "Användning: locale set <locale>",

 	CM_MYLOCALE_HELP = "Låter användare ställa in sitt eget språk.",
 	CM_MYLOCALE_SET = "Ditt språk är nu inställt till %s.",
@@ -150,16 +157,16 @@ local L = {
 	CM_DEOPME_HELP = "Player issuing this command will be demoted from assistant status.",

 	CM_LEADER_HELP = "Promote a player to group leader.",
-	CM_LEADER_USAGE = "Usage: leader <name>",
+	CM_LEADER_USAGE = "Användning: leader <name>",

 	CM_PROMOTE_HELP = "Promote a player to raid assistant.",
-	CM_PROMOTE_USAGE = "Usage: promote <name>",
+	CM_PROMOTE_USAGE = "Användning: promote <name>",

 	CM_DEMOTE_HELP = "Demote a player from assistant status.",
-	CM_DEMOTE_USAGE = "Usage: demote <name>",
+	CM_DEMOTE_USAGE = "Användning: demote <name>",

 	CM_QUEUE_HELP = "Enter the LFG queue for the specified category.",
-	CM_QUEUE_USAGE = "Usage: queue <type>",
+	CM_QUEUE_USAGE = "Användning: queue <type>",
 	CM_QUEUE_INVALID = "No such dungeon type: %q.",

 	CM_LEAVELFG_HELP = "Lämna LFG-kön.",
@@ -170,7 +177,7 @@ local L = {
 	CM_ACCEPTLFG_NOEXIST = "There is currently no LFG proposal to accept.",

 	CM_CONVERT_HELP = "Convert group to party or raid.",
-	CM_CONVERT_USAGE = "Usage: convert party||raid",
+	CM_CONVERT_USAGE = "Användning: convert party||raid",
 	CM_CONVERT_LFG = "LFG groups cannot be converted.",
 	CM_CONVERT_NOGROUP = "Cannot convert if not in a group.",
 	CM_CONVERT_NOLEAD = "Cannot convert group, not leader.",
@@ -181,27 +188,27 @@ local L = {
 	CM_CONVERT_INVALID = "Invalid group type, only \"party\" or \"raid\" allowed.",

 	CM_LIST_HELP = "Toggle status of a command on the blacklist/whitelist.",
-	CM_LIST_USAGE = "Usage: list <command>",
+	CM_LIST_USAGE = "Användning: list <command>",

 	CM_LISTMODE_HELP = "Toggle list between being a blacklist and being a whitelist.",

 	CM_GROUPALLOW_HELP = "Allow a group to use a specific command.",
-	CM_GROUPALLOW_USAGE = "Usage: groupallow <group> <command>",
+	CM_GROUPALLOW_USAGE = "Användning: groupallow <group> <command>",

 	CM_GROUPDENY_HELP = "Deny a group to use a specific command.",
-	CM_GROUPDENY_USAGE = "Usage: groupdeny <group> <command>",
+	CM_GROUPDENY_USAGE = "Användning: groupdeny <group> <command>",

 	CM_RESETGROUPACCESS_HELP = "Reset the group's access to a specific command.",
-	CM_RESETGROUPACCESS_USAGE = "Usage: resetgroupaccess <group> <command>",
+	CM_RESETGROUPACCESS_USAGE = "Användning: resetgroupaccess <group> <command>",

 	CM_USERALLOW_HELP = "Allow a user to use a specific command.",
-	CM_USERALLOW_USAGE = "Usage: userallow <player> <command>",
+	CM_USERALLOW_USAGE = "Användning: userallow <player> <command>",

 	CM_USERDENY_HELP = "Deny a user to use a specific command.",
-	CM_USERDENY_USAGE = "Usage: userdeny <player> <command>",
+	CM_USERDENY_USAGE = "Användning: userdeny <player> <command>",

 	CM_RESETUSERACCESS_HELP = "Reset the user's access to a specific command.",
-	CM_RESETUSERACCESS_USAGE = "Usage: resetuseraccess <player> <command>",
+	CM_RESETUSERACCESS_USAGE = "Användning: resetuseraccess <player> <command>",

 	CM_TOGGLE_HELP = "Toggle AddOn on and off.",

@@ -217,23 +224,29 @@ local L = {
 	CM_READYCHECK_FAIL = "Failed to accept or decline ready check.",

 	CM_LOOT_HELP = "Provides various loot functions.",
-	CM_LOOT_USAGE = "Usage: loot type||threshold||master||pass",
+	CM_LOOT_USAGE = "Användning: loot type||threshold||master||pass",
 	CM_LOOT_LFG = "Cannot use loot command in LFG group.",
 	CM_LOOT_NOMETHOD = "No loot method specified.",
 	CM_LOOT_NOTHRESHOLD = "No loot threshold specified.",
 	CM_LOOT_NOMASTER = "No master looter specified.",

 	CM_ROLL_HELP = "Provides tools for managing or starting/stopping rolls.",
-	CM_ROLL_USAGE = "Usage: roll [start||stop||pass||time||do||set]",
-	CM_ROLL_START_USAGE = "Usage: roll start <[time] [item]>",
-	CM_ROLL_SET_USAGE = "Usage: roll set min||max||time <amount>",
+	CM_ROLL_USAGE = "Användning: roll [start||stop||pass||time||do||set]",
+	CM_ROLL_START_USAGE = "Användning: roll start <[time] [item]>",
+	CM_ROLL_SET_USAGE = "Användning: roll set min||max||time <amount>",

 	CM_RAIDWARNING_HELP = "Sends a raid warning.",
-	CM_RAIDWARNING_USAGE = "Usage: raidwarning <message>",
+	CM_RAIDWARNING_USAGE = "Användning: raidwarning <message>",
 	CM_RAIDWARNING_NORAID = "Cannot send raid warning when not in a raid group.",
 	CM_RAIDWARNING_NOPRIV = "Cannot send raid warning: Not raid leader or assistant.",
 	CM_RAIDWARNING_SENT = "Sent raid warning.",

+	CM_DUNGEONMODE_HELP = "Set the dungeon difficulty.",
+	CM_DUNGEONMODE_USAGE = "Användning: dungeondifficulty <difficulty>",
+
+	CM_RAIDMODE_HELP = "Set the raid difficulty.",
+	CM_RAIDMODE_USAGE = "Användning: raiddifficulty <difficulty>",
+
 	------------
 	-- Events --
 	------------
@@ -391,6 +404,25 @@ local L = {
 	PM_LIST_SETWHITE = "Now using list as whitelist.",
 	PM_LIST_SETBLACK = "Now using list as blacklist.",

+	----------------
+	-- GroupTools --
+	----------------
+
+	GT_DUNGEON_NORMAL = "Normal",
+	GT_DUNGEON_HEROIC = "Heroic",
+	GT_RAID_N10 = "Normal (10)",
+	GT_RAID_N25 = "Normal (25)",
+	GT_RAID_H10 = "Heroic (10)",
+	GT_RAID_H25 = "Heroic (25)",
+
+	GT_DIFF_INVALID = "%q is not a valid difficulty.",
+
+	GT_DD_DUPE = "Dungeon difficulty is already set to %s.",
+	GT_DD_SUCCESS = "Successfully set the dungeon difficulty to %s!",
+
+	GT_RD_DUPE = "Raid difficulty is already set to %s.",
+	GT_RD_SUCCESS = "Successfully set raid difficulty to %s!",
+
 	------------------
 	-- QueueManager --
 	------------------