本文整理汇总了C#中Mooege.Net.MooNet.MooNetClient.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# MooNetClient.SendMessage方法的具体用法?C# MooNetClient.SendMessage怎么用?C# MooNetClient.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mooege.Net.MooNet.MooNetClient
的用法示例。
在下文中一共展示了MooNetClient.SendMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryParse
/// <summary>
/// Parses a read line from console.
/// </summary>
/// <param name="line">The line to be parsed.</param>
/// <param name="client">The invoker client if any.</param>
/// <param name="responseMedium">The response medium to command</param>
public static bool TryParse(string line, MooNetClient client=null, ResponseMediums responseMedium = ResponseMediums.Console)
{
var output = string.Empty;
line = line.Trim().ToLower();
if (line == String.Empty) // just return false, if message is empty.
return false;
if (line[0] != Config.Instance.CommandPrefix) // if line does not start with command-prefix
{
output = "Unknown command: " + line;
if(client==null && responseMedium== ResponseMediums.Console) Logger.Info(output); // only output 'unknown command' message to console.
return false;
}
line = line.Substring(1); // advance to actual command.
var command = line.Split(' ')[0]; // get command
var parameters = String.Empty;
if (line.Contains(' ')) parameters = line.Substring(line.IndexOf(' ') + 1).ToLower().Trim(); // get parameters if any.
foreach(var pair in Commands)
{
if (pair.Key.Command != command) continue;
InvokeCommand(pair.Key, pair.Value, parameters, client, responseMedium);
return true;
}
// if execution reaches here, it means command was not found.
output = "Unknown command: " + line;
// if invoked from console
if (client == null)
{
Logger.Info(output);
return true;
}
// if invoked by a client
if (responseMedium == ResponseMediums.Channel)
client.SendMessage(output);
else if (responseMedium == ResponseMediums.Whisper)
client.SendWhisper(output);
return true;
}
示例2: InvokeCommand
private static void InvokeCommand(CommandAttribute commandAttribute, Command command, string parameters, MooNetClient client = null, ResponseMediums responseMedium = ResponseMediums.Console)
{
var output = string.Empty;
if (client != null && commandAttribute.ConsoleOnly)
output = "You don't have enough privileges to run this command.";
else
output = command.Invoke(parameters, client); // invoke the command
// if invoked from console
if (client == null)
{
Logger.Info(output);
return;
}
// if invoked by a client
if (responseMedium == ResponseMediums.Channel)
client.SendMessage(output);
else if (responseMedium == ResponseMediums.Whisper)
client.SendWhisper(output);
}