decord/source/modules/guild_automod/AutomodStore.tsx
2026-08-05 07:35:12 +00:00

473 lines
13 KiB
TypeScript

// Module ID: 16477
// Function ID: 16478
// Name: withEqualityFn
// Dependencies: [32, 5, 19, 11146, 676, 700, 16478, 705, 11151, 4154, 3868, 2]
// Exports: getRuleCountByTriggerType, useAutomodRulesList, useSyncAutomodRules, useSyncAutomodRulesEffect
// Module 16477 (withEqualityFn)
import _slicedToArray from "_slicedToArray";
import closure_3 from "identity";
import noop from "noop";
import { AutomodTriggerType } from "AutomodEventType";
import { EMPTY_STRING_SNOWFLAKE_ID } from "ME";
import identity from "identity";
const require = arg1;
let closure_7 = {};
const withEqualityFn = identity.createWithEqualityFn((arg0, arg1) => {
let closure_0 = arg0;
let closure_1 = arg1;
let obj = {
rules: {},
fetching: false,
error: null,
updateRule(guildId) {
let _slicedToArray;
let triggerType;
const callback = guildId;
guildId = guildId.guildId;
({ id: _slicedToArray, triggerType } = guildId);
const rules = guildId().rules;
let obj = rules[guildId];
if (obj == null) {
obj = {};
}
let items = obj[triggerType];
if (items == null) {
items = [];
}
const found = items.filter((id) => {
const isDefaultRuleIdResult = guildId(guildId2[6]).isDefaultRuleId(id.id);
let tmp2 = !isDefaultRuleIdResult;
if (isDefaultRuleIdResult) {
tmp2 = id.triggerType !== triggerType;
}
return tmp2;
});
if (someResult) {
let mapped = found.map((id) => {
let tmp = id;
if (id.id === _slicedToArray) {
tmp = closure_0;
}
return tmp;
});
} else {
mapped = [];
mapped[HermesBuiltin.arraySpread(found, 0)] = guildId;
}
someResult = items.some((id) => id.id === _slicedToArray);
callback(705).batchUpdates(() => {
let obj = { rules: null, error: null };
obj = {};
const merged = Object.assign(rules);
obj = {};
const merged1 = Object.assign(obj);
obj[triggerType] = mapped;
obj[guildId] = obj;
obj[0] = obj;
guildId(obj);
});
},
removeRule(arg0, arg1) {
const callback = arg0;
const dependencyMap = arg1;
const rules = dependencyMap().rules;
let closure_3 = tmp;
const keys = Object.keys(tmp);
let noop = keys.reduce((arg0, arg1) => {
const NumberResult = Number(arg1);
let items = tmp[NumberResult];
if (items == null) {
items = [];
}
arg0[NumberResult] = items.filter((id) => id.id !== closure_0);
return arg0;
}, {});
callback(705).batchUpdates(() => {
let obj = { rules: null, error: null };
obj = {};
const merged = Object.assign(rules);
obj[closure_1] = noop;
obj[0] = obj;
callback(obj);
});
},
syncRules: null
};
let _slicedToArray = callback((arg0) => {
let closure_0 = arg0;
let c6 = 0;
let c7 = 0;
let c4 = 0;
return (function*(arg0) {
if (c7 === 2) {
c7 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
return { value: "T", done: null };
}
} else {
try {
c7 = 2;
if (0 === c6) {
if (arg0 === 1) {
c7 = 3;
throw arg1;
} else if (arg0 === 2) {
c7 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
let aPIError = tmp3;
let rules = tmp7;
let callback2;
rules = undefined;
aPIError = undefined;
if ((function isSyncNeeded(closure_0) {
let num = table[closure_0];
const timestamp = Date.now();
if (num == null) {
num = 0;
}
return timestamp - num > 20000;
})(callback)) {
const _Date = Date;
c7[tmp41] = Date.now();
let c4 = 1;
callback2 = function convertToRulesByTriggerType(arr) {
const obj = { [closure_5.KEYWORD]: [], [closure_5.ML_SPAM]: [], [closure_5.DEFAULT_KEYWORD_LIST]: [], [closure_5.MENTION_SPAM]: [], [closure_5.USER_PROFILE]: [], [closure_5.SERVER_POLICY]: [] };
const item = arr.forEach((arg0) => {
let arr = obj[arg0.triggerType];
if (arr != null) {
arr = arr.push(arg0);
}
});
return obj;
};
c6 = 2;
c7 = 1;
const obj1 = { value: null, done: false };
obj1[0] = callback(outer1_1[8]).fetchAutomodRules(tmp41);
return obj1;
}
}
} else {
if (1 === tmp7) {
c4 = 0;
c4 = closure_5;
aPIError = new callback(outer1_1[9]).APIError(c4);
let obj2 = callback(outer1_1[7]);
obj2.batchUpdates(() => {
callback({ error: aPIError });
});
} else if (arg0 === 1) {
c7 = 3;
throw arg1;
} else if (arg0 !== 2) {
callback2 = callback2(arg1);
rules = callback2().rules;
obj = callback(outer1_1[7]);
obj.batchUpdates(() => {
let obj = { rules: null, error: null };
obj = {};
const merged = Object.assign(rules);
obj[callback] = closure_1;
obj[0] = obj;
callback(obj);
});
c4 = 0;
}
c4 = 0;
c7 = 3;
obj2 = { value: null, done: true };
obj2[0] = arg1;
return obj2;
}
c7 = 3;
} catch (tmp32) {
closure_5 = tmp32;
if (tmp4 === c4) {
c7 = tmp2;
throw tmp32;
} else {
c6 = tmp;
}
}
}
})();
});
obj[5] = function() {
const self = this;
const apply = _slicedToArray.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
};
return obj;
});
const result = require("noop").fileFinishedImporting("modules/guild_automod/AutomodStore.tsx");
export const useAutomodStore = withEqualityFn;
export const getRuleCountByTriggerType = function getRuleCountByTriggerType(arg0, arg1) {
const tmp = withEqualityFn.getState().rules[arg0];
let items;
if (tmp != null) {
items = tmp[arg1];
}
if (items == null) {
items = [];
}
return items.length;
};
export const useSyncAutomodRules = function useSyncAutomodRules(arg0) {
const _require = arg0;
const tmp = first(React.useState(false), 2);
const dependencyMap = tmp[1];
const tmp2 = first(withEqualityFn((arg0) => {
const items = [, ];
({ syncRules: arr[0], fetching: arr[1] } = arg0);
return items;
}, _require(3868).shallow), 2);
first = tmp2[0];
const callback = tmp4;
const items = [tmp[0], ];
const items1 = [arg0, tmp2[1], first];
items[1] = React.useCallback(callback(function*() {
if (c4 === 2) {
c4 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
return { value: "T", done: null };
}
} else {
try {
c4 = 2;
if (0 === v0) {
if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
let closure_0 = tmp3;
if (!c3) {
if (null != outer1_0) {
c3 = 1;
v0(true);
v0 = 2;
c4 = 1;
const obj1 = { value: null, done: false };
obj1[0] = outer1_2(tmp20);
return obj1;
}
}
c4 = 3;
}
} else if (1 === tmp7) {
c3 = 0;
v0(false);
throw _slicedToArray;
} else if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 !== 2) {
c3 = 0;
v0(false);
}
c3 = 0;
v0(false);
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} catch (tmp24) {
_slicedToArray = tmp24;
if (tmp4 === c3) {
c4 = tmp2;
throw tmp24;
} else {
v0 = tmp;
}
}
}
}), items1);
return items;
};
export const useSyncAutomodRulesEffect = function useSyncAutomodRulesEffect(arg0) {
let _require = arg0;
const tmp = first(React.useState(false), 2);
const dependencyMap = tmp[1];
const tmp2 = first(withEqualityFn((arg0) => {
const items = [, ];
({ syncRules: arr[0], fetching: arr[1] } = arg0);
return items;
}, _require(3868).shallow), 2);
first = tmp2[0];
const callback = tmp4;
let items = [tmp[0], ];
const items1 = [arg0, tmp2[1], first];
items[1] = React.useCallback(callback(function*() {
if (c4 === 2) {
c4 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
return { value: "T", done: null };
}
} else {
try {
c4 = 2;
if (0 === v0) {
if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
let closure_0 = tmp3;
if (!c3) {
if (null != outer1_0) {
c3 = 1;
v0(true);
v0 = 2;
c4 = 1;
const obj1 = { value: null, done: false };
obj1[0] = outer1_2(tmp20);
return obj1;
}
}
c4 = 3;
}
} else if (1 === tmp7) {
c3 = 0;
v0(false);
throw _slicedToArray;
} else if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 !== 2) {
c3 = 0;
v0(false);
}
c3 = 0;
v0(false);
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} catch (tmp24) {
_slicedToArray = tmp24;
if (tmp4 === c3) {
c4 = tmp2;
throw tmp24;
} else {
v0 = tmp;
}
}
}
}), items1);
const tmp5 = first(items, 2);
_require = tmp6;
const items2 = [arg0, tmp5[1]];
const effect = React.useEffect(() => {
tmp4(function*() {
if (v0 === 2) {
v0 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp3 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
return { value: "T", done: null };
}
} else {
try {
v0 = 2;
if (0 === c1) {
if (arg0 === 1) {
v0 = 3;
throw arg1;
} else if (arg0 === 2) {
v0 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
c1 = 1;
v0 = 1;
const obj1 = { value: null, done: false };
obj1[0] = v0();
return obj1;
}
} else if (arg0 === 1) {
v0 = 3;
throw arg1;
} else if (arg0 === 2) {
v0 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
v0 = 3;
return { value: "T", done: null };
}
} catch (tmp6) {
v0 = tmp;
throw tmp6;
}
}
})();
}, items2);
const items3 = [tmp5[0], tmp5[1]];
return items3;
};
export const useAutomodRulesList = function useAutomodRulesList(arg0) {
const _require = arg0;
return withEqualityFn((updateRule) => {
let tmp = closure_0;
if (closure_0 == null) {
tmp = outer1_6;
}
let obj = updateRule.rules[tmp];
if (obj == null) {
obj = {};
}
obj = { rulesByTriggerType: obj, updateRule: updateRule.updateRule, removeRule: updateRule.removeRule };
return obj;
}, _require(3868).shallow);
};