當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。