Weather fixed
This commit is contained in:
parent
e6e4f17eee
commit
58f2540083
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Searches.Commands.Models
|
||||
{
|
||||
public class Coord
|
||||
{
|
||||
public double lon { get; set; }
|
||||
public double lat { get; set; }
|
||||
}
|
||||
|
||||
public class Weather
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string main { get; set; }
|
||||
public string description { get; set; }
|
||||
public string icon { get; set; }
|
||||
}
|
||||
|
||||
public class Main
|
||||
{
|
||||
public double temp { get; set; }
|
||||
public int pressure { get; set; }
|
||||
public int humidity { get; set; }
|
||||
public double temp_min { get; set; }
|
||||
public double temp_max { get; set; }
|
||||
}
|
||||
|
||||
public class Wind
|
||||
{
|
||||
public double speed { get; set; }
|
||||
public int deg { get; set; }
|
||||
}
|
||||
|
||||
public class Clouds
|
||||
{
|
||||
public int all { get; set; }
|
||||
}
|
||||
|
||||
public class Sys
|
||||
{
|
||||
public int type { get; set; }
|
||||
public int id { get; set; }
|
||||
public double message { get; set; }
|
||||
public string country { get; set; }
|
||||
public double sunrise { get; set; }
|
||||
public double sunset { get; set; }
|
||||
}
|
||||
|
||||
public class WeatherData
|
||||
{
|
||||
public Coord coord { get; set; }
|
||||
public List<Weather> weather { get; set; }
|
||||
public Main main { get; set; }
|
||||
public int visibility { get; set; }
|
||||
public Wind wind { get; set; }
|
||||
public Clouds clouds { get; set; }
|
||||
public int dt { get; set; }
|
||||
public Sys sys { get; set; }
|
||||
public int id { get; set; }
|
||||
public string name { get; set; }
|
||||
public int cod { get; set; }
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ using ImageSharp;
|
||||
using NadekoBot.Extensions;
|
||||
using System.IO;
|
||||
using NadekoBot.Modules.Searches.Commands.OMDB;
|
||||
using NadekoBot.Modules.Searches.Commands.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Searches
|
||||
{
|
||||
@ -25,28 +26,30 @@ namespace NadekoBot.Modules.Searches
|
||||
{
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Weather(IUserMessage umsg, string city, string country)
|
||||
public async Task Weather(IUserMessage umsg, [Remainder] string query)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
city = city.Replace(" ", "");
|
||||
country = city.Replace(" ", "");
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
return;
|
||||
|
||||
string response;
|
||||
using (var http = new HttpClient())
|
||||
response = await http.GetStringAsync($"http://api.ninetales.us/nadekobot/weather/?city={city}&country={country}").ConfigureAwait(false);
|
||||
response = await http.GetStringAsync($"http://api.openweathermap.org/data/2.5/weather?q={query}&appid=42cd627dd60debf25a5739e50a217d74&units=metric").ConfigureAwait(false);
|
||||
|
||||
var obj = JObject.Parse(response)["weather"];
|
||||
var data = JsonConvert.DeserializeObject<WeatherData>(response);
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
.AddField(fb => fb.WithName("🌍 **Location**").WithValue($"{obj["target"]}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("📏 **Lat,Long**").WithValue($"{obj["latitude"]}, {obj["longitude"]}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("☁ **Condition**").WithValue($"{obj["condition"]}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("😓 **Humidity**").WithValue($"{obj["humidity"]}%").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("💨 **Wind Speed**").WithValue($"{obj["windspeedk"]}km/h ({obj["windspeedm"]}mph)").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("🌡 **Temperature**").WithValue($"{obj["centigrade"]}°C ({obj["fahrenheit"]}°F)").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("🔆 **Feels like**").WithValue($"{obj["feelscentigrade"]}°C ({obj["feelsfahrenheit"]}°F)").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("🌄 **Sunrise**").WithValue($"{obj["sunrise"]}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("🌇 **Sunset**").WithValue($"{obj["sunset"]}").WithIsInline(true))
|
||||
.WithOkColor();
|
||||
.AddField(fb => fb.WithName("🌍 **Location**").WithValue(data.name + ", " + data.sys.country).WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("📏 **Lat,Long**").WithValue($"{data.coord.lat}, {data.coord.lon}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("☁ **Condition**").WithValue(String.Join(", ", data.weather.Select(w=>w.main))).WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("😓 **Humidity**").WithValue($"{data.main.humidity}%").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("💨 **Wind Speed**").WithValue(data.wind.speed + " km/h").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("🌡 **Temperature**").WithValue(data.main.temp + "°C").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("🔆 **Min - Max**").WithValue($"{data.main.temp_min}°C - {data.main.temp_max}°C").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("🌄 **Sunrise (utc)**").WithValue($"{data.sys.sunrise.ToUnixTimestamp():HH:mm}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName("🌇 **Sunset (utc)**").WithValue($"{data.sys.sunset.ToUnixTimestamp():HH:mm}").WithIsInline(true))
|
||||
.WithOkColor()
|
||||
.WithFooter(efb => efb.WithText("Powered by http://openweathermap.org"));
|
||||
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
@ -4648,8 +4648,8 @@ namespace NadekoBot.Resources {
|
||||
return ResourceManager.GetString("osub_usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to overwatch ow.
|
||||
/// </summary>
|
||||
public static string overwatch_cmd {
|
||||
@ -7818,7 +7818,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Shows weather data for a specified city and a country. BOTH ARE REQUIRED. Use country abbrevations..
|
||||
/// Looks up a localized string similar to Shows weather data for a specified city. You can also specify a country after a comma..
|
||||
/// </summary>
|
||||
public static string weather_desc {
|
||||
get {
|
||||
@ -7827,7 +7827,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to `{0}we Moscow RF`.
|
||||
/// Looks up a localized string similar to `{0}we Moscow, RU`.
|
||||
/// </summary>
|
||||
public static string weather_usage {
|
||||
get {
|
||||
|
@ -1876,10 +1876,10 @@
|
||||
<value>weather we</value>
|
||||
</data>
|
||||
<data name="weather_desc" xml:space="preserve">
|
||||
<value>Shows weather data for a specified city and a country. BOTH ARE REQUIRED. Use country abbrevations.</value>
|
||||
<value>Shows weather data for a specified city. You can also specify a country after a comma.</value>
|
||||
</data>
|
||||
<data name="weather_usage" xml:space="preserve">
|
||||
<value>`{0}we Moscow RF`</value>
|
||||
<value>`{0}we Moscow, RU`</value>
|
||||
</data>
|
||||
<data name="youtube_cmd" xml:space="preserve">
|
||||
<value>youtube yt</value>
|
||||
@ -2781,7 +2781,7 @@
|
||||
<data name="crstats_usage" xml:space="preserve">
|
||||
<value>`{0}crstats` or `{0}crstats 3`</value>
|
||||
</data>
|
||||
<data name="overwatch_cmd" xml:space="preserve">
|
||||
<data name="overwatch_cmd" xml:space="preserve">
|
||||
<value>overwatch ow</value>
|
||||
</data>
|
||||
<data name="overwatch_desc" xml:space="preserve">
|
||||
|
@ -82,6 +82,8 @@ namespace NadekoBot.Extensions
|
||||
|
||||
public static double UnixTimestamp(this DateTime dt) => dt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
|
||||
public static DateTime ToUnixTimestamp(this double number) => new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(number);
|
||||
|
||||
public static async Task<IUserMessage> SendMessageAsync(this IGuildUser user, string message, bool isTTS = false) =>
|
||||
await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user