Files
discord-decomp/modules/guild_automod/AutomodTriggerConfigs.tsx
T
2026-11-01 12:12:55 +02:00

157 lines
6.0 KiB
TypeScript

// Metro module 16377 (f16378).
import { useMemo } from "react";
import * as _Constants from "./Constants";
import { AutomodTriggerType, MENTION_SPAM_LIMIT_DEFAULT } from "./Constants";
import { intl, t } from "../../intl/index.native";
import { useIsUserProfileRuleEnabled } from "./PermissionUtils";
import * as _ExperimentUtils from "./ExperimentUtils";
let c11784_5, c11784_6, c11784_7;
const { AutomodActionType, AutomodEventType } = _Constants;
const r27 = {
NEW: "new",
RECOMMENDED: "recommended",
BETA: "beta",
ALPHA: "alpha"
};
const r32 = {};
r32[AutomodTriggerType.SPAM_LINK] = {
getDefaultRuleName: () => intl.string(t.ffR2cM),
type: AutomodTriggerType.SPAM_LINK,
eventType: AutomodEventType.MESSAGE_SEND,
perGuildMaxCount: 0,
availableActionTypes: new Set(),
flags: new Set(),
defaultActionTypes: new Set()
};
r32[AutomodTriggerType.KEYWORD] = {
getDefaultRuleName: () => intl.string(t.ffR2cM),
type: AutomodTriggerType.KEYWORD,
eventType: AutomodEventType.MESSAGE_SEND,
perGuildMaxCount: 6,
availableActionTypes: new Set([AutomodActionType.BLOCK_MESSAGE, AutomodActionType.FLAG_TO_CHANNEL, AutomodActionType.USER_COMMUNICATION_DISABLED]),
flags: new Set(),
defaultActionTypes: new Set([AutomodActionType.BLOCK_MESSAGE])
};
r32[AutomodTriggerType.ML_SPAM] = {
getDefaultRuleName: () => intl.string(t["puF/Os"]),
type: AutomodTriggerType.ML_SPAM,
eventType: AutomodEventType.MESSAGE_SEND,
perGuildMaxCount: 1,
availableActionTypes: new Set([AutomodActionType.BLOCK_MESSAGE, AutomodActionType.FLAG_TO_CHANNEL]),
flags: new Set([]),
defaultActionTypes: new Set([AutomodActionType.BLOCK_MESSAGE])
};
r32[AutomodTriggerType.DEFAULT_KEYWORD_LIST] = {
getDefaultRuleName: () => intl.string(t.LnGhZv),
type: AutomodTriggerType.DEFAULT_KEYWORD_LIST,
eventType: AutomodEventType.MESSAGE_SEND,
perGuildMaxCount: 1,
availableActionTypes: new Set([AutomodActionType.BLOCK_MESSAGE, AutomodActionType.FLAG_TO_CHANNEL]),
flags: new Set([]),
defaultActionTypes: new Set([AutomodActionType.BLOCK_MESSAGE])
};
r32[AutomodTriggerType.MENTION_SPAM] = {
getDefaultRuleName: () => intl.string(t.pX7i6n),
type: AutomodTriggerType.MENTION_SPAM,
eventType: AutomodEventType.MESSAGE_SEND,
perGuildMaxCount: 1,
availableActionTypes: new Set([AutomodActionType.BLOCK_MESSAGE, AutomodActionType.FLAG_TO_CHANNEL, AutomodActionType.USER_COMMUNICATION_DISABLED]),
flags: new Set([]),
defaultActionTypes: new Set([AutomodActionType.BLOCK_MESSAGE])
};
r32[AutomodTriggerType.USER_PROFILE] = {
getDefaultRuleName: () => intl.string(t.q1L2v8),
type: AutomodTriggerType.USER_PROFILE,
eventType: AutomodEventType.GUILD_MEMBER_JOIN_OR_UPDATE,
perGuildMaxCount: 1,
availableActionTypes: new Set([AutomodActionType.QUARANTINE_USER, AutomodActionType.FLAG_TO_CHANNEL]),
flags: new Set([]),
defaultActionTypes: new Set([AutomodActionType.QUARANTINE_USER])
};
r32[AutomodTriggerType.SERVER_POLICY] = {
getDefaultRuleName: () => intl.string(t.ZQr92M),
type: AutomodTriggerType.SERVER_POLICY,
eventType: AutomodEventType.MESSAGE_SEND,
perGuildMaxCount: 1,
availableActionTypes: new Set([AutomodActionType.FLAG_TO_CHANNEL]),
flags: new Set([r27.ALPHA]),
defaultActionTypes: new Set()
};
c11784_5 = r32;
c11784_6 = {
MEMBERS: "members",
CONTENT: "content"
};
const r218 = {};
r218[c11784_6.MEMBERS] = [c11784_5[AutomodTriggerType.USER_PROFILE]];
r218[c11784_6.CONTENT] = [c11784_5[AutomodTriggerType.SERVER_POLICY], c11784_5[AutomodTriggerType.MENTION_SPAM], c11784_5[AutomodTriggerType.ML_SPAM], c11784_5[AutomodTriggerType.DEFAULT_KEYWORD_LIST], c11784_5[AutomodTriggerType.KEYWORD]];
c11784_7 = r218;
export { r27 as AutomodTriggerConfigFlags };
export { c11784_5 as triggerConfigs };
export { c11784_6 as AutomodTriggerCategory };
export { c11784_7 as AUTOMOD_RULE_CONFIGS_BY_CATEGORY };
export function checkTriggerTypeForFlag(a0, a1) {
return c11784_5[a0].flags.has(a1);
}
export function getAvailableActionTypes(a0) {
return Array.from(c11784_5[a0].availableActionTypes);
}
export function validateRuleByTriggerConfigOrThrow({ id, eventType, triggerType, actions }, a1) {
const r14 = c11784_5[triggerType];
let c23117_2 = r14;
if (a1.filter((item) => id !== item.id && item.triggerType === triggerType).length > r14.perGuildMaxCount) {
throw new Error(`You have exceeded the maximum number of rules of type ${triggerType}`);
}
if (actions.some((action) => !c23117_2.availableActionTypes.has(action.type))) {
throw new Error("You have provided an action that is not available for this trigger type");
}
if (eventType !== r14.eventType) {
throw new Error("You have provided an event type that is not available for this trigger type");
}
}
export function useAvailableTriggerTypes(a0) {
const isUserProfileRuleEnabled = useIsUserProfileRuleEnabled(a0);
return useMemo(() => {
const r3 = {};
r3[c11784_6.MEMBERS] = [];
r3[c11784_6.CONTENT] = [];
return Object.keys(c11784_7).reduce((acc, a1) => {
acc[a1] = c11784_7[a1].filter((item) => {
let r2 = item.type !== AutomodTriggerType.SERVER_POLICY;
if (r2) {
const r1 = item.type === AutomodTriggerType.USER_PROFILE && !isUserProfileRuleEnabled;
r2 = r1 ? !r1 : item.perGuildMaxCount > 0;
}
return r2;
}).map((item) => item.type);
return acc;
}, r3);
}, [isUserProfileRuleEnabled]);
}
export function getDefaultTriggerMetadataForTriggerType(a0, a1) {
const isInMentionRaidExperiment = _ExperimentUtils.isInMentionRaidExperiment(a1);
if (AutomodTriggerType.DEFAULT_KEYWORD_LIST === a0) {
return {
allowList: [],
presets: []
};
}
if (AutomodTriggerType.USER_PROFILE !== a0 && AutomodTriggerType.KEYWORD !== a0) {
if (AutomodTriggerType.MENTION_SPAM === a0) {
return {
mentionTotalLimit: MENTION_SPAM_LIMIT_DEFAULT,
mentionRaidProtectionEnabled: isInMentionRaidExperiment
};
}
if (AutomodTriggerType.ML_SPAM !== a0) {
AutomodTriggerType.SERVER_POLICY;
}
return void 0;
}
return {
keywordFilter: [],
regexPatterns: [],
allowList: []
};
}