Example #1
0
        public ProtectionService(DiscordSocketClient client, Kotocorn bot, MuteService mute, DbService db)
        {
            _log    = LogManager.GetCurrentClassLogger();
            _client = client;
            _mute   = mute;
            _db     = db;
            _bot    = bot;

            Initialize();

            _client.MessageReceived += HandleAntiSpam;
            _client.UserJoined      += HandleAntiRaid;

            _bot.JoinedGuild  += _bot_JoinedGuild;
            _client.LeftGuild += _client_LeftGuild;
        }
Example #2
0
 public UserPunishService(MuteService mute, DbService db)
 {
     _mute = mute;
     _db   = db;
 }
Example #3
0
        public LogCommandService(DiscordSocketClient client, KotocornStrings strings,
                                 Kotocorn bot, DbService db, MuteService mute, ProtectionService prot, GuildTimezoneService tz)
        {
            _client  = client;
            _log     = LogManager.GetCurrentClassLogger();
            _strings = strings;
            _db      = db;
            _mute    = mute;
            _prot    = prot;
            _tz      = tz;

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

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

                    await Task.WhenAll(keys.Select(key =>
                    {
                        if (PresenceUpdates.TryRemove(key, out var msgs))
                        {
                            var title = GetText(key.Guild, "presence_updates");
                            var desc  = string.Join(Environment.NewLine, msgs);
                            return(key.SendConfirmAsync(title, desc.TrimTo(2048)));
                        }
                        return(Task.CompletedTask);
                    }));
                }
                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_Kotocorn
            _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;
        }