// Weather Bot // Returns the weather in the city you want. For students finished with the tutorial using System; using System.Text.RegularExpressions; //For the Regex type variable using System.Xml; //For parsing the weather RSS feed namespace ChatBot { class WeatherBot : BasicBot { public override string HandleMessage(string message, string user) { if (User.RegexMatch("weather|temperature", message) || state != "0") { if (state == "1" && User.RegexMatch("(?[a-zA-Z ]+),(?[a-zA-Z ]+)", message)) { Regex locationr = new Regex(@"(weather )?(?[a-zA-Z\s]+),(?[a-zA-Z\s]+)"); Match locationm = locationr.Match(message); string city = locationm.Groups["city"].Value; string stateS = locationm.Groups["state"].Value; state = "0"; return "The current conditions in " + city + ", " + stateS + " are: " + User.RSSWeatherToday(city, stateS); } if (User.RegexMatch("in (?[a-zA-Z ]+),(?[a-zA-Z ]+)", message)) { Regex locationr = new Regex(@"in (?[a-zA-Z\s]+),(?[a-zA-Z\s]+)"); Match locationm = locationr.Match(message); string city = locationm.Groups["city"].Value; string stateS = locationm.Groups["state"].Value; state = "0"; return "The current conditions in " + city + ", " + stateS + " are: " + User.RSSWeatherToday(city, stateS); } else { state = "1"; return "The weather in what city and state?"; } } else return "Hi, I'm the weather bot. Ask about today's weather!"; } } }