예제 #1
0
 public static void Main()
 {
     #region Конфигурация
     StandardKernel kernel = new StandardKernel();
     kernel.Bind <IStoreData>().To <StoreDataMethods>();
     kernel.Bind <ICreatorJson>().To <CreatorJsonMethods>();
     Bot = SimpleTBot.ConfigureBot(ConfigurationManager.AppSettings[ConstantStrings.TelegaToken]);
     WeatherCore.SetWeatherApi(ConfigurationManager.AppSettings[ConstantStrings.WeatherToken]);
     OpenWeatherCore.SetWeatherApi(ConfigurationManager.AppSettings[ConstantStrings.OpenWeatherMapToken]);
     jCreator = kernel.Get <ICreatorJson>();
     jCreator.SetJsonPath(Environment.CurrentDirectory + "//LocalizationStrings.json");
     localization         = jCreator.ReadConfig <LocalizationModel>();
     localization.Current = ConfigurationManager.AppSettings[ConstantStrings.Localization] == "ru" ? localization.Ru : localization.En;
     kernel.Get <IStoreData>().StoreData(localization, ConstantStrings.Localization);
     MessageCore.GetStoreDataFromKernel(kernel);
     WebApiCore.GetStoreDataFromKernel(kernel);
     KeyboardCore.GetStoreDataFromKernel(kernel);
     #endregion
     #region Запуск бота
     Bot.OnMessage       += BotOnMessage;
     Bot.OnCallbackQuery += BotOnCallbackQuery;
     Bot.StartReceiving();
     Console.WriteLine(localization.Current.BotStartingConsole);
     #endregion
     #region Остановка бота
     Console.ReadLine();
     Bot.StopReceiving();
     Console.WriteLine(localization.Current.BotStoppedConsole);
     Console.ReadLine();
     #endregion
 }
예제 #2
0
        private async Task <WeatherInfo> Helper()
        {
            var currentWeather = new WeatherCore(TownName);
            var weatherInfo    = await currentWeather.GetWetherInfo();

            Mediator.Notify("GetCityWeatherScreen", TownName);
            return(weatherInfo);
        }
예제 #3
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);
        }
예제 #4
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);
                }
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            WeatherCore weactherCore = new WeatherCore();

            Console.WriteLine(weactherCore.SendRequest().ToJson());
        }