decord/source/modules/guild_automod/AutomodStore.tsx

454 lines
13 KiB
TypeScript
Raw Normal View History

// Module ID: 17634
// Function ID: 17635
// Name: AutomodStore
// Dependencies: [32, 5, 19, 11933, 1074, 1244, 17635, 1249, 11938, 4506, 4227, 2]
2026-07-29 08:29:29 +00:00
// Exports: getRuleCountByTriggerType, useAutomodRulesList, useSyncAutomodRules, useSyncAutomodRulesEffect
2026-07-20 16:05:17 +00:00
// Module 17634 (AutomodStore)
import _mod4227 from "module_4227" /* 4227 */;
import SystemRulesUtils from "SystemRulesUtils" /* 17635 */;
import _slicedToArray from "module_32" /* 32 */;
import asyncGeneratorStep from "asyncGeneratorStep" /* 5 */;
import noop from "module_19" /* 19 */;
2026-07-23 10:11:24 +00:00
const require = globalThis.__r;
require = fn;
const AutomodTriggerType = fn(11933).AutomodTriggerType;
const EMPTY_STRING_SNOWFLAKE_ID = fn(1074).EMPTY_STRING_SNOWFLAKE_ID;
2026-07-20 16:05:17 +00:00
let closure_7 = {};
const identity = fn(1244);
2026-07-29 08:29:29 +00:00
const withEqualityFn = identity.createWithEqualityFn((arg0, arg1) => {
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
dependencyMap = arg1;
2026-07-23 10:11:24 +00:00
let obj = {
2026-07-20 16:05:17 +00:00
rules: {},
2026-07-23 10:11:24 +00:00
fetching: false,
error: null,
2026-07-20 16:05:17 +00:00
updateRule(guildId) {
guildId = guildId.guildId;
2026-08-24 06:08:38 +00:00
({ id: closure_2, triggerType } = guildId);
2026-07-23 10:11:24 +00:00
const rules = guildId().rules;
2026-07-20 16:05:17 +00:00
let obj = rules[guildId];
2026-07-29 08:29:29 +00:00
if (obj == null) {
2026-07-20 16:05:17 +00:00
obj = {};
}
let items = obj[triggerType];
2026-07-29 08:29:29 +00:00
if (items == null) {
2026-07-20 16:05:17 +00:00
items = [];
}
const found = items.filter((id) => {
const isDefaultRuleIdResult = SystemRulesUtils.isDefaultRuleId(id.id);
2026-07-29 08:29:29 +00:00
let tmp2 = !isDefaultRuleIdResult;
if (isDefaultRuleIdResult) {
tmp2 = id.triggerType !== triggerType;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp2;
2026-07-20 16:05:17 +00:00
});
if (someResult) {
let mapped = found.map((id) => {
let tmp = id;
if (id.id === closure_1_2) {
2026-07-23 10:11:24 +00:00
tmp = closure_0;
2026-07-20 16:05:17 +00:00
}
return tmp;
});
} else {
mapped = [];
2026-07-29 08:29:29 +00:00
mapped[HermesBuiltin.arraySpread(found, 0)] = guildId;
2026-07-20 16:05:17 +00:00
}
someResult = items.some((id) => id.id === closure_1_2);
guildId(1249).batchUpdates(() => {
2026-08-24 06:08:38 +00:00
obj = { rules: null, error: null };
const obj2 = {};
2026-07-20 16:05:17 +00:00
const merged = Object.assign(rules);
const obj3 = {};
2026-07-20 16:05:17 +00:00
const merged1 = Object.assign(obj);
obj3[triggerType] = mapped;
obj2[guildId] = obj3;
obj.rules = obj2;
2026-07-23 10:11:24 +00:00
guildId(obj);
2026-07-20 16:05:17 +00:00
});
2026-07-29 08:29:29 +00:00
},
removeRule(arg0, arg1) {
closure_0 = arg0;
2026-08-24 06:08:38 +00:00
dependencyMap = arg1;
2026-07-29 08:29:29 +00:00
const rules = dependencyMap().rules;
2026-08-24 06:08:38 +00:00
closure_3 = tmp;
2026-07-29 08:29:29 +00:00
const keys = Object.keys(tmp);
closure_4 = keys.reduce((acc, item) => {
const NumberResult = Number(item);
let items = closure_3[NumberResult];
2026-07-29 08:29:29 +00:00
if (items == null) {
items = [];
}
acc[NumberResult] = items.filter((id) => id.id !== closure_1_0);
return acc;
2026-07-29 08:29:29 +00:00
}, {});
closure_0(1249).batchUpdates(() => {
const obj = { rules: null, error: null };
const obj2 = {};
2026-07-29 08:29:29 +00:00
const merged = Object.assign(rules);
obj2[closure_1] = closure_4;
obj.rules = obj2;
closure_0(obj);
2026-07-29 08:29:29 +00:00
});
},
syncRules: null
2026-07-20 16:05:17 +00:00
};
closure_2 = asyncGeneratorStep(async (arg0, value) => {
if (c7 === 2) {
c7 = 3;
throw new TypeError("Generator functions may not be called on executing generators");
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw value;
} else if (arg0 === 2) {
let obj2 = { value, done: true };
return obj2;
2026-07-29 08:29:29 +00:00
} else {
return { value: "HermesInternal", done: null };
}
} else {
try {
c7 = 2;
if (0 === c6) {
if (arg0 === 1) {
c7 = 3;
throw value;
} else if (arg0 === 2) {
c7 = 3;
const obj5 = { value, done: true };
return obj5;
2026-07-29 08:29:29 +00:00
} else {
const error = tmp3;
closure_2 = tmp7;
closure_130_0 = closure_0;
closure_130_1 = undefined;
let rules;
closure_130_3 = undefined;
if ((function isSyncNeeded(arg0) {
let num = closure_1_7[arg0];
const timestamp = Date.now();
if (num == null) {
num = 0;
}
return timestamp - num > 20000;
})(closure_0)) {
const _Date = Date;
c7[tmp40] = Date.now();
c4 = 1;
function convertToRulesByTriggerType(arr) {
const obj = { [closure_1_5.KEYWORD]: [], [closure_1_5.ML_SPAM]: [], [closure_1_5.DEFAULT_KEYWORD_LIST]: [], [closure_1_5.MENTION_SPAM]: [], [closure_1_5.USER_PROFILE]: [], [closure_1_5.SERVER_POLICY]: [] };
const item = arr.forEach((item) => {
if (obj[item.triggerType] != null) {
arr.push(item);
}
});
return obj;
}
c6 = 2;
c7 = 1;
const obj6 = { value: closure_0(convertToRulesByTriggerType[8]).fetchAutomodRules(tmp40), done: false };
return obj6;
2026-07-29 08:29:29 +00:00
}
}
} else {
if (1 === tmp7) {
2026-07-29 08:29:29 +00:00
c4 = 0;
closure_130_4 = closure_5;
const aPIError = new closure_0(convertToRulesByTriggerType[9]).APIError(closure_130_4);
closure_130_3 = aPIError;
closure_0(convertToRulesByTriggerType[7]).batchUpdates(() => {
closure_0({ error });
});
const obj3 = closure_0(convertToRulesByTriggerType[7]);
} else if (arg0 === 1) {
2026-07-29 08:29:29 +00:00
c7 = 3;
throw value;
} else if (arg0 !== 2) {
closure_130_1 = convertToRulesByTriggerType(value);
rules = closure_131_1().rules;
closure_0(convertToRulesByTriggerType[7]).batchUpdates(() => {
const obj = { rules: null, error: null };
const obj2 = {};
const merged = Object.assign(closure_1_2);
obj2[closure_1_0] = convertToRulesByTriggerType;
obj.rules = obj2;
closure_0(obj);
});
c4 = 0;
let obj = closure_0(convertToRulesByTriggerType[7]);
2026-07-29 08:29:29 +00:00
}
c4 = 0;
2026-07-29 08:29:29 +00:00
c7 = 3;
const obj7 = { value, done: true };
return obj7;
}
c7 = 3;
} catch (tmp32) {
closure_5 = tmp32;
if (tmp4 === c4) {
c7 = tmp2;
throw tmp32;
} else {
c6 = tmp;
2026-07-29 08:29:29 +00:00
}
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
});
obj.syncRules = function() {
2026-07-29 08:29:29 +00:00
const self = this;
2026-08-24 06:08:38 +00:00
const apply = closure_2.apply;
2026-07-29 08:29:29 +00:00
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
};
return obj;
});
const size = fn(2);
const result = size.fileFinishedImporting("modules/guild_automod/AutomodStore.tsx");
2026-07-20 16:05:17 +00:00
export const useAutomodStore = withEqualityFn;
export const getRuleCountByTriggerType = function getRuleCountByTriggerType(guildId, triggerType) {
const tmp = withEqualityFn.getState().rules[guildId];
2026-07-20 16:05:17 +00:00
let items;
2026-07-29 08:29:29 +00:00
if (tmp != null) {
items = tmp[triggerType];
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (items == null) {
2026-07-20 16:05:17 +00:00
items = [];
}
return items.length;
};
2026-07-29 08:29:29 +00:00
export const useSyncAutomodRules = function useSyncAutomodRules(arg0) {
closure_0 = arg0;
const tmp = _slicedToArray(noop.useState(false), 2);
closure_1 = tmp[1];
const tmp2 = _slicedToArray(withEqualityFn((arg0) => {
2026-07-29 08:29:29 +00:00
const items = [, ];
({ syncRules: arr[0], fetching: arr[1] } = arg0);
return items;
}, _mod4227.shallow), 2);
const first = tmp2[0];
closure_3 = tmp4;
2026-07-29 08:29:29 +00:00
const items = [tmp[0], ];
const items1 = [arg0, tmp2[1], first];
items[1] = noop.useCallback(asyncGeneratorStep(async (arg0, value) => {
2026-07-29 08:29:29 +00:00
if (c4 === 2) {
c4 = 3;
throw new TypeError("Generator functions may not be called on executing generators");
2026-07-29 08:29:29 +00:00
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
const obj2 = { value, done: true };
return obj2;
2026-07-29 08:29:29 +00:00
} else {
2026-09-01 10:26:29 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} else {
try {
c4 = 2;
if (0 === c1) {
2026-07-29 08:29:29 +00:00
if (arg0 === 1) {
c4 = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
c4 = 3;
const obj3 = { value, done: true };
return obj3;
2026-07-29 08:29:29 +00:00
} else {
2026-08-24 06:08:38 +00:00
closure_0 = tmp3;
if (!closure_3) {
if (null != closure_0) {
2026-07-29 08:29:29 +00:00
c3 = 1;
v2(true);
c1 = 2;
2026-07-29 08:29:29 +00:00
c4 = 1;
const obj4 = { value: first(tmp20), done: false };
return obj4;
2026-07-29 08:29:29 +00:00
}
}
c4 = 3;
}
} else if (1 === tmp7) {
c3 = 0;
closure_128_1(false);
2026-08-24 06:08:38 +00:00
throw closure_2;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 1) {
c4 = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 !== 2) {
c3 = 0;
closure_128_1(false);
2026-07-29 08:29:29 +00:00
}
c3 = 0;
closure_128_1(false);
2026-07-29 08:29:29 +00:00
c4 = 3;
const obj = { value, done: true };
2026-07-29 08:29:29 +00:00
return obj;
} catch (tmp24) {
2026-08-24 06:08:38 +00:00
closure_2 = tmp24;
2026-07-29 08:29:29 +00:00
if (tmp4 === c3) {
c4 = tmp2;
throw tmp24;
} else {
c1 = tmp;
2026-07-29 08:29:29 +00:00
}
}
}
}), items1);
return items;
};
2026-07-20 16:05:17 +00:00
export const useSyncAutomodRulesEffect = function useSyncAutomodRulesEffect(arg0) {
_require = arg0;
const tmp = first(noop.useState(false), 2);
2026-08-24 06:08:38 +00:00
dependencyMap = tmp[1];
2026-07-29 08:29:29 +00:00
const tmp2 = first(withEqualityFn((arg0) => {
const items = [, ];
({ syncRules: arr[0], fetching: arr[1] } = arg0);
return items;
}, require("module_4227").shallow), 2);
2026-07-29 08:29:29 +00:00
first = tmp2[0];
asyncGeneratorStep = tmp4;
2026-07-29 08:29:29 +00:00
let items = [tmp[0], ];
const items1 = [arg0, tmp2[1], first];
items[1] = noop.useCallback(asyncGeneratorStep(async (arg0, value) => {
2026-07-29 08:29:29 +00:00
if (c4 === 2) {
c4 = 3;
throw new TypeError("Generator functions may not be called on executing generators");
2026-07-29 08:29:29 +00:00
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
const obj2 = { value, done: true };
return obj2;
2026-07-29 08:29:29 +00:00
} else {
2026-09-01 10:26:29 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} else {
try {
c4 = 2;
if (0 === c1) {
2026-07-29 08:29:29 +00:00
if (arg0 === 1) {
c4 = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
c4 = 3;
const obj3 = { value, done: true };
return obj3;
2026-07-29 08:29:29 +00:00
} else {
2026-08-24 06:08:38 +00:00
closure_0 = tmp3;
if (!closure_3) {
if (null != closure_0) {
2026-07-29 08:29:29 +00:00
c3 = 1;
v2(true);
c1 = 2;
2026-07-29 08:29:29 +00:00
c4 = 1;
const obj4 = { value: first(tmp20), done: false };
return obj4;
2026-07-29 08:29:29 +00:00
}
}
c4 = 3;
}
} else if (1 === tmp7) {
c3 = 0;
closure_128_1(false);
2026-08-24 06:08:38 +00:00
throw closure_2;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 1) {
c4 = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 !== 2) {
c3 = 0;
closure_128_1(false);
2026-07-29 08:29:29 +00:00
}
c3 = 0;
closure_128_1(false);
2026-07-29 08:29:29 +00:00
c4 = 3;
const obj = { value, done: true };
2026-07-29 08:29:29 +00:00
return obj;
} catch (tmp24) {
2026-08-24 06:08:38 +00:00
closure_2 = tmp24;
2026-07-29 08:29:29 +00:00
if (tmp4 === c3) {
c4 = tmp2;
throw tmp24;
} else {
c1 = tmp;
2026-07-29 08:29:29 +00:00
}
}
}
}), items1);
const tmp5 = first(items, 2);
_require = tmp6;
const items2 = [arg0, tmp5[1]];
const effect = noop.useEffect(() => {
(async (arg0, value) => {
if (c0 === 2) {
c0 = 3;
throw new TypeError("Generator functions may not be called on executing generators");
2026-07-29 08:29:29 +00:00
} else if (tmp3 === 3) {
if (arg0 === 1) {
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
const obj2 = { value, done: true };
return obj2;
2026-07-29 08:29:29 +00:00
} else {
2026-09-01 10:26:29 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} else {
try {
c0 = 2;
2026-07-29 08:29:29 +00:00
if (0 === c1) {
if (arg0 === 1) {
c0 = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
c0 = 3;
const obj3 = { value, done: true };
return obj3;
2026-07-29 08:29:29 +00:00
} else {
c1 = 1;
c0 = 1;
const obj4 = { value: closure_2_0(), done: false };
return obj4;
2026-07-29 08:29:29 +00:00
}
} else if (arg0 === 1) {
c0 = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
c0 = 3;
const obj = { value, done: true };
2026-07-29 08:29:29 +00:00
return obj;
} else {
c0 = 3;
2026-09-01 10:26:29 +00:00
return { value: "HermesInternal", done: null };
2026-07-29 08:29:29 +00:00
}
} catch (tmp6) {
c0 = tmp;
2026-07-29 08:29:29 +00:00
throw tmp6;
}
}
})();
}, items2);
const items3 = [tmp5[0], tmp5[1]];
return items3;
2026-07-20 16:05:17 +00:00
};
export const useAutomodRulesList = function useAutomodRulesList(arg0) {
_require = arg0;
2026-07-29 08:29:29 +00:00
return withEqualityFn((updateRule) => {
let tmp = closure_0;
if (closure_0 == null) {
tmp = EMPTY_STRING_SNOWFLAKE_ID;
2026-07-29 08:29:29 +00:00
}
let obj = updateRule.rules[tmp];
if (obj == null) {
2026-07-20 16:05:17 +00:00
obj = {};
}
return { rulesByTriggerType: obj, updateRule: updateRule.updateRule, removeRule: updateRule.removeRule };
}, require("module_4227").shallow);
2026-07-20 16:05:17 +00:00
};