コード例 #1
0
ファイル: FilterService.cs プロジェクト: Forex22/brackeys-bot
        private async Task DeleteMsgAndInfractUser(SocketUserMessage s, string message)
        {
            SocketGuildUser target = s.Author as SocketGuildUser;

            IReadOnlyCollection <SocketMessage> nearbyMessages = s.Channel.GetCachedMessages(s, Direction.Before, 1);
            SocketUserMessage linkMessage = nearbyMessages.Any() ? nearbyMessages.Last() as SocketUserMessage : s;
            string            url         = linkMessage.GetJumpUrl();

            // Delete message before creating infractions and notifying moderators because
            //  if something fails during infraction creation or notifying the moderators we
            //  are at least certain the message got deleted.
            await s.DeleteAsync();

            _moderationService.AddInfraction(target,
                                             Infraction.Create(_moderationService.RequestInfractionID())
                                             .WithType(InfractionType.Warning)
                                             .WithModerator(_discord.CurrentUser)
                                             .WithAdditionalInfo($"[Go near message]({url})\n**{message}**")
                                             .WithDescription("Used filtered word"));

            await _loggingService.CreateEntry(ModerationLogEntry.New
                                              .WithActionType(ModerationActionType.Filtered)
                                              .WithTarget(target)
                                              .WithReason($"[Go near message]({url})\n**{message}**")
                                              .WithTime(DateTimeOffset.Now)
                                              .WithModerator(_discord.CurrentUser));

            NotifyUser(s);
        }
コード例 #2
0
        private async Task DeleteMsgAndInfractUser(SocketUserMessage s, string message)
        {
            SocketGuildUser target = s.Author as SocketGuildUser;

            IReadOnlyCollection <SocketMessage> nearbyMessages = s.Channel.GetCachedMessages(s, Direction.Before, 1);
            SocketUserMessage linkMessage = nearbyMessages.Any() ? nearbyMessages.Last() as SocketUserMessage : s;
            string            url         = linkMessage.GetJumpUrl();

            // Delete message before creating infractions and notifying moderators because
            //  if something fails during infraction creation or notifying the moderators we
            //  are at least certain the message got deleted.
            await s.DeleteAsync();

            Infraction infraction;

            if (_dataService.Configuration.MuteUserIfUsingFilteredWord)
            {
                IRole mutedRole = _discord.GetGuild(_dataService.Configuration.GuildID).GetRole(_dataService.Configuration.MutedRoleID);
                await target.AddRoleAsync(mutedRole);

                _dataService.UserData.GetOrCreate(target.Id).Muted = true;
                _dataService.SaveUserData();

                TimeSpan muteDuration = TimeSpan.FromMilliseconds(_dataService.Configuration.FilteredWordMuteDuration);
                infraction = _moderationService.AddTemporaryInfraction(TemporaryInfractionType.TempMute,
                                                                       target, _discord.CurrentUser, muteDuration,
                                                                       "Used filtered word", $"[Go near message]({url})\n**{message}**");
            }
            else
            {
                infraction = Infraction.Create(_moderationService.RequestInfractionID())
                             .WithType(InfractionType.Warning)
                             .WithModerator(_discord.CurrentUser)
                             .WithAdditionalInfo($"[Go near message]({url})\n**{message}**")
                             .WithDescription("Used filtered word");

                _moderationService.AddInfraction(target, infraction);
            }

            await _loggingService.CreateEntry(ModerationLogEntry.New
                                              .WithInfractionId(infraction.ID)
                                              .WithActionType(ModerationActionType.Filtered)
                                              .WithTarget(target)
                                              .WithReason($"[Go near message]({url})\n**{message}**")
                                              .WithTime(DateTimeOffset.Now)
                                              .WithModerator(_discord.CurrentUser));

            NotifyUser(s);
        }
コード例 #3
0
        private void CheckTemporaryInfractions()
        {
            DateTime    now   = DateTime.UtcNow;
            SocketGuild guild = _client.GetGuild(_data.Configuration.GuildID);

            int resolvedCounter = 0;

            foreach (UserData user in _data.UserData.GetUsersWithTemporaryInfractions())
            {
                if (user.HasTemporaryInfraction(TemporaryInfractionType.TempBan))
                {
                    TemporaryInfraction infraction = user.TemporaryInfractions.First(t => t.Type == TemporaryInfractionType.TempBan);
                    if (infraction.Expire <= now)
                    {
                        guild.RemoveBanAsync(user.ID);

                        _ = _modLog.CreateEntry(ModerationLogEntry.New
                                                .WithActionType(ModerationActionType.Unban)
                                                .WithTarget(user.ID)
                                                .WithReason("Temporary ban timed out.")
                                                .WithTime(DateTimeOffset.Now)
                                                .WithModerator(_client.CurrentUser));

                        user.TemporaryInfractions.RemoveAll(i => i.Type == TemporaryInfractionType.TempBan);
                        resolvedCounter++;
                    }
                }
                if (user.HasTemporaryInfraction(TemporaryInfractionType.TempMute))
                {
                    TemporaryInfraction infraction = user.TemporaryInfractions.First(t => t.Type == TemporaryInfractionType.TempMute);
                    if (infraction.Expire <= now)
                    {
                        IRole mutedRole = guild.GetRole(_data.Configuration.MutedRoleID);

                        // If the user is no longer in the server, just remove the entry, but don't attempt to remove his role.
                        IGuildUser guildUser = guild.GetUser(user.ID);
                        guildUser?.RemoveRoleAsync(mutedRole);

                        user.Muted = false;
                        _data.SaveUserData();

                        ModerationLogEntry entry = ModerationLogEntry.New
                                                   .WithActionType(ModerationActionType.Unmute)
                                                   .WithReason("Temporary mute timed out.")
                                                   .WithTime(DateTimeOffset.Now)
                                                   .WithModerator(_client.CurrentUser);

                        if (guildUser != null)
                        {
                            entry = entry.WithTarget(guildUser);
                        }
                        else
                        {
                            entry = entry.WithTarget(user.ID);
                        }

                        _ = _modLog.CreateEntry(entry);

                        user.TemporaryInfractions.RemoveAll(i => i.Type == TemporaryInfractionType.TempMute);
                        resolvedCounter++;
                    }
                }
            }

            if (resolvedCounter > 0)
            {
                _log.LogMessageAsync(new LogMessage(LogSeverity.Info, "TemporaryInfractions", $"Resolved {resolvedCounter} temporary infraction(s)."));
                _data.SaveUserData();
            }
        }