refactor progress

This commit is contained in:
Hampus Kraft
2026-02-17 12:22:36 +00:00
parent cb31608523
commit d5abd1a7e4
8257 changed files with 1190207 additions and 761040 deletions

View File

@@ -1,102 +0,0 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
export enum AuditLogActionType {
GUILD_UPDATE = 1,
CHANNEL_CREATE = 10,
CHANNEL_UPDATE = 11,
CHANNEL_DELETE = 12,
CHANNEL_OVERWRITE_CREATE = 13,
CHANNEL_OVERWRITE_UPDATE = 14,
CHANNEL_OVERWRITE_DELETE = 15,
MEMBER_KICK = 20,
MEMBER_PRUNE = 21,
MEMBER_BAN_ADD = 22,
MEMBER_BAN_REMOVE = 23,
MEMBER_UPDATE = 24,
MEMBER_ROLE_UPDATE = 25,
MEMBER_MOVE = 26,
MEMBER_DISCONNECT = 27,
BOT_ADD = 28,
ROLE_CREATE = 30,
ROLE_UPDATE = 31,
ROLE_DELETE = 32,
INVITE_CREATE = 40,
INVITE_UPDATE = 41,
INVITE_DELETE = 42,
WEBHOOK_CREATE = 50,
WEBHOOK_UPDATE = 51,
WEBHOOK_DELETE = 52,
EMOJI_CREATE = 60,
EMOJI_UPDATE = 61,
EMOJI_DELETE = 62,
STICKER_CREATE = 90,
STICKER_UPDATE = 91,
STICKER_DELETE = 92,
MESSAGE_DELETE = 72,
MESSAGE_BULK_DELETE = 73,
MESSAGE_PIN = 74,
MESSAGE_UNPIN = 75,
}
export const ALL_AUDIT_LOG_ACTION_TYPES: ReadonlyArray<AuditLogActionType> = [
AuditLogActionType.GUILD_UPDATE,
AuditLogActionType.CHANNEL_CREATE,
AuditLogActionType.CHANNEL_UPDATE,
AuditLogActionType.CHANNEL_DELETE,
AuditLogActionType.CHANNEL_OVERWRITE_CREATE,
AuditLogActionType.CHANNEL_OVERWRITE_UPDATE,
AuditLogActionType.CHANNEL_OVERWRITE_DELETE,
AuditLogActionType.MEMBER_KICK,
AuditLogActionType.MEMBER_PRUNE,
AuditLogActionType.MEMBER_BAN_ADD,
AuditLogActionType.MEMBER_BAN_REMOVE,
AuditLogActionType.MEMBER_UPDATE,
AuditLogActionType.MEMBER_ROLE_UPDATE,
AuditLogActionType.MEMBER_MOVE,
AuditLogActionType.MEMBER_DISCONNECT,
AuditLogActionType.BOT_ADD,
AuditLogActionType.ROLE_CREATE,
AuditLogActionType.ROLE_UPDATE,
AuditLogActionType.ROLE_DELETE,
AuditLogActionType.INVITE_CREATE,
AuditLogActionType.INVITE_UPDATE,
AuditLogActionType.INVITE_DELETE,
AuditLogActionType.WEBHOOK_CREATE,
AuditLogActionType.WEBHOOK_UPDATE,
AuditLogActionType.WEBHOOK_DELETE,
AuditLogActionType.EMOJI_CREATE,
AuditLogActionType.EMOJI_UPDATE,
AuditLogActionType.EMOJI_DELETE,
AuditLogActionType.STICKER_CREATE,
AuditLogActionType.STICKER_UPDATE,
AuditLogActionType.STICKER_DELETE,
AuditLogActionType.MESSAGE_DELETE,
AuditLogActionType.MESSAGE_BULK_DELETE,
AuditLogActionType.MESSAGE_PIN,
AuditLogActionType.MESSAGE_UNPIN,
];

View File

@@ -17,22 +17,26 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {AuditLogActionType} from '@fluxer/constants/src/AuditLogActionType';
import type {ValueOf} from '@fluxer/constants/src/ValueOf';
import type {I18n, MessageDescriptor} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import {AuditLogActionType} from './AuditLogActionType';
export const AUDIT_LOG_TARGET_TYPES = {
ALL: 'all',
GUILD: 'guild',
MEMBER: 'member',
USER: 'user',
ROLE: 'role',
CHANNEL: 'channel',
EMOJI: 'emoji',
STICKER: 'sticker',
INVITE: 'invite',
WEBHOOK: 'webhook',
MESSAGE: 'message',
} as const;
export type AuditLogTargetType = (typeof AUDIT_LOG_TARGET_TYPES)[keyof typeof AUDIT_LOG_TARGET_TYPES];
export type AuditLogTargetType = ValueOf<typeof AUDIT_LOG_TARGET_TYPES>;
export interface AuditLogActionDefinition {
value: AuditLogActionType;
@@ -230,14 +234,17 @@ export function getTranslatedAuditLogActions(i18n: I18n): Array<{
}
export const AUDIT_LOG_TARGET_LABELS: Record<AuditLogTargetType, MessageDescriptor> = {
[AUDIT_LOG_TARGET_TYPES.ALL]: msg`All`,
[AUDIT_LOG_TARGET_TYPES.GUILD]: msg`Community`,
[AUDIT_LOG_TARGET_TYPES.MEMBER]: msg`Member`,
[AUDIT_LOG_TARGET_TYPES.USER]: msg`User`,
[AUDIT_LOG_TARGET_TYPES.ROLE]: msg`Role`,
[AUDIT_LOG_TARGET_TYPES.CHANNEL]: msg`Channel`,
[AUDIT_LOG_TARGET_TYPES.EMOJI]: msg`Emoji`,
[AUDIT_LOG_TARGET_TYPES.STICKER]: msg`Sticker`,
[AUDIT_LOG_TARGET_TYPES.INVITE]: msg`Invite`,
[AUDIT_LOG_TARGET_TYPES.WEBHOOK]: msg`Webhook`,
[AUDIT_LOG_TARGET_TYPES.MESSAGE]: msg`Message`,
};
export function getTranslatedAuditLogTargetLabels(i18n: I18n): Record<AuditLogTargetType, string> {

View File

@@ -0,0 +1,23 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
export enum HelpCenterArticleSlug {
AttachmentExpiry = 'attachment-expiry',
ChangeDateOfBirth = 'change-date-of-birth',
}

View File

@@ -20,7 +20,7 @@
import type {I18n, MessageDescriptor} from '@lingui/core';
import {msg} from '@lingui/core/macro';
export interface ViolationCategoryDescriptor {
interface ViolationCategoryDescriptor {
value: string;
name: MessageDescriptor;
desc: MessageDescriptor;

View File

@@ -0,0 +1,119 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import DeveloperModeStore from '@app/stores/DeveloperModeStore';
import type {MessageDescriptor} from '@lingui/core';
import {msg} from '@lingui/core/macro';
const BASE_PRESETS = [
{key: '15m', minutes: 15},
{key: '30m', minutes: 30},
{key: '1h', minutes: 60},
{key: '3h', minutes: 3 * 60},
{key: '4h', minutes: 4 * 60},
{key: '8h', minutes: 8 * 60},
{key: '24h', minutes: 24 * 60},
{key: '3d', minutes: 3 * 24 * 60},
{key: 'never', minutes: null},
] as const;
const DEVELOPER_PRESETS = [{key: '10s', minutes: 10 / 60}] as const;
const ALL_PRESETS = [...BASE_PRESETS, ...DEVELOPER_PRESETS] as const;
const BASE_TIME_WINDOW_KEYS: ReadonlyArray<(typeof BASE_PRESETS)[number]['key']> = BASE_PRESETS.map(
(preset) => preset.key,
);
const DEVELOPER_TIME_WINDOW_KEYS: ReadonlyArray<(typeof DEVELOPER_PRESETS)[number]['key']> = DEVELOPER_PRESETS.map(
(preset) => preset.key,
);
export type TimeWindowKey = (typeof ALL_PRESETS)[number]['key'];
export type TimeWindowPreset = (typeof ALL_PRESETS)[number];
const PRESET_MAP = new Map<TimeWindowKey, TimeWindowPreset>(ALL_PRESETS.map((preset) => [preset.key, preset]));
export const TIME_WINDOW_PRESETS: ReadonlyArray<TimeWindowPreset> = BASE_PRESETS;
export const DEFAULT_TIME_WINDOW_KEY: TimeWindowKey = '24h';
export const TIME_WINDOW_LABEL_MESSAGES: Record<TimeWindowKey, MessageDescriptor> = {
'10s': msg`10 seconds`,
'15m': msg`15 minutes`,
'30m': msg`30 minutes`,
'1h': msg`1 hour`,
'3h': msg`3 hours`,
'4h': msg`4 hours`,
'8h': msg`8 hours`,
'24h': msg`24 hours`,
'3d': msg`3 days`,
never: msg`Don't clear`,
};
export const TIME_WINDOW_FOR_LABEL_MESSAGES: Record<Exclude<TimeWindowKey, 'never'>, MessageDescriptor> = {
'10s': msg`For 10 seconds`,
'15m': msg`For 15 minutes`,
'30m': msg`For 30 minutes`,
'1h': msg`For 1 hour`,
'3h': msg`For 3 hours`,
'4h': msg`For 4 hours`,
'8h': msg`For 8 hours`,
'24h': msg`For 24 hours`,
'3d': msg`For 3 days`,
};
export const minutesToMs = (minutes: number | null): number | null => (minutes == null ? null : minutes * 60 * 1000);
export const getTimeWindowPreset = (key: TimeWindowKey): TimeWindowPreset | undefined => PRESET_MAP.get(key);
const getTimeWindowKeys = (includeDeveloperOptions: boolean): ReadonlyArray<TimeWindowKey> => {
if (!includeDeveloperOptions) return BASE_TIME_WINDOW_KEYS;
return [...DEVELOPER_TIME_WINDOW_KEYS, ...BASE_TIME_WINDOW_KEYS];
};
export const createTimeWindowOptionList = (keys: ReadonlyArray<TimeWindowKey>): ReadonlyArray<TimeWindowPreset> => {
const list = keys.map((key) => {
const preset = PRESET_MAP.get(key);
if (!preset) {
throw new Error(`Unknown time window key: ${key}`);
}
return preset;
});
const neverIndex = list.findIndex((preset) => preset.key === 'never');
if (neverIndex <= 0) return list;
const neverPreset = list[neverIndex];
const withoutNever = list.filter((_, index) => index !== neverIndex);
return [neverPreset, ...withoutNever];
};
export const getTimeWindowPresets = (options?: {
includeDeveloperOptions?: boolean;
includeNever?: boolean;
}): ReadonlyArray<TimeWindowPreset> => {
const includeDeveloperOptions = options?.includeDeveloperOptions ?? DeveloperModeStore.isDeveloper;
const includeNever = options?.includeNever ?? true;
const keys = getTimeWindowKeys(includeDeveloperOptions);
const filteredKeys = includeNever ? keys : keys.filter((key) => key !== 'never');
return createTimeWindowOptionList(filteredKeys);
};
export const getFiniteTimeWindowPresets = (options?: {
includeDeveloperOptions?: boolean;
}): ReadonlyArray<TimeWindowPreset> =>
getTimeWindowPresets({includeDeveloperOptions: options?.includeDeveloperOptions, includeNever: false});