Example #1
0
 public CommandHandler(IServiceProvider services)
 {
     _client   = services.GetService <DiscordSocketClient>();
     _config   = services.GetService <ChikaConfig>();
     _commands = services.GetService <CommandService>();
     _services = services;
 }
Example #2
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);
        }