Exemplo n.º 1
0
        /// <summary>
        /// Отправить ответ погоды
        /// </summary>
        /// <param name="coords">Координаты</param>
        /// <param name="chat">Чат ИД</param>
        /// <returns>True False</returns>
        public static bool SendWeatherAnswer(WeatherLocationModel coords, ChatId chat = null)
        {
            var    keyboard = KeyboardCore.ConfigureStandartKeyboard();
            string result   = WebApiCore.ExecuteHttpRequest(WeatherCore.CreateApiStringWithLocation(new Location()
            {
                Latitude  = coords.lat,
                Longitude = coords.lon
            }));
            GeoWeatherModel model = JsonConvert.DeserializeObject <GeoWeatherModel>(result);

            if (model is null)
            {
                SendBadWeatherResponse(chat);
            }
            WithKeyboardSending(CreateWeatherAnswer(model), keyboard, chat: chat);
            return(false);
        }
Exemplo n.º 2
0
        private static void SendBadWeatherResponse(ChatId id)
        {
            var keyboard = KeyboardCore.ConfigureStandartKeyboard();

            WithKeyboardSending(localization.Current.WeatherErrorResponseMsg, keyboard, chat: id);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Обработка сообщения "Погода"
        /// </summary>
        /// <param name="args">Аргументы</param>
        /// <param name="IsWeatherBegin">Ведется ли проверка погоды сейчас</param>
        /// <param name="chat">Чат ИД</param>
        public static bool WeatherMessage(MessageEventArgs args, bool IsWeatherBegin, ChatId chat = null, string UsingApiMethod = null)
        {
            TelegramBotClient Bot = SimpleTBot.GetBot();

            if (!IsWeatherBegin)
            {
                var keyboard = KeyboardCore.ConfigureWeatherKeyboard();

                WithKeyboardSending(localization.Current.WeatherBeginedMsg, keyboard, args);
                return(true);
            }
            else
            {
                if (args.Message.Text == localization.Current.WeatherStopCommandMsg)
                {
                    var keyboard = KeyboardCore.ConfigureStandartKeyboard();

                    WithKeyboardSending(localization.Current.WeatherStopCommandAnswer, keyboard, args);
                    return(false);
                }
                else
                {
                    var keyboard = KeyboardCore.ConfigureStandartKeyboard();
                    if (args.Message.Type == MessageType.Text)
                    {
                        if (UsingApiMethod == ConstantStrings.WeatherToken)
                        {
                            string result = WebApiCore.ExecuteHttpRequest(WeatherCore.CreateApiStringWithCity(args.Message.Text));
                            List <FindedAddressModel> models = JsonConvert.DeserializeObject <List <FindedAddressModel> >(result);

                            WithVariantsSending(localization.Current.WeatherResultFindedMsg,
                                                KeyboardCore.ConfigureWeatherKeyboardWithVariants(models), args);
                            return(false);
                        }
                        if (UsingApiMethod == ConstantStrings.OpenWeatherMapToken)
                        {
                            try
                            {
                                string result             = WebApiCore.ExecuteHttpRequest(OpenWeatherCore.CreateApiStringWithCity(args.Message.Text));
                                GeoOpenWeatherModel model = JsonConvert.DeserializeObject <GeoOpenWeatherModel>(result);

                                WithKeyboardSending(CreateOpenWeatherAnswer(model), keyboard, args);
                            }
                            catch (Exception)
                            {
                                SendBadWeatherResponse(chat ?? args.Message.Chat.Id);
                            }
                        }
                    }
                    else if (args.Message.Type == MessageType.Location || args.Message.Type == MessageType.Venue)
                    {
                        if (UsingApiMethod == ConstantStrings.WeatherToken)
                        {
                            SendWeatherAnswer(new WeatherLocationModel()
                            {
                                lat = args.Message.Location.Latitude,
                                lon = args.Message.Location.Longitude
                            }, args.Message.Chat.Id);
                        }
                        if (UsingApiMethod == ConstantStrings.OpenWeatherMapToken)
                        {
                            try
                            {
                                string result             = WebApiCore.ExecuteHttpRequest(OpenWeatherCore.CreateApiStringWithLocation(args.Message.Location));
                                GeoOpenWeatherModel model = JsonConvert.DeserializeObject <GeoOpenWeatherModel>(result);

                                WithKeyboardSending(CreateOpenWeatherAnswer(model), keyboard, args);
                            }
                            catch (Exception)
                            {
                                SendBadWeatherResponse(chat ?? args.Message.Chat.Id);
                            }
                        }
                    }
                    return(false);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Обработка сообщения /start
        /// </summary>
        /// <param name="args">Аргументы</param>
        /// <param name="welcomingMessage">Приветственное сообщение</param>
        /// <param name="chat">Чат ИД</param>
        public static void StartMessage(MessageEventArgs args, string welcomingMessage, ChatId chat = null)
        {
            var keyboard = KeyboardCore.ConfigureStandartKeyboard();

            WithKeyboardSending(welcomingMessage, keyboard, args);
        }