private static async void CheckWeather_Elapsed(object sender, ElapsedEventArgs e)
        {
            foreach (User user in DatabaseAccess.Instance.Users)
            {
                if (user.NotifierTime == null || user.WeatherLocation == null)
                {
                    continue;
                }
                if (!(DateTime.Now.Hour == user.NotifierTime.Value.Hours && DateTime.Now.Minute == user.NotifierTime.Value.Minutes))
                {
                    continue;
                }
                SocketUser disUser = client.GetUser(user.Id);
                if (disUser == null)
                {
                    continue;
                }

                WeatherApi apiResult = await weatherApiHandler.Request2WeatherApiAsync(credentials.WeatherApiKey, user.WeatherLocation);

                EmbedBuilder weatherEmbed = new EmbedBuilder()
                                            .WithTitle("Weather Info")
                                            .WithDescription("Weather Notification for today")
                                            .AddField(user.WeatherLocation, $"{apiResult.Weather.Temperature} °C")
                                            .AddField("Max. Temp today", $"{apiResult.Weather.MaxTemperature} °C")
                                            .AddField("Min. Temp for today", $"{apiResult.Weather.MinTemperature} °C")
                                            .AddField("Weather Condition", apiResult.WeatherCondition.First().ShortDescription)
                                            .WithColor(Color.Blue)
                                            .WithTimestamp(DateTime.Now)
                                            .WithFooter(FileAccess.GENERIC_FOOTER, FileAccess.GENERIC_THUMBNAIL_URL);
                await disUser.SendMessageAsync(embed : weatherEmbed.Build()).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        private static async Task checkWeather()
        {
            WeatherApi apiResult = await weatherApiHandler.Request2WeatherApiAsync(credentials.WeatherApiKey, credentials.WeatherPlace);

            //main.temp 70%,
            pointsSum = calculateWeatherPoints(15f, 20f, 0.7f, apiResult.Weather.Temperature);
            //main.humidity 5%,
            pointsSum += calculateWeatherPoints(10f, 50f, 0.05f, apiResult.Weather.Humidity);
            //wind.speed 5%,
            pointsSum += calculateWeatherPoints(10f, 4f, 0.05f, apiResult.Wind.Speed);
            //clouds.all 10%,
            pointsSum += calculateWeatherPoints(50f, 10f, 0.1f, apiResult.Clouds.Density);
            //rain.1h 0.2 10%,
            pointsSum += calculateWeatherPoints(2.5f, 0f, 0.1f, 0f);
        }