public async Task Weather(CommandContext ctx,
                                  [Description("Location to retrieve weather data from")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = await GoogleService.GetWeatherDataAsync(query).ConfigureAwait(false);

            if (results.COD == 404)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_LOCATION, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                Func <double, double> format = GoogleService.CelsiusToFahrenheit;
                var output = new DiscordEmbedBuilder()
                             .WithTitle(":partly_sunny: Current weather in " + results.Name + ", " + results.Sys.Country)
                             .AddField("Temperature", $"{results.Main.Temperature:F1}°C / {format(results.Main.Temperature):F1}°F", true)
                             .AddField("Humidity", $"{results.Main.Humidity}%", true)
                             .AddField("Wind Speed", $"{results.Wind.Speed}m/s", true)
                             .WithUrl("https://openweathermap.org/city/" + results.ID)
                             .WithColor(SharedData.DefaultColor);
                await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);
            }
        }
示例#2
0
 public void GetWeatherData()
 {
     Assert.IsTrue(GoogleService.GetWeatherDataAsync("Ottawa").Result.COD == 404);
     Assert.IsFalse(GoogleService.GetWeatherDataAsync("Ottura").Result.COD == 404);
 }