Exemple #1
0
        public async Task StartAsync()
        {
            string token  = _token;
            string prefix = _prefix;

            if (string.IsNullOrEmpty(token))
            {
                Console.WriteLine("Please enter a bot token.");

                token  = Console.ReadLine();
                _token = token;

                BotStorage.Config.Token = token;
                BotStorage.SaveConfig(BotStorage.Config);
            }

            if (string.IsNullOrEmpty(prefix))
            {
                Console.WriteLine("Please enter a bot prefix.");

                prefix  = Console.ReadLine();
                _prefix = prefix;

                BotStorage.Config.Prefix = prefix;
                BotStorage.SaveConfig(BotStorage.Config);
            }

            _client.Log += _client_Log;

            while (true)
            {
                try
                {
                    await _client.LoginAsync(TokenType.Bot, token);

                    break;
                }
                catch (Exception ex) when(ex is ArgumentException || ex is Discord.Net.HttpException)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("Supplied token invalid. Please re-enter your token.");

                    token  = Console.ReadLine();
                    _token = token;

                    BotStorage.Config.Token = token;
                    BotStorage.SaveConfig(BotStorage.Config);

                    continue;
                }
            }

            await _client.StartAsync();

            await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _provider);
        }
Exemple #2
0
 public TelegramBot(string name, string key) : base(name, key)
 {
     // регистрация бота
     BotStorage.AddActivityBot(this);
 }