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


C# IncomingMessage.HasMessage方法代码示例

本文整理汇总了C#中IncomingMessage.HasMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IncomingMessage.HasMessage方法的具体用法?C# IncomingMessage.HasMessage怎么用?C# IncomingMessage.HasMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IncomingMessage的用法示例。


在下文中一共展示了IncomingMessage.HasMessage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleCommand

        public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
        {
            CommandManager commands = CommandManager.GetInstance();
            if (!msg.HasMessage())
            {

                msg.SendChat("Available commands: " + commands.AvailableCommands());
                return;
            }

            string cmd = msg.Message.ToLower();
            if (!commands.HasCommand(cmd))
            {
                msg.SendChat("No help for command: " + cmd);
            }
            else
            {
                string help = commands.GetCommand(cmd).Help();
                if (help == null || help.Equals(""))
                {
                    msg.SendChat("No help available for: " + cmd);
                }
                else
                {
                    msg.SendChat("Help for " + cmd + ": " + help);
                }
            }
        }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:28,代码来源:Help.cs

示例2: HandleCommand

        public void HandleCommand(IRCServer server, string command, IncomingMessage message)
        {
            if (!message.HasMessage())
            {
                // bad syntax
                return;
            }

            if (COMMAND_REGEX.IsMatch(message.Message))
            {
                Match m = COMMAND_REGEX.Match(message.Message);
                string cmd = m.Groups[1].Value;

                if (cmd.Equals("about"))
                {
                    if (m.Groups[2].Value == null || m.Groups[2].Value.Equals(""))
                    {
                        message.SendChat("Need context");
                    }

                    string markov = MarkovDatabaseAdapter.MarkovFind(m.Groups[2].Value, m.Groups[3].Value);
                    if (markov == null || markov.Equals(""))
                    {
                        message.SendChat("I can't :(");
                    }
                    else
                    {
                        message.SendChat(markov);
                    }
                }
            }
        }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:32,代码来源:Markov.cs

示例3: HandleCommand

 public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
 {
     if (msg.HasMessage())
     {
         string nick = msg.Message.Split(' ')[0];
         server.Nick = nick;
     }
 }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:8,代码来源:ChangeNick.cs

示例4: HandleCommand

 public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
 {
     if (msg.HasMessage())
     {
         server.Write("QUIT :" + msg.Message);
     }
     else
     {
         server.Write("QUIT :Bye!");
     }
     server.Flush();
     server.Dispose();
 }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:13,代码来源:Kill.cs

示例5: HandleCommand

        public void HandleCommand(IRCServer server, string command, IncomingMessage message)
        {
            if (message.HasMessage())
            {
                string msg = message.Message;
                string target = message.Target;
                string[] parts = message.Message.Split(new char[] { ' ' }, 2);
                if (parts[0].StartsWith("{") && parts[0].EndsWith("}") && parts.Length > 1)
                {
                    target = parts[0].Replace("{", "").Replace("}", "");
                    msg = parts[1];
                }

                server.SendMessage(target, msg);
            }
        }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:16,代码来源:Say.cs

示例6: HandleCommand

        public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
        {
            if (msg.HasMessage())
            {
                string channel = msg.Message;
                string partMessage = "Bye!";
                if (command.Equals("part"))
                {
                    string[] parts;
                    if (msg.Message.Contains(" "))
                    {
                        parts = msg.Message.Split(new char[] { ' ' }, 2);
                    }
                    else
                    {
                        parts = new string[] { msg.Message };
                    }

                    if (parts.Length > 1)
                    {
                        if (parts[0].StartsWith("#"))
                        {
                            channel = parts[0];
                            partMessage = parts[1];
                        }
                        else
                        {
                            partMessage = msg.Message;
                        }

                    }
                    server.PartChannel(channel, partMessage);
                }
                else
                {
                    server.JoinChannel(msg.Message);
                }
            }
            else
            {
                msg.SendChat(Help());
            }
        }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:43,代码来源:ChannelChange.cs

示例7: HandleCommand

 public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
 {
     if (!msg.HasMessage())
     {
         // oh no
         return;
     }
     string nick = msg.Message.ToLower().Split(new char[] { ' ' }, 2)[0];
     string lastSeenEvent = Database.GetKeyValue(server, "lastseen.event." + nick);
     if (lastSeenEvent == null)
     {
         msg.SendChat("Have not seen " + nick);
     }
     else
     {
         TimeSpan t = TimeSpan.FromMilliseconds(Environment.TickCount - long.Parse(Database.GetKeyValue(msg.Server, "lastseen.time." + nick)));
         string answer = string.Format("{0:D2} hours, {1:D2} minutes, {2:D2} seconds",
                                 t.Hours,
                                 t.Minutes,
                                 t.Seconds);
         msg.SendChat(string.Format("Last seen {0}: {1} ago, {2}", nick, answer, lastSeenEvent));
     }
 }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:23,代码来源:Seen.cs

示例8: Handle

        public void Handle(IncomingMessage msg)
        {
            if (!msg.IsDestChannel() || !msg.HasMessage())
            {
                return;
            }
            if (SED_REGEX.IsMatch(msg.Message))
            {
                string lastmessage = Database.GetKeyValue(msg.Server, LASTMESSAGE_PREFIX + msg.Sender);
                if (lastmessage == null || lastmessage.Equals(""))
                {
                    // oh no
                    return;
                }

                string reply;
                Match m = SED_REGEX.Match(msg.Message);
                if (m.Groups[3] == null || m.Groups[3].Value.Equals(""))
                {
                    reply = ReplaceFirst(lastmessage, m.Groups[1].Value, m.Groups[2].Value);
                }
                else if (m.Groups[3] != null && m.Groups[3].Value.Equals("g"))
                {
                    reply = lastmessage.Replace(m.Groups[1].Value, m.Groups[2].Value);
                }
                else
                {
                    msg.SendChat(msg.Sender + ": You did something wrong...");
                    return;
                }
                msg.SendChat(msg.Sender + " meant: " + reply);
            }
            else
            {
                Database.SetKeyValue(msg.Server, LASTMESSAGE_PREFIX + msg.Sender, msg.Message);
            }
        }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:37,代码来源:SedListener.cs

示例9: HandleCommand

        public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
        {
            try
            {
                string location;
                if (!msg.HasMessage())
                {
                    location = Database.GetKeyValue(msg.Server, "weather.lastlocation." + msg.Sender);
                    if (location == null)
                    {
                        msg.SendChat(msg.Sender + ": No previous location stored");
                        return;
                    }
                }
                else
                {
                    location = msg.Message;
                    Database.SetKeyValue(msg.Server, "weather.lastlocation." + msg.Sender, location);
                }

                long lastquery = -1;
                try
                {
                    lastquery = long.Parse(Database.GetKeyValue(msg.Server, "weather.lastquery." + location));
                }
                catch (Exception)
                {
                    lastquery = -1;
                }

                if (lastquery > 0 && Environment.TickCount - lastquery < TIMEOUT)
                {
                    string lastdata = Database.GetKeyValue(msg.Server, "weather.lastdata." + location);
                    if (lastdata != null && !lastdata.Equals(""))
                    {
                        msg.SendChat(msg.Sender + ": " + lastdata);
                    }
                    else
                    {
                        // oh no
                    }
                }
                else
                {
                    string location_encoded = Uri.EscapeUriString(location);
                    Database.SetKeyValue(msg.Server, "weather.lastquery." + location, Environment.TickCount);
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(WEATHER_URL + location_encoded);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    string responseContent;
                    using (var streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        responseContent = streamReader.ReadToEnd();
                    }

                    JObject json = JObject.Parse(responseContent);

                    Database.SetKeyValue(msg.Server, "weather.lastquery." + location, Environment.TickCount);

                    JToken list = json["list"][0];
                    StringBuilder w = new StringBuilder("Weather for " + list["name"].ToString() + ", " + list["sys"]["country"].ToString() + ", ");

                    JToken weather = list["weather"][0];
                    string description = weather["description"].ToString();
                    if (description != null && !description.Equals(""))
                    {
                        w.Append(description).Append(", ");
                    }

                    JToken main = list["main"]; JToken wind = list["wind"];
                    w.Append(string.Format("Temp {0}c (min {1}c/max {2}c), {3}% Humidity, {4} hPa, {5}% Cloudy, Wind Speed {6}m/s",
                        main["temp"].ToString(),
                        main["temp_min"].ToString(),
                        main["temp_max"].ToString(),
                        main["humidity"].ToString(),
                        main["pressure"].ToString(),
                        list["clouds"]["all"].ToString(),
                        wind["speed"].ToString()));

                    JToken windGust = wind["gust"];
                    if (windGust != null)
                    {
                        w.Append(string.Format(" (gusting {0}m/s)", windGust.ToString()));
                    }

                    string formatted = w.ToString();
                    Database.SetKeyValue(msg.Server, "weather.lastdata." + location, formatted);
                    msg.SendChat(msg.Sender + ": " + formatted);
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
        }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:94,代码来源:Weather.cs

示例10: HandleCommand

        public void HandleCommand(IRCServer server, string command, IncomingMessage msg)
        {
            if (!msg.HasMessage())
            {
                msg.SendChat(Help());
                return;
            }

            string term = msg.Message;
            long lastquery;
            try
            {
                lastquery = long.Parse(Database.GetKeyValue(msg.Server, LASTQUERY_PREFIX + term));
            }
            catch (Exception)
            {
                lastquery = -1;
            }

            if (lastquery > 0 && Environment.TickCount - lastquery < TIMEOUT)
            {
                string lastdata = Database.GetKeyValue(msg.Server, LASTRESULT_PREFIX + term);
                if (lastdata != null && !lastdata.Equals(""))
                {
                    msg.SendChat(msg.Sender + ": " + lastdata);
                }
                else
                {
                    msg.SendChat(string.Format("{0}: There was an error last time retrieving the definition for {1}, please try again in {2} minute(s)", msg.Sender, term,
                            TimeSpan.FromMilliseconds(TIMEOUT - (Environment.TickCount - lastquery)).Minutes));
                }
            }
            else
            {
                string term_encoded;
                try
                {
                    term_encoded = Uri.EscapeUriString(term);
                }
                catch (Exception)
                {
                    msg.SendChat(msg.Sender + ": Error parsing location," + msg.Message);
                    return;
                }
                Database.SetKeyValue(msg.Server, LASTQUERY_PREFIX + term, Environment.TickCount);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URBAN_URL + term_encoded);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string responseContent;
                using (var streamReader = new StreamReader(response.GetResponseStream()))
                {
                    responseContent = streamReader.ReadToEnd();
                }

                JObject json = JObject.Parse(responseContent);
                StringBuilder definition = new StringBuilder("Urban definition of `" + term + "`: ");

                try
                {
                    definition.Append(json["list"][0]["definition"].ToString());
                }
                catch (Exception)
                {
                    msg.SendChat(msg.Sender + ": Error parsing urban data for, " + msg.Message);
                    return;
                }

                string formatted = definition.ToString();
                Database.SetKeyValue(msg.Server, LASTRESULT_PREFIX + term, formatted);
                msg.SendChat(msg.Sender + ": " + formatted);
            }
        }
开发者ID:krich38,项目名称:Watson-CSharp,代码行数:71,代码来源:UrbanDictionary.cs


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