Beispiel #1
0
        public DiscordBot(string version, string configPath, string dbConnectionString)
        {
            _state = BotState.Initialize(version, configPath);
            SentrySdk.Init(new SentryOptions
            {
                Dsn              = new Dsn(_state.SentryDsn),
                Debug            = true,
                AttachStacktrace = true
            });

            _client        = new DiscordSocketClient();
            _client.Log   += Log;
            _client.Ready += OnClientReady;

            _commands      = new CommandService();
            _commands.Log += Log;


            var types = Assembly.GetExecutingAssembly().FindTypesWithAttribute <ServiceAttribute>().ToImmutableArray();

            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commands)
                        .AddSingleton(_state)
                        .AddSingleton(MemeLoader.LoadAllTemplates())
                        .AddServices(types)
                        .AddDbContextPool <BotContext>(options => { options.UseSqlite(dbConnectionString); })
                        .BuildServiceProvider();
        }
Beispiel #2
0
        public DiscordBot(string filePath)
        {
            _state = BotState.Initialize(filePath);

            _client      = new DiscordSocketClient();
            _client.Log += Log;

            _commands = new CommandService();
            _services = new ServiceCollection();
        }
Beispiel #3
0
        public DiscordBot(string version, string configPath, string dbPath)
        {
            _state     = BotState.Initialize(version, configPath);
            _dbContext = new SQLiteAsyncConnection(dbPath);

            _completionSource = new TaskCompletionSource <Task>();
            _client           = new DiscordSocketClient();
            _client.Log      += Log;
            _client.Ready    += () =>
            {
                _completionSource.SetResult(Task.CompletedTask);
                Log($"Running as user {_client.CurrentUser.Username} ({_client.CurrentUser.Id})");
                return(Task.CompletedTask);
            };

            _commands = new CommandService();
            _services = null;
        }