private async Task <DiscordMessage> WeatherForecast(string location) { Coordinates coordinates; try { coordinates = await _lookup.Lookup(location); } catch { return(new DiscordMessage("Could not find " + location)); } var weatherRequest = new WeatherLookup(_apiKeys.ForecastIoKey, coordinates.Latitude, coordinates.Longitude); WeatherData weather; try { weather = await weatherRequest.Get(); } catch { return(new DiscordMessage("Found " + coordinates.Name + " but could not find any weather there.")); } var forecastEmbed = new EmbedBuilder(); forecastEmbed.Title = "3 day forecast for: " + coordinates.Name; var dailyWeather = weather.daily.data.Skip(2).Take(3); foreach (var dayWeather in dailyWeather) { var weatherIcon = _weatherEmoji[dayWeather.icon]; var forecastField = new EmbedFieldBuilder { Name = TimeFromEpoch(dayWeather.time).DayOfWeek.ToString(), Value = $"{weatherIcon} {dayWeather.summary} {Temp(dayWeather.temperatureMin)} to {Temp(dayWeather.temperatureMax)}", }; forecastEmbed.Fields.Add(forecastField); } return(new DiscordMessage(forecastEmbed)); }
private async Task <DiscordMessage> WeatherToday(string location) { Coordinates coordinates; try { coordinates = await _lookup.Lookup(location); } catch (Exception e) { Log.Debug(e, "Plugin-Weather: Location Lookup failure"); if (!string.IsNullOrWhiteSpace(e.InnerException?.Message)) { Log.Debug(e.InnerException, "Plugin-Weather: Location Lookup failure details"); } return(new DiscordMessage("Could not find " + location)); } var weatherRequest = new WeatherLookup(_apiKeys.ForecastIoKey, coordinates.Latitude, coordinates.Longitude); WeatherData weather; try { weather = await weatherRequest.Get(); } catch (Exception e) { Log.Debug(e, "Plugin-Weather: Weather Lookup failure"); if (!string.IsNullOrWhiteSpace(e.InnerException?.Message)) { Log.Debug(e.InnerException, "Plugin-Weather: Weather Lookup failure details"); } return(new DiscordMessage("Found " + coordinates.Name + " but could not find any weather there.")); } var weatherEmbed = new EmbedBuilder(); var wToday = weather.currently; var moonPhase = weather.daily.data[0].MoonPhase(); var weatherIcon = _weatherIcons[wToday.icon]; weatherEmbed.Title = $"Weather for {coordinates.Name}"; weatherEmbed.Description = wToday.summary; weatherEmbed.ThumbnailUrl = weatherIcon; var tempField = new EmbedFieldBuilder { Name = "Temperature", Value = Temp(wToday.temperature), IsInline = true }; var windField = new EmbedFieldBuilder { Name = "Wind", Value = $"{Windspeed(wToday.windSpeed)} - {Windbearing(wToday.windBearing)}", IsInline = true }; var humField = new EmbedFieldBuilder { Name = "Humidty", Value = $"{wToday.humidity * 100}%", IsInline = true }; var moonField = new EmbedFieldBuilder { Name = "Moon", Value = moonPhase, IsInline = true }; var precipitation = "None"; if (wToday.precipIntensity > 0.4 && wToday.precipProbability > 0.2) { precipitation = $"{wToday.precipProbability * 100}% of {wToday.precipType}"; } var precipField = new EmbedFieldBuilder { Name = "Precipitation", Value = precipitation }; weatherEmbed.Fields.Add(tempField); weatherEmbed.Fields.Add(moonField); weatherEmbed.Fields.Add(windField); weatherEmbed.Fields.Add(humField); weatherEmbed.Fields.Add(precipField); return(new DiscordMessage(weatherEmbed)); }