Exemple #1
0
        public static async Task Main()
        {
            Console.Title = nameof(HitagiBot);

            var    botHandle   = new TelegramBotClient(Config["Tokens:Telegram"]);
            string botUsername = null;

            try
            {
                var botUser = await botHandle.GetMeAsync();

                botUsername = botUser.Username;
            }
            catch (AggregateException e)
            {
                Console.WriteLine($"An error occurred while retrieving the bot's info: {e.Message}");
                Console.WriteLine("Press any key to terminate...");
                Console.ReadKey();
                Environment.Exit(1);
            }

            _messageHandler = new ArgumentHandler <Message>(botUsername);
            _messageHandler.Add("/start", BaseCommands.Start);
            _messageHandler.Add("/help", BaseCommands.Help);
            _messageHandler.Add("/settings", BaseCommands.Settings);
            _messageHandler.Add("/lastplayed", LastFmCommands.LastPlayed);
            _messageHandler.Add("/setlastfm", LastFmCommands.SetLastFm);
            _messageHandler.Add("/weather", WeatherCommands.WeatherCommand);
            _messageHandler.Add("/forecast", WeatherCommands.Forecast);
            _messageHandler.Add("/geocode", GeocodeCommands.Geocode);
            _messageHandler.Add("/setlocation", GeocodeCommands.SetLocation);
            _messageHandler.Add("/movie", MovieCommands.Movie);
            _messageHandler.Add("/tvshow", TvCommands.TvShow);
            _messageHandler.Add("/ping", MiscCommands.Ping);
            _messageHandler.Add("/userid", MiscCommands.UserId);

            botHandle.OnMessage += Bot_OnMessage;

            botHandle.StartReceiving();

            while (botHandle.IsReceiving)
            {
                await Task.Delay(TimeSpan.FromSeconds(10));
            }

            Environment.Exit(0);
        }