internal async Task ConnectAsync(DiscordBotConfig config)
        {
            Log.Information("Initializing connection.");
            _commandHandler    = new CommandHandlerService(_client, _logger, config, _service, _serviceProvider);
            _messageHandler    = new MessageHandlerService(_client, _logger, config, _levelingService, _userAccountRepository);
            _userEventsHandler = new UserEventsHandlerService(_client, _logger, config, _userAccountRepository);
            _client.Log       += _logger.Log;
            _client.Ready     += ReadyAsync;
            if (config.Token == null || config.Token == "")
            {
                throw new ArgumentNullException("Token", "Discord Bot Token is empty!");
            }
            if (config.CmdPrefix == null || config.CmdPrefix == "")
            {
                throw new ArgumentNullException("cmdPrefix", "Discord Bot cmdPrefix is empty!");
            }

            await _client.LoginAsync(TokenType.Bot, config.Token);

            await _client.StartAsync();

            await _commandHandler.InitializeAsync();

            _messageHandler.Initialize();
            _userEventsHandler.Initialize();
            await Task.Delay(-1);
        }
Ejemplo n.º 2
0
        async Task InitializeServices()
        {
            var services = ConfigureServices();

            _config = await services.GetRequiredService <Configuration>().BuildConfig().ConfigureAwait(false);

            _client     = services.GetRequiredService <DiscordSocketClient>();
            _cmdHandler = services.GetRequiredService <CommandHandlerService>();
            await _cmdHandler.InitializeAsync().ConfigureAwait(false);

            _logger             = services.GetRequiredService <LoggingService>();
            _reliabilityService = services.GetRequiredService <ReliabilityService>();
        }
Ejemplo n.º 3
0
        // Logs in and initializes the bot, then waits for exit
        public async Task Start()
        {
            // Connect to the client
            await _client.LoginAsync(TokenType.Bot, _managementService.GetBotToken());

            await _client.StartAsync();

            // Initialize the command service
            await _commandHandlerService.InitializeAsync();

            // Block the program until it is closed.
            await Task.Delay(-1);
        }
Ejemplo n.º 4
0
        public async Task RunAsync()
        {
            client.Log   += async(LogMessage x) => Console.WriteLine($"[{x.Severity}] {x.Message}");
            client.Ready += async() => await client.SetGameAsync("e:help | https://discordemoji.com", "https://twitch.tv/courierfive", ActivityType.Streaming);

            await discordEmoji.Start();

            await commandHandler.InitializeAsync();

            await client.LoginAsync(TokenType.Bot, configuration.Token);

            await client.StartAsync();

            await Task.Delay(-1);
        }