Ejemplo n.º 1
0
        public async Task MainAsync()
        {
            Console.OutputEncoding = System.Text.Encoding.Unicode;

            //Init for Log
            LogInit();
            // Init DB
            DatabaseInit db = new DatabaseInit();

            db.InitDB();

            // New Client
            // Load config.xml if doesn't exist create one. Both with exception handling.
            this._configXML = this.configClass.LoadConfigXML();

            this._client = new DiscordSocketClient(new DiscordSocketConfig
            {
                MessageCacheSize    = 200,
                LogLevel            = LogSeverity.Info,
                AlwaysDownloadUsers = true,
                LargeThreshold      = 250
            });

            // New CommandService
            this._commands = new CommandService(new CommandServiceConfig
            {
                // Config Here if needed
                LogLevel = LogSeverity.Info
            });

            // New CommandHandlingService
            this._cmdHandService = new CommandHandlingService(this._client, this._commands, this._configXML, this._devMode);

            // Add Own Features
            ListenFor1337 _listenFor1337 = new ListenFor1337(_client, _cmdHandService, _devMode);

            // New ServiceCollection
            this._services = new ServiceCollection()
                             .AddSingleton(this._client)
                             .AddSingleton(this._commands)
                             .AddSingleton(this._cmdHandService)
                             // Add More Services below if needed
                             .AddSingleton(_listenFor1337)
                             .BuildServiceProvider();

            // Init CommandHandlingService
            await _cmdHandService.InitializeAsync(_services);

            this._client.Log        += Log;
            this._client.UserJoined += UserJoined;


            if (this._configXML != null)
            {
                await _client.LoginAsync(TokenType.Bot, this.configClass.GetToken(_configXML));
            }
            else
            {
                CloseByInvalidToken();
            }
            await _client.StartAsync();

            // Block this task until the program is closed.
            await Task.Delay(-1);
        }