本文整理汇总了C#中ISender.GetAvailableCommands方法的典型用法代码示例。如果您正苦于以下问题:C# ISender.GetAvailableCommands方法的具体用法?C# ISender.GetAvailableCommands怎么用?C# ISender.GetAvailableCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISender
的用法示例。
在下文中一共展示了ISender.GetAvailableCommands方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowHelp
/// <summary>
/// Shows the help.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="args">Arguments.</param>
public static void ShowHelp(ISender sender, ArgumentList args)
{
var commands = sender.GetAvailableCommands();
if (commands != null && commands.Count > 0)
{
int page = 0;
if (!args.TryGetInt(0, out page))
{
if (args.Count > 0)
{
var command = args.GetString(0);
if (commands.ContainsKey(command))
{
sender.SendMessage(commands[command].description);
commands[command].ShowHelp(sender, true);
return;
}
else
throw new CommandError("No such command: " + command);
}
}
else
page--;
// const Int32 MaxLines = 5;
var maxLines = sender is Player ? 5 : 15;
var lineOffset = page * maxLines;
var maxPages = (int)Math.Ceiling(commands.Count / (double)maxLines);
if (page >= 0 && page < maxPages)
{
var cmds = new List<CommandInfo>();
var sorted = commands
.OrderBy(x => x.Key.ToLower())
.Select(x => x.Value)
.ToArray();
for (var i = lineOffset; i < lineOffset + maxLines; i++)
{
if (i < sorted.Length)
cmds.Add(sorted[i]);
}
var prefixMax = cmds
.Select(x => x.Prefix.Length)
.OrderByDescending(x => x)
.First();
foreach (var cmd in cmds)
cmd.ShowDescription(sender, prefixMax);
sender.SendMessage(String.Format("[Page {0} / {1}]", page + 1, maxPages));
}
else
{
sender.SendMessage("Usage:");
sender.SendMessage(" help <command> - Get help for a command.");
sender.SendMessage(" help <page> - View a list of commands. Valid page numbers are 1 to " + maxPages + ".");
sender.SendMessage("Examples:");
sender.SendMessage(" help oplogin");
sender.SendMessage(" help 1");
}
}
else
sender.SendMessage("You have no available commands.");
}