This commit is contained in:
+21
-2
@@ -1,3 +1,5 @@
|
||||
import { moderatorMaximumRestrictionMs, type AuthUser } from './auth.js';
|
||||
|
||||
export type ModerationGame = 't5' | 't6';
|
||||
export type ModerationScope = 'server' | 'game' | 'fleet';
|
||||
export type ModerationActionKind = 'warn' | 'message' | 'kick' | 'announce';
|
||||
@@ -9,8 +11,8 @@ export interface ModerationPlayer {
|
||||
guid: string;
|
||||
name: string;
|
||||
aliases: string[];
|
||||
firstSeen: string;
|
||||
lastSeen: string;
|
||||
firstSeen: string | null;
|
||||
lastSeen: string | null;
|
||||
servers: string[];
|
||||
restrictions: number;
|
||||
}
|
||||
@@ -31,6 +33,23 @@ export interface ModerationSanction {
|
||||
revision: number;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export function canRevokeModerationRestriction(
|
||||
actor: Pick<AuthUser, 'id' | 'role'> | null | undefined,
|
||||
restriction: Pick<ModerationSanction, 'actorId' | 'scope' | 'createdAt' | 'expiresAt'>
|
||||
): boolean {
|
||||
if (actor?.role === 'admin') return true;
|
||||
if (
|
||||
actor?.role !== 'moderator' ||
|
||||
actor.id !== restriction.actorId ||
|
||||
(restriction.scope !== 'server' && restriction.scope !== 'game') ||
|
||||
!restriction.expiresAt
|
||||
)
|
||||
return false;
|
||||
const duration = Date.parse(restriction.expiresAt) - Date.parse(restriction.createdAt);
|
||||
return duration > 0 && duration <= moderatorMaximumRestrictionMs;
|
||||
}
|
||||
|
||||
export interface ModerationAction {
|
||||
id: string;
|
||||
game: ModerationGame;
|
||||
|
||||
Reference in New Issue
Block a user