コード例 #1
0
 public CaseView(ModCase modCase)
 {
     Id                = modCase.Id;
     CaseId            = modCase.CaseId;
     GuildId           = modCase.GuildId.ToString();
     Title             = modCase.Title;
     Description       = modCase.Description;
     UserId            = modCase.UserId.ToString();
     Username          = modCase.Username;
     Discriminator     = modCase.Discriminator;
     Nickname          = modCase.Nickname;
     ModId             = modCase.ModId.ToString();
     CreatedAt         = modCase.CreatedAt;
     OccuredAt         = modCase.OccuredAt;
     LastEditedAt      = modCase.LastEditedAt;
     LastEditedByModId = modCase.LastEditedByModId.ToString();
     Labels            = modCase.Labels;
     Others            = modCase.Others;
     Valid             = modCase.Valid;
     CreationType      = modCase.CreationType;
     PunishmentType    = modCase.PunishmentType;
     PunishedUntil     = modCase.PunishedUntil;
     PunishmentActive  = modCase.PunishmentActive;
     AllowComments     = modCase.AllowComments;
     LockedByUserId    = modCase.LockedByUserId.ToString();
     LockedAt          = modCase.LockedAt;
     MarkedToDeleteAt  = modCase.MarkedToDeleteAt;
     DeletedByUserId   = modCase.DeletedByUserId.ToString();
 }
コード例 #2
0
        public CaseExpandedView(ModCase modCase, IUser moderator, IUser lastModerator, IUser suspect, List <CommentExpandedView> comments, UserNoteExpandedView userNoteView)
        {
            ModCase       = new CaseView(modCase);
            Moderator     = DiscordUserView.CreateOrDefault(moderator);
            LastModerator = DiscordUserView.CreateOrDefault(lastModerator);
            Suspect       = DiscordUserView.CreateOrDefault(suspect);
            Comments      = comments;
            UserNote      = userNoteView;

            if (modCase.PunishedUntil != null)
            {
                if (modCase.PunishedUntil > modCase.CreatedAt)
                {
                    if (modCase.PunishedUntil < DateTime.UtcNow)
                    {
                        PunishmentProgress = 100;
                    }
                    else
                    {
                        double totalPunished   = (modCase.PunishedUntil.Value - modCase.CreatedAt).TotalSeconds;
                        double alreadyPunished = (DateTime.UtcNow - modCase.CreatedAt).TotalSeconds;

                        PunishmentProgress = alreadyPunished / totalPunished * 100;
                    }
                }
            }
        }
コード例 #3
0
        public void RemoveModeratorInfo()
        {
            Moderator     = null;
            LastModerator = null;
            LockedBy      = null;
            DeletedBy     = null;
            ModCase.RemoveModeratorInfo();

            foreach (var comment in Comments)
            {
                comment.RemoveModeratorInfo(ModCase.UserId);
            }
        }
コード例 #4
0
        public async Task <bool> IsAllowedTo(APIActionPermission permission, ModCase modCase)
        {
            if (modCase == null)
            {
                return(false);
            }
            if (IsSiteAdmin())
            {
                return(true);
            }
            switch (permission)
            {
            case APIActionPermission.View:
                if (currentUser == null)
                {
                    return(false);
                }
                return(modCase.UserId == currentUser.Id || await HasPermissionOnGuild(DiscordPermission.Moderator, modCase.GuildId));

            case APIActionPermission.Delete:
                return(await HasPermissionOnGuild(DiscordPermission.Moderator, modCase.GuildId));

            case APIActionPermission.ForceDelete:
                return(false);     // only siteadmin

            case APIActionPermission.Edit:
                GuildConfig guildConfig;
                try
                {
                    using var scope = _serviceProvider.CreateScope();
                    guildConfig     = await GuildConfigRepository.CreateDefault(scope.ServiceProvider).GetGuildConfig(modCase.GuildId);
                }
                catch (ResourceNotFoundException)
                {
                    return(false);
                }
                if (guildConfig.StrictModPermissionCheck && modCase.PunishmentType != PunishmentType.Warn)
                {
                    GuildPermission x = GuildPermission.CreateInstantInvite;
                    if (modCase.PunishmentType == PunishmentType.Kick)
                    {
                        x = GuildPermission.KickMembers;
                    }
                    if (modCase.PunishmentType == PunishmentType.Ban)
                    {
                        x = GuildPermission.BanMembers;
                    }
                    if (modCase.PunishmentType == PunishmentType.Mute)
                    {
                        x = GuildPermission.ManageRoles;
                    }
                    if (await HasPermissionOnGuild(DiscordPermission.Admin, modCase.GuildId))
                    {
                        return(true);
                    }
                    return(await HasPermissionOnGuild(DiscordPermission.Moderator, modCase.GuildId) &&
                           await HasRolePermissionInGuild(modCase.GuildId, x));
                }
                return(await HasPermissionOnGuild(DiscordPermission.Moderator, modCase.GuildId));
            }
            return(false);
        }
コード例 #5
0
 public ModCaseTableEntry(ModCase modCase, IUser moderator, IUser suspect)
 {
     ModCase   = new CaseView(modCase);
     Moderator = DiscordUserView.CreateOrDefault(moderator);
     Suspect   = DiscordUserView.CreateOrDefault(suspect);
 }
コード例 #6
0
 public void RemoveModeratorInfo()
 {
     Moderator = null;
     ModCase.RemoveModeratorInfo();
 }