コード例 #1
0
 public CommandHandler(IServiceProvider services)
 {
     _config   = services.GetRequiredService <AssistantConfig>();
     _client   = services.GetRequiredService <DiscordSocketClient>();
     _logger   = services.GetRequiredService <LoggingService>();
     _commands = services.GetRequiredService <CommandService>();
     _services = services;
 }
コード例 #2
0
        public Assistant(AssistantConfig config)
        {
            DiscordSocketConfig clientConfig = new DiscordSocketConfig
            {
                LogLevel = config.Log?.Severity ?? LoggingService.DefaultSeverity
            };

            _config   = config;
            _client   = new DiscordSocketClient();
            _services = new ServiceCollection()
                        .AddSingleton(_config)
                        .AddSingleton(_client)
                        .AddSingleton(new CommandService(new CommandServiceConfig {
                DefaultRunMode = RunMode.Async
            }))
                        .AddSingleton <Random>()
                        .AddSingleton <HttpService>()
                        .AddSingleton <CommandHandler>()
                        .AddSingleton <LoggingService>()
                        .AddSingleton <IInitializable>(s => s.GetRequiredService <CommandHandler>())
                        .AddSingleton <IInitializable>(s => s.GetRequiredService <LoggingService>())
                        .BuildServiceProvider();
        }
コード例 #3
0
 private static Task Main(string[] args) =>
 new Assistant(AssistantConfig.FromFile("config.json")).StartAndBlock();
コード例 #4
0
 public LoggingService(DiscordSocketClient client, AssistantConfig config) :
     this(client, config.Log)
 {
 }