示例#1
0
        /// <summary>
        /// Starts the execution of the bot.
        /// </summary>
        public async Task Start()
        {
            _client = new DiscordSocketClient();

            Data = new DataModule();
            Data.InitializeDataFiles();

            Commands = new CommandHandler(Data, Configuration["prefix"]);

            _leaderboardNavigator = new EventPointCommand.LeaderboardNavigator(Data.EventPoints, Data.Settings);

            _services = new ServiceCollection()

                        // Add the command service
                        .AddSingleton(Commands.Service)

                        // Add the singletons for the databases
                        .AddSingleton(Data.EventPoints)
                        .AddSingleton(Data.Settings)
                        .AddSingleton(Data.Statistics)
                        .AddSingleton(Data.CustomCommands)
                        .AddSingleton(Data.Cooldowns)
                        .AddSingleton(Data.Rules)
                        .AddSingleton(Data.UnityDocs)
                        .AddSingleton(Data.Mutes)
                        .AddSingleton(Data.Bans)

                        .AddSingleton(_leaderboardNavigator)

                        // Finally, build the provider
                        .BuildServiceProvider();

            UserHelper.Data = Data;

            Commands.ServiceProvider = _services;
            await Commands.InstallCommands(_client);

            RegisterMuteOnJoin();
            RegisterMassiveCodeblockHandle();
            RegisterMentionMessage();
            RegisterStaffPingLogging();
            RegisterLeaderboardNavigationHandle();

            _ = PeriodicCheckMute(new TimeSpan(TimeSpan.TicksPerMinute * 2), System.Threading.CancellationToken.None);
            _ = PeriodicCheckBan(new TimeSpan(TimeSpan.TicksPerMinute * 3), System.Threading.CancellationToken.None);

            await _client.LoginAsync(TokenType.Bot, Configuration["token"]);

            await _client.SetGameAsync($"{ Configuration["prefix"] }help");

            await _client.StartAsync();
        }
示例#2
0
        /// <summary>
        /// Starts the execution of the bot.
        /// </summary>
        public async Task Start()
        {
            Log.Initialize();
            Log.Settings = new Log.LogSettings
            {
                IncludeTimestamp = true
            };

            Console.WriteLine($"\n  [ ] BrackeysBot v{Version}\n");
            Log.WriteLine("=== Intializing Startup ===");

            _client      = new DiscordSocketClient();
            _client.Log += async logMessage => Log.WriteLine($"[DiscordClient] ({logMessage.Severity.ToString()}) {logMessage.Message}");

            _client.Ready += OnReady;

            Data = new DataModule();
            Data.InitializeDataFiles();

            Commands = new CommandHandler(Data, Configuration["prefix"]);

            _leaderboardNavigator = new EventPointCommand.LeaderboardNavigator(Data.EventPoints, Data.Settings);

            _services = new ServiceCollection()

                        // Add BrackeysBot
                        .AddSingleton(this)

                        // Add the command service
                        .AddSingleton(Commands.Service)

                        // Add the singletons for the databases
                        .AddSingleton(Data.EventPoints)
                        .AddSingleton(Data.Settings)
                        .AddSingleton(Data.Statistics)
                        .AddSingleton(Data.CustomCommands)
                        .AddSingleton(Data.Cooldowns)
                        .AddSingleton(Data.Rules)
                        .AddSingleton(Data.UnityDocs)
                        .AddSingleton(Data.Mutes)
                        .AddSingleton(Data.Bans)

                        .AddSingleton(_leaderboardNavigator)

                        // Finally, build the provider
                        .BuildServiceProvider();

            UserHelper.Data = Data;

            Commands.ServiceProvider = _services;
            await Commands.InstallCommands(_client);

            RegisterMuteOnJoin();
            RegisterMassiveCodeblockHandle();
            RegisterMentionMessage();
            RegisterStaffPingLogging();
            RegisterLeaderboardNavigationHandle();

            _ = PeriodicCheckMute(new TimeSpan(TimeSpan.TicksPerMinute * 2), CancellationToken.None);
            _ = PeriodicCheckBan(new TimeSpan(TimeSpan.TicksPerMinute * 3), CancellationToken.None);

            await _client.LoginAsync(TokenType.Bot, Configuration["token"]);

            await _client.SetGameAsync($"{ Configuration["prefix"] }help");

            await _client.StartAsync();
        }