public static ForecastResponse GetForecast(long id)
        {
            var user = UserExistCommand.GetUser(id);

            if (user.Latitude is null || user.Longitude is null)
            {
                return(null);
            }

            string response;
            var    url = "https://api.openweathermap.org/data/2.5/forecast?lat=" +
                         Convert.ToString(user.Latitude) + "&lon=" + Convert.ToString(user.Longitude) +
                         "&units=metric&appid=" + Bot.ReadTokenOWM(@"[path].json");

            if (!Bot.CheckUrl(url))
            {
                return(null);
            }

            HttpWebRequest  httpWebRequest  = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
            {
                response = streamReader.ReadToEnd();
            }

            ForecastResponse forecastResponse = JsonConvert.DeserializeObject <ForecastResponse>(response);

            return(forecastResponse);
        }
Ejemplo n.º 2
0
        public static async void Execute(object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            if (e?.Message?.Type != MessageType.Location)
            {
                return;
            }

            var user = UserExistCommand.GetUser(e.Message.Chat.Id);

            user.Latitude  = e?.Message?.Location?.Latitude;
            user.Longitude = e?.Message?.Location?.Longitude;

            var replyKeyboard = new ReplyKeyboardMarkup(new[]
            {
                new[]
                {
                    new KeyboardButton("Сейчас"),
                    new KeyboardButton("На 12 часов")
                },
                new[]
                {
                    new KeyboardButton("На день"),
                    new KeyboardButton("На три дня")
                }
            });

            await Bot.client.SendTextMessageAsync(e?.Message?.From?.Id, "Узнать погоду или " +
                                                  "получить график на 5 дней ( /chart ):", replyMarkup : replyKeyboard);
        }
Ejemplo n.º 3
0
        public static async void Execute(object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            if (!Name.Equals(e?.Message?.Text))
            {
                return;
            }

            var user     = UserExistCommand.GetUser(e.Message.From.Id);
            var forecast = GetLocationCommand.GetForecast(user.Id);

            if (forecast is null)
            {
                GetLocationCommand.SetLocation(user.Id);
                return;
            }

            var temp  = new int[5];
            var marks = new string[5];
            var j     = 1;

            for (var i = 0; i < 5; i++, j += 8)
            {
                temp[i]  = (int)forecast.List[j].Main.Temp + 5;
                marks[i] = forecast.List[j].Dt_txt;
            }

            var dataset = new List <int[]>();

            dataset.Add(temp);

            var lineChart = new LineChart(600, 300);

            lineChart.SetTitle("График температуры на 5 дней", "0088A0", 14);
            lineChart.SetData(dataset);
            lineChart.SetGrid(10, 10);

            lineChart.AddAxis(new ChartAxis(ChartAxisType.Bottom, marks));
            var chartAxisLeft = new ChartAxis(ChartAxisType.Left);

            chartAxisLeft.SetRange(-20, 80);
            lineChart.AddAxis(chartAxisLeft);

            lineChart.SetDatasetColors(new string[] { "85E0F0" });
            lineChart.SetLegend(new string[] { "Температура" });

            await Bot.client.SendPhotoAsync(user.Id, lineChart.GetUrl());
        }
Ejemplo n.º 4
0
        public static async void Execute(object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            var user      = UserExistCommand.GetUser(e.Message.From.Id);
            var message   = $"{DateTime.Now}. {e?.Message?.Text} от {user.FirstName} {user.LastName}.";
            var writePath = @"C:[path].TXT";

            try
            {
                using (StreamWriter streamWriter = new StreamWriter(writePath, true, System.Text.Encoding.Default))
                {
                    await streamWriter.WriteLineAsync(message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }