local z={startsWith=function(z,R)if z:sub(1,#R)==R then return z:sub(#R+1)end end}return{Name="\114\117\110\105\102",Aliases={};Description="\082\117\110\115 \097 \103\105\118\101\110 \099\111\109\109\097\110\100 \115\116\114\105\110\103 \105\102 \097 \099\101\114\116\097\105\110 \099\111\110\100\105\116\105\111\110 \105\115 \109\101\116\046";Group="\068\101\102\097\117\108\116\085\116\105\108";Args={{Type="\099\111\110\100\105\116\105\111\110\070\117\110\099\116\105\111\110";Name="\067\111\110\100\105\116\105\111\110",Description="\084\104\101 \099\111\110\100\105\116\105\111\110 \102\117\110\099\116\105\111\110"};{Type="\115\116\114\105\110\103";Name="\065\114\103\117\109\101\110\116",Description="\084\104\101 \097\114\103\117\109\101\110\116 \116\111 \116\104\101 \099\111\110\100\105\116\105\111\110 \102\117\110\099\116\105\111\110"};{Type="\115\116\114\105\110\103";Name="\084\101\115\116 \097\103\097\105\110\115\116",Description="\084\104\101 \116\101\120\116 \116\111 \116\101\115\116 \097\103\097\105\110\115\116\046"};{Type="\115\116\114\105\110\103";Name="\067\111\109\109\097\110\100",Description="\084\104\101 \099\111\109\109\097\110\100 \115\116\114\105\110\103 \116\111 \114\117\110 \105\102 \114\101\113\117\105\114\101\109\101\110\116\115 \097\114\101 \109\101\116\046 \073\102 \111\109\105\116\116\101\100\044 \114\101\116\117\114\110 \118\097\108\117\101 \102\114\111\109 \099\111\110\100\105\116\105\111\110 \102\117\110\099\116\105\111\110 \105\115 \117\115\101\100\046";Optional=true}};Run=function(R,y,r,f,l)local o=z[y]if not o then return("\067\111\110\100\105\116\105\111\110 \037\113 \105\115 \110\111\116 \118\097\108\105\100\046"):format(y)end local M=o(f,r)if M then return R.Dispatcher:EvaluateAndRun(R.Cmdr.Util.RunEmbeddedCommands(R.Dispatcher,l or M))end return""end}
local conditions = {
	startsWith = function (text, arg)
		if text:sub(1, #arg) == arg then
			return text:sub(#arg + 1)
		end
	end
}

return {
	Name = "runif";
	Aliases = {};
	Description = "Runs a given command string if a certain condition is met.";
	Group = "DefaultUtil";
	Args = {
		{
			Type = "conditionFunction";
			Name = "Condition";
			Description = "The condition function"
		},
		{
			Type = "string";
			Name = "Argument";
			Description = "The argument to the condition function"
		},
		{
			Type = "string";
			Name = "Test against";
			Description = "The text to test against."
		},
		{
			Type = "string";
			Name = "Command";
			Description = "The command string to run if requirements are met. If omitted, return value from condition function is used.";
			Optional = true;
		},
	};

	Run = function(context, condition, arg, testAgainst, command)
		local conditionFunc = conditions[condition]

		if not conditionFunc then
			return ("Condition %q is not valid."):format(condition)
		end

		local text = conditionFunc(testAgainst, arg)

		if text then
			return context.Dispatcher:EvaluateAndRun(context.Cmdr.Util.RunEmbeddedCommands(context.Dispatcher, command or text))
		end

		return ""
	end
}