Exemplo n.º 1
0
        private async Task _client_MessageReceived_Slowmode(SocketMessage m)
        {
            if (m.Author.Id == _client.CurrentUser.Id)
            {
                return;                                        // Ignore messages from the bot itself
            }
            if (!(m.Author is SocketGuildUser author))
            {
                return;                                        // Ignore messages that do not come from a guild
            }
            if (author.Roles.Select(r => r.Id).Any(x => _config.BypassIds.Contains(x)))
            {
                return;                                                                         // Ignore messages from privileged users
            }
            var channel = m.Channel as SocketTextChannel;

            if (!Intervals.ContainsKey(channel))
            {
                return;                                  // Ignore channels for which slowmode is not enabled
            }
            var interval = Intervals[channel];

            if (!_lastMessage.ContainsKey(author.Id))
            {
                var dictionary = new Dictionary <SocketTextChannel, DateTime>();
                dictionary.Add(channel, DateTime.UtcNow);
                _lastMessage.Add(author.Id, dictionary);
            }
            else
            {
                if (DateTime.UtcNow.Subtract(_lastMessage[author.Id][channel]).TotalSeconds >= Intervals[channel]) // If the user's message was sent after the interval was up
                {
                    _lastMessage[author.Id][channel] = DateTime.UtcNow;
                }
                else
                {
                    // Delete message and mute user
                    await m.DeleteAsync();

                    var muteRole = author.Guild.GetRole(_config.MuteRoleId);
                    await author.AddRoleAsync(muteRole);

                    // author.Guild.Id, author.Id, 0, DateTime.UtcNow, DateTime.UtcNow.Add(MuteTime), "N/A (SLOWMODE AUTO-MUTE)"
                    var mute = await _records.AddMuteAsync(new Mute
                    {
                        GuildId     = author.Guild.Id,
                        SubjectId   = author.Id,
                        ModeratorId = 0,
                        Timestamp   = DateTime.UtcNow,
                        UnmuteAt    = DateTime.UtcNow.Add(MuteTime),
                        Reason      = "N/A (SLOWMODE AUTO-MUTE)",
                        Active      = true
                    });

                    _unpunish.Mutes.Add(mute);
                    _records.DisposeContext();
                    await _log.LogModMessageAsync($"Automatically muted {author.Nickname ?? author.Username}#{author.Discriminator} ({author.Id})'s message in {channel.Mention} for {MuteTime.Humanize(5)} for violating slowmode: `{m.Content}`");
                }
            }
        }
Exemplo n.º 2
0
        private async Task _client_MessageReceived_Ratelimit(SocketMessage m)
        {
            if (m.Author.Id == _client.CurrentUser.Id) return;
            var message = m as SocketUserMessage;
            if (m == null) return;
            var author = m.Author as SocketGuildUser;
            if (author == null) return;
            if (IgnoredChannels.Contains(m.Channel.Id)) return;

            if (author.Roles.Select(r => r.Id).Any(x => _config.BypassIds.Contains(x))) return;

            if (!_lastthreemessages.ContainsKey(author.Id))
                _lastthreemessages.Add(author.Id, new DateTime[3]);

            // if it has been at least <limit> since the user's last 3 messages were sent
            if (_lastthreemessages[author.Id].All(x => DateTime.Compare(DateTime.UtcNow, x.AddSeconds(Limit)) > 0))
            {
                _lastthreemessages[author.Id][0] = _lastthreemessages[author.Id][1];
                _lastthreemessages[author.Id][1] = _lastthreemessages[author.Id][2];
                _lastthreemessages[author.Id][2] = DateTime.UtcNow;
            }
            else
            {
                var muteRole = author.Guild.GetRole(_config.MuteRoleId);
                await author.AddRoleAsync(muteRole);

                var dmChannel = await author.GetOrCreateDMChannelAsync();
                await dmChannel.SendMessageAsync($"You've been muted for {MuteTime.Humanize(5)} for ratelimiting: `{m.Content}`");
                var name = author.Nickname == null
                    ? author.Username
                    : $"{author.Username} (nickname: {author.Nickname})";
                await _log.LogModMessageAsync($"I automatically muted **{name} ({author.Id})** for {MuteTime.Humanize(5)} ratelimiting in {(m.Channel as SocketTextChannel).Mention}: `{m.Content}`");
                var mute = await _records.AddMuteAsync(new Mute
                {
                    GuildId = author.Guild.Id,
                    SubjectId = author.Id,
                    ModeratorId = 0,
                    Timestamp = DateTime.UtcNow,
                    UnmuteAt = DateTime.UtcNow.Add(MuteTime),
                    Reason = "N/A (RATELIMIT AUTO-MUTE)",
                    Active = true
                });
                _records.DisposeContext();
                _unpunish.Mutes.Add(mute);
            }
        }
Exemplo n.º 3
-1
        private async Task _client_MessageReceived_Blacklist(SocketMessage m)
        {
            if (m.Author.Id == _client.CurrentUser.Id)
            {
                return;
            }
            var author = m.Author as SocketGuildUser;

            if (author == null)
            {
                return;
            }
            var guild = (m.Channel as SocketGuildChannel)?.Guild;

            if (guild == null)
            {
                return;
            }
            if (author.Roles.Select(r => r.Id).Any(x => _config.BypassIds.Contains(x)))
            {
                return;
            }
            var violation = CheckViolation(m);

            if (!violation.IsViolating)
            {
                return;
            }

            var muteRole = guild.GetRole(_config.MuteRoleId);
            await m.DeleteAsync();

            await author.AddRoleAsync(muteRole);

            var dmChannel = await author.GetOrCreateDMChannelAsync();

            Mute mute = null;

            if (violation.Blacklist == null)
            {
                await dmChannel.SendMessageAsync($"You've been muted for {GlobalBlacklist.MuteTime.Humanize(5)} for violating the world blacklist: `{m.Content}`");

                var name = author.Nickname == null
                    ? author.Username
                    : $"{author.Username} (nickname: {author.Nickname})";
                await _log.LogModMessageAsync($"I automatically muted **{name} ({author.Id})** for {GlobalBlacklist.MuteTime.Humanize(5)} for violating the word blacklist in {(m.Channel as SocketTextChannel).Mention}: `{m.Content}`");

                mute = await _records.AddMuteAsync(new Mute
                {
                    GuildId     = guild.Id,
                    SubjectId   = author.Id,
                    ModeratorId = 0,
                    Timestamp   = DateTime.UtcNow,
                    UnmuteAt    = DateTime.UtcNow.Add(GlobalBlacklist.MuteTime),
                    Reason      = "N/A (BLACKLIST AUTO-MUTE)",
                    Active      = true
                });
            }
            else
            {
                await dmChannel.SendMessageAsync($"You've been muted for {violation.Blacklist.MuteTime.Humanize(5)} for violating the world blacklist: `{m.Content}`");

                var name = author.Nickname == null
                    ? author.Username
                    : $"{author.Username} (nickname: {author.Nickname})";
                await _log.LogModMessageAsync($"I automatically muted **{name} ({author.Id})** for {violation.Blacklist.MuteTime.Humanize(5)} for violating the word blacklist in {(m.Channel as SocketTextChannel).Mention}: `{m.Content}`");

                mute = await _records.AddMuteAsync(new Mute
                {
                    GuildId     = guild.Id,
                    SubjectId   = author.Id,
                    ModeratorId = 0,
                    Timestamp   = DateTime.UtcNow,
                    UnmuteAt    = DateTime.UtcNow.Add(violation.Blacklist.MuteTime),
                    Reason      = "N/A (BLACKLIST AUTO-MUTE)",
                    Active      = true
                });
            }
            _records.DisposeContext();
            _unpunish.Mutes.Add(mute);
        }