Esempio n. 1
0
        public async Task InitializeAsync()
        {
            _service.AddTypeParsers();
            var sw     = Stopwatch.StartNew();
            var loaded = _service.AddModules(Assembly.GetEntryAssembly());

            sw.Stop();
            await _logger.Log(LogSeverity.Info, LogSource.DepressedBot,
                              $"Loaded {loaded.Count} modules and {loaded.Sum(m => m.Commands.Count)} commands loaded in {sw.ElapsedMilliseconds}ms.");

            _client.Log += async(m) => await _logger.Log(new LogEventArgs(m));

            _client.Ready += async() => await OnReady(new ReadyEventArgs(_client));

            _client.MessageReceived += async(s) =>
            {
                if (!(s is SocketUserMessage msg))
                {
                    return;
                }
                if (msg.Author.IsBot)
                {
                    return;
                }
                if (msg.Channel is IDMChannel dm)
                {
                    if (msg.Content.StartsWith($"{Config.CommandPrefix}confess", StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }
                    await dm.SendMessageAsync("I do not support commands via DM.");

                    return;
                }

                var args = new MessageReceivedEventArgs(msg);
                await HandleMessageReceivedAsync(args);
            };
            _client.MessageReceived += async(s) =>
            {
                if (!(s is SocketUserMessage msg))
                {
                    return;
                }
                if (msg.Author.IsBot)
                {
                    return;
                }
                await _confessional.HandleMessageAsync(new DepressedBotContext(_client, msg, _provider));
            };
        }