public LogCommandService(DiscordSocketClient client, NadekoStrings strings,
                                 IEnumerable <GuildConfig> gcs, DbService db, MuteService mute, ProtectionService prot, GuildTimezoneService tz)
        {
            _client  = client;
            _log     = LogManager.GetCurrentClassLogger();
            _strings = strings;
            _db      = db;
            _tz      = tz;

            GuildLogSettings = gcs
                               .ToDictionary(g => g.GuildId, g => g.LogSetting)
                               .ToConcurrent();

            var timer = new Timer(async state =>
            {
                try
                {
                    var keys = PresenceUpdates.Keys.ToList();

                    await Task.WhenAll(keys.Select(key =>
                    {
                        if (!PresenceUpdates.TryRemove(key, out var msgs))
                        {
                            return(Task.CompletedTask);
                        }
                        var title = GetText(key.Guild, "presence_updates");
                        var desc  = string.Join(Environment.NewLine, msgs);
                        return(key.SendConfirmAsync(title, desc.TrimTo(2048)));
                    }));
                }
                catch (Exception ex)
                {
                    _log.Warn(ex);
                }
            }, null, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));

            //_client.MessageReceived += _client_MessageReceived;
            _client.MessageUpdated += _client_MessageUpdated;
            _client.MessageDeleted += _client_MessageDeleted;
            _client.UserBanned     += _client_UserBanned;
            _client.UserUnbanned   += _client_UserUnbanned;
            _client.UserJoined     += _client_UserJoined;
            _client.UserLeft       += _client_UserLeft;
            //_client.UserPresenceUpdated += _client_UserPresenceUpdated;
            _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
            _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated_TTS;
            _client.GuildMemberUpdated    += _client_GuildUserUpdated;
#if !GLOBAL_NADEKO
            _client.UserUpdated += _client_UserUpdated;
#endif
            _client.ChannelCreated   += _client_ChannelCreated;
            _client.ChannelDestroyed += _client_ChannelDestroyed;
            _client.ChannelUpdated   += _client_ChannelUpdated;

            mute.UserMuted   += MuteCommands_UserMuted;
            mute.UserUnmuted += MuteCommands_UserUnmuted;

            prot.OnAntiProtectionTriggered += TriggeredAntiProtection;
        }
Ejemplo n.º 2
0
        public LogService(DiscordSocketClient client, StringService strings, DbService db, MuteService mute, ProtectionService prot, GuildTimezoneService tz, VerificationService vs)
        {
            _client  = client;
            _db      = db;
            _strings = strings;
            _tzs     = tz;
            _vs      = vs;
            _log     = LogManager.GetCurrentClassLogger();

            var timer = new Timer(async state => {
                try {
                    var keys = PresenceUpdates.Keys.ToList();

                    await Task.WhenAll(keys.Select(key => {
                        if (!PresenceUpdates.TryRemove(key, out var msgs))
                        {
                            return(Task.CompletedTask);
                        }
                        var title = GetText(key.Guild, "presence_updates");
                        var desc  = string.Join(Environment.NewLine, msgs);
                        return(key.SendConfirmAsync(desc.TrimTo(2048), title));
                    }));
                } catch (Exception ex) {
                    _log.Warn(ex);
                }
            }, null, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));

            //_client.MessageReceived      += _client_MessageReceived;
            _client.MessageUpdated += _client_MessageUpdated;
            _client.MessageDeleted += _client_MessageDeleted;
            _client.UserBanned     += _client_UserBanned;
            _client.UserUnbanned   += _client_UserUnbanned;
            _client.UserJoined     += _client_UserJoined;
            _client.UserLeft       += _client_UserLeft;
            //_client.UserPresenceUpdated  += _client_UserPresenceUpdated;
            _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
            _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated_TTS;
            _client.GuildMemberUpdated    += _client_GuildUserUpdated;
            _client.UserUpdated           += _client_UserUpdated;
            _client.ChannelCreated        += _client_ChannelCreated;
            _client.ChannelDestroyed      += _client_ChannelDestroyed;
            _client.ChannelUpdated        += _client_ChannelUpdated;

            mute.UserMuted   += MuteCommands_UserMuted;
            mute.UserUnmuted += MuteCommands_UserUnmuted;

            prot.OnAntiProtectionTriggered += TriggeredAntiProtection;

            _vs.VerificationStep    += VerificationService_VerificationStep;
            _vs.VerificationMessage += VerificationService_VerificationMessage;
        }