public async Task <string> BuildResult() { WeatherClient OWM = new WeatherClient("88597cb7a556c191905de0f52f23d7d6"); var res = await OWM.Forecast(Location); var r = res[Offset]; StringBuilder sb = new StringBuilder(); if (Measure(Measurement.Temp)) { sb.Append($"The temperature on {r.Date} in {Location} is {r.Temp}\r\n"); } if (Measure(Measurement.Pressure)) { sb.Append($"The pressure on {r.Date} in {Location} is {r.Pressure}\r\n"); } if (Measure(Measurement.Humidity)) { sb.Append($"Humidity on {r.Date} in {Location} is {r.Humidity}\r\n"); } if (sb.Length == 0) { return("I do not understand"); } else { return(sb.ToString()); } }
private static async Task CompleteDialog(IDialogContext context, ComplexWeatherForm state) { await context.PostAsync("Wait a sec. Thinking...", "en-US"); var weatherClient = new WeatherClient("88597cb7a556c191905de0f52f23d7d6"); string message; try { var forecastArray = await weatherClient.Forecast(state.City); var forecast = forecastArray?.SingleOrDefault(f => f.When.Date == state.Date?.Date); if (forecast != null) { if (state.Parameter == ComplexParameterOptions.Humidity) { message = $"The humidity on {forecast.ShortDate} in {forecast.City} is {forecast.Humidity}\r\n"; } else if (state.Parameter == ComplexParameterOptions.Pressure) { message = $"The pressure on {forecast.ShortDate} in {forecast.City} is {forecast.Pressure}\r\n"; } else if (state.Parameter == ComplexParameterOptions.Temperature) { message = $"The temperature on {forecast.ShortDate} in {forecast.City} is {forecast.Temp}\r\n"; } else { message = "Sorry, unknown parameter \"{parameter}\" requested... Try again"; } } else { message = "Sorry! I was not able to get the forecast."; } } catch (Exception) { message = $"Sorry! I was not able to get the forecast."; } await context.PostAsync(message, "en-US"); context.Done<object>(null); }
public async Task GetWether(IDialogContext context, LuisResult result) { var parameter = "temperature"; var location = "Moscow"; DateTime date = DateTime.Today.Date; EntityRecommendation entityContainer; if (result.TryFindEntity("builtin.geography.city", out entityContainer)) { location = entityContainer.Entity; } if (result.TryFindEntity("builtin.datetime.date", out entityContainer)) { DateTime.TryParse(entityContainer?.Resolution?.SingleOrDefault().Value, out date); } if (result.TryFindEntity("parameter", out entityContainer)) { parameter = entityContainer.Entity; } var weatherClient = new WeatherClient("88597cb7a556c191905de0f52f23d7d6"); var forecastArray = await weatherClient.Forecast(location); var forecast = forecastArray.SingleOrDefault(f => f.When.Date == date.Date); string message; if (forecast != null) { if (parameter.Contains("humid")) { message = $"The humidity on {forecast.Date} in {location} is {forecast.Humidity}\r\n"; } else if (parameter.Contains("pres")) { message = $"The pressure on {forecast.Date} in {location} is {forecast.Pressure}\r\n"; } else if (parameter.Contains("temp")) { message = $"The temperature on {forecast.Date} in {location} is {forecast.Temp}\r\n"; } else { message = "Sorry, unknown parameter \"{parameter}\" requested... Try again"; } } else { message = "Sorry! I was not able to get the forecast."; } await context.PostAsync(message, "en-US"); //await context.PostWithTranslationAsync(message, "en-US", Thread.CurrentThread.CurrentCulture.Name); context.Wait(MessageReceived); }
public async Task <string> GetWeather() { var owm = new WeatherClient("522ea52cffe0c78955e0e319e1572a7b"); var res = await owm.Forecast("rostov-on-don"); var weather = res[0]; var sb = new StringBuilder(); sb.Append(weather.Temp < -10 ? $"Ужасно холодно, на улице {weather.Temp}! Лучше сидеть дома. " : (DateTime.Now.DayOfWeek == DayOfWeek.Sunday ? $"Температура {weather.Temp}. Отличная погода, чтобы погулять. " : $"Температура {weather.Temp}. Отличная погода, чтобы идти на пары. ")); if (weather.Humidity > 50) { sb.Append(weather.Temp > 0 ? $"Возможен дождь! Захватите зонтик :)" : $"Возможен снег! По пути можно играть в снежки! :)"); } return(sb.Length == 0 ? "Глупый бот Вас не понимать. Пните разработчика :(" : sb.ToString()); }
async Task <string> Reply(string msg) { string city = "Moscow"; int when = 0; string whens = "today"; Measurement mes = Measurement.None; var a = msg.ToLower().Split(' '); if (IsPresent(a, "help")) { return(@"This is a simple weather bot. Example of commands include: temperature today temperature in Moscow humidity tomorrow"); } if (IsPresent(a, "temperature")) { mes |= Measurement.Temp; } if (IsPresent(a, "humidity")) { mes |= Measurement.Humidity; } if (IsPresent(a, "pressure")) { mes |= Measurement.Pressure; } if (IsPresent(a, "today")) { when = 0; whens = "today"; } if (IsPresent(a, "tomorrow")) { when = 1; whens = "tomorrow"; } if (NextTo(a, "in") != "") { city = NextTo(a, "in"); } var res = await OWM.Forecast(city); var r = res[when]; StringBuilder sb = new StringBuilder(); if ((mes & Measurement.Temp) > 0) { sb.Append($"The temperature on {r.Date} in {city} is {r.Temp}\r\n"); } if ((mes & Measurement.Pressure) > 0) { sb.Append($"The pressure on {r.Date} in {city} is {r.Pressure}\r\n"); } if ((mes & Measurement.Humidity) > 0) { sb.Append($"Humidity on {r.Date} in {city} is {r.Humidity}\r\n"); } if (sb.Length == 0) { return("I do not understand"); } else { return(sb.ToString()); } }
public async Task ProcessWeather(IDialogContext context, LuisResult result) { var location = "Moscow"; var measure = "temperature"; var date = DateTime.Now.Date; EntityRecommendation entityContainer; if (result.TryFindEntity("builtin.geography.city", out entityContainer)) { location = entityContainer.Entity; } if (result.TryFindEntity("builtin.datetime.date", out entityContainer)) { DateTime.TryParse(entityContainer?.Resolution?.SingleOrDefault().Value, out date); } if (result.TryFindEntity("measurement", out entityContainer)) { measure = entityContainer.Entity; } var weatherClient = new WeatherClient("88597cb7a556c191905de0f52f23d7d6"); var forecastArray = await weatherClient.Forecast(location); var forecast = forecastArray.SingleOrDefault(f => f.When.Date == date.Date); string message; if (forecast != null) { if (measure.Contains("humid")) { message = $"The humidity on {forecast.Date} in {location} is {forecast.Humidity}\r\n"; } else if (measure.Contains("pres")) { message = $"The pressure on {forecast.Date} in {location} is {forecast.Pressure}\r\n"; } else if (measure.Contains("temp") || measure.Contains("cold") || measure.Contains("warm")) { message = $"The temperature on {forecast.Date} in {location} is {forecast.Temp}\r\n"; } else { message = "Sorry, unknown parameter \"{parameter}\" requested... Try again"; } } else { message = "Sorry! I was not able to get the forecast."; } #if TRANSLATE message = await Translator.Translate(message, "en-US", Locale); #endif await context.PostAsync(message); context.Wait(MessageReceived); }