コード例 #1
0
        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;
                }

                dynamic temperature = JsonConvert.DeserializeObject <dynamic>(await ApiRequestService.Request2WeatherApiAsync(user.WeatherLocation));

                EmbedBuilder weatherEmbed = new EmbedBuilder()
                                            .WithTitle("Weather Info")
                                            .WithDescription("Weather Notification for today")
                                            .AddField(user.WeatherLocation, $"{temperature.main.temp} °C")
                                            .AddField("Max. Temp today", $"{temperature.main.temp_max} °C")
                                            .AddField("Min. Temp for today", $"{temperature.main.temp_min} °C")
                                            .AddField("Weather Condition", (string)temperature.weather[0].main)
                                            .WithColor(Color.Blue)
                                            .WithTimestamp(DateTime.Now)
                                            .WithFooter(FileAccess.GENERIC_FOOTER, FileAccess.GENERIC_THUMBNAIL_URL);
                await disUser.SendMessageAsync(embed : weatherEmbed.Build()).ConfigureAwait(false);
            }
        }
コード例 #2
0
        private static async Task checkWeather()
        {
            dynamic temperature = JsonConvert.DeserializeObject <dynamic>(await ApiRequestService.Request2WeatherApiAsync());

            //main.temp 60%,
            pointsSum = calculateWeatherPoints(15f, 20f, 0.6f, (float)temperature.main.temp);
            //main.humidity 5%,
            pointsSum += calculateWeatherPoints(10f, 50f, 0.05f, (float)temperature.main.humidity);
            //wind.speed 5%,
            pointsSum += calculateWeatherPoints(10f, 4f, 0.05f, (float)temperature.wind.speed);
            //clouds.all 10%,
            pointsSum += calculateWeatherPoints(50f, 10f, 0.1f, (float)temperature.clouds.all);
            //rain.1h 0.2 10%,
            pointsSum += calculateWeatherPoints(2.5f, 0f, 0.1f, 0f);//temperature.rain != null ? (float)temperature.rain["1h"] : 0f);
            //pointsSum += calculateWeatherPoints(2.5f, 0f, 0.1f, 0.5f);
            //snow.1h 0.1 10%
            pointsSum += calculateWeatherPoints(2.5f, 0f, 0.1f, temperature.snow != null ? (float)temperature.snow["1h"] : 0f);
        }
コード例 #3
0
        private static async Task HandleNaturalInput(Input input)
        {
            SocketUserMessage message = input.Message;

            if ((message.Channel as SocketDMChannel) != null && HasCleverbotApiKey)
            {
                //dm channel
                if (message.Author.Id == client.CurrentUser.Id)
                {
                    return;
                }
                //privat message
                RequestCounter++;


                CleverApi messageOutput = JsonConvert.DeserializeObject <CleverApi>(await ApiRequestService.Request2CleverBotApiAsync(message));
                await message.Channel.SendMessageAsync(messageOutput.Answer);
            }
        }