Example #1
0
        public async Task Start()
        {
            Console.Title = "Chika";

            // Set up our Discord client
            _client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Verbose,
                MessageCacheSize = 100
            });

            _client.Log += Log;

            // Set up the config directory and core config
            if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Configurations")))
                Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "Configurations"));

            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Configurations", "Chika.json")))
                _config = await ChikaConfig.UseCurrentAsync();
            else
                _config = await ChikaConfig.CreateNewAsync();

            // Set up services
            _mod = new ModerationService();
            await _mod.LoadConfigurationAsync();



            // Instantiate the dependency map and add our services and client to it.
            var serviceProvider = ConfigureServices();

            // Set up command handler
            _commands = new CommandHandler(serviceProvider);
            await _commands.InstallAsync();


            // Connect to Discord
            await _client.LoginAsync(TokenType.Bot, _config.Token);
            await _client.StartAsync();



            // Hang indefinitely
            await Task.Delay(-1);
        }
Example #2
0
        public async Task Start()
        {
            Console.Title = "Kratos";

            // Set up our Discord client
            _client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel         = LogSeverity.Verbose,
                MessageCacheSize = 100
            });

            _client.Log += Log;

            // Set up the config directory and core config
            if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "config")))
            {
                Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "config"));
            }

            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "config", "core.json")))
            {
                _config = await CoreConfig.UseCurrentAsync();
            }
            else
            {
                _config = await CoreConfig.CreateNewAsync();
            }

            // Set up services
            _mod = new ModerationService();
            await _mod.LoadConfigurationAsync();

            _usernotes = new UsernoteService();

            _records = new RecordService();

            _tags = new TagService();

            _log = new LogService(_client);
            await _log.LoadConfigurationAsync();

            _unpunish = new UnpunishService(_client, _blacklist, _log, _records, _config);
            await _unpunish.GetRecordsAsync();

            _slowmode = new SlowmodeService(_client, _log, _unpunish, _records, _config);

            _ratelimit = new RatelimitService(_client, _config, _records, _unpunish, _log);
            await _ratelimit.LoadConfigurationAsync();

            if (_ratelimit.IsEnabled)
            {
                _ratelimit.Enable(_ratelimit.Limit);
            }

            _blacklist = new BlacklistService(_client, _unpunish, _records, _log, _config);

            _aliases = new AliasTrackingService(_client);
            await _aliases.LoadConfigurationAsync();

            _permissions = new PermissionsService();
            _permissions.LoadPermissions(Assembly.GetEntryAssembly());
            await _permissions.LoadConfigurationAsync();

            // Instantiate the dependency map and add our services and client to it.
            var serviceProvider = ConfigureServices();

            // Set up command handler
            _commands = new CommandHandler(serviceProvider);
            await _commands.InstallAsync();

            // Set up an event handler to execute some state-reliant startup tasks
            _client.Ready += async() =>
            {
                await _blacklist.LoadConfigurationAsync();
            };
            // Connect to Discord
            await _client.LoginAsync(TokenType.Bot, _config.Token);

            await _client.StartAsync();

            // Start unpunisher loop
            await _unpunish.StartAsync();

            // Hang indefinitely
            await Task.Delay(-1);
        }