当前位置: 首页>>代码示例>>C#>>正文


C# MooNetClient.SendMessage方法代码示例

本文整理汇总了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;
        }
开发者ID:MacGiver,项目名称:mooege,代码行数:51,代码来源:CommandManager.cs

示例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);
        }
开发者ID:MacGiver,项目名称:mooege,代码行数:22,代码来源:CommandManager.cs


注:本文中的Mooege.Net.MooNet.MooNetClient.SendMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。