decord/source/modules/application_commands/CommandPermissionContext.tsx

244 lines
8.8 KiB
TypeScript
Raw Normal View History

2026-08-24 06:08:38 +00:00
// Module ID: 8492
// Function ID: 8493
2026-07-29 08:29:29 +00:00
// Name: computePermissions
2026-08-24 06:08:38 +00:00
// Dependencies: [19, 1983, 1395, 1434, 1218, 1391, 1991, 1910, 4024, 1922, 676, 8493, 589, 506, 1954, 2]
2026-07-29 08:29:29 +00:00
// Exports: buildPermissionContext, computeCommandContextType, getContextGuildId, usePermissionContext
2026-07-20 16:05:17 +00:00
2026-08-24 06:08:38 +00:00
// Module 8492 (computePermissions)
import fromStringAll from "fromString" /* 506 */;
import PermissionOverwriteType from "PermissionOverwriteType" /* 1954 */;
import resolveNsfwTogglesWithDefaults from "resolveNsfwTogglesWithDefaults" /* 8493 */;
import closure_3 from "noop" /* 19 */;
import closure_4 from "initialize" /* 1983 */;
import { ChannelRecordBase } from "createChannelRecord" /* 1395 */;
import { isGuildNSFW } from "GuildNSFWContentLevel" /* 1434 */;
import closure_7 from "fetchFingerprint" /* 1218 */;
import closure_8 from "ensureGuildLoaded" /* 1391 */;
import closure_9 from "trackCommunicationDisabled" /* 1991 */;
import closure_10 from "createGuildRecordFromRust" /* 1910 */;
import closure_11 from "getUncachedChannelPermissions" /* 4024 */;
import closure_12 from "mergeGuildAvatar" /* 1922 */;
import ME from "ME" /* 676 */;
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
require = arg1;
2026-07-20 16:05:17 +00:00
function computePermissions(isPrivate) {
if (!(isPrivate instanceof ChannelRecordBase)) {
if (null != isPrivate) {
2026-08-24 06:08:38 +00:00
const permissions = closure_11.computePermissions(isPrivate);
2026-07-29 08:29:29 +00:00
let SEND_MESSAGES_IN_THREADS = constants2;
2026-07-20 16:05:17 +00:00
let flag = true;
let flag2 = true;
if (!obj6.has(permissions, constants2.ADMINISTRATOR)) {
2026-07-29 08:29:29 +00:00
let tmp13Result = tmp13(506);
const hasItem = tmp13Result.has(permissions, SEND_MESSAGES_IN_THREADS.VIEW_CHANNEL);
2026-07-20 16:05:17 +00:00
if (tmp3) {
let hasItem1 = hasItem;
if (hasItem) {
2026-07-29 08:29:29 +00:00
tmp13Result = tmp13(506);
hasItem1 = tmp13Result.has(permissions, SEND_MESSAGES_IN_THREADS.USE_APPLICATION_COMMANDS);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const has = tmp13(506).has;
2026-07-20 16:05:17 +00:00
if (arg1) {
SEND_MESSAGES_IN_THREADS = SEND_MESSAGES_IN_THREADS.SEND_MESSAGES_IN_THREADS;
let hasItem2 = has(permissions, SEND_MESSAGES_IN_THREADS);
} else {
hasItem2 = has(permissions, SEND_MESSAGES_IN_THREADS.SEND_MESSAGES);
}
2026-07-29 08:29:29 +00:00
const tmp13Result1 = tmp13(506);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
flag = true;
flag2 = hasItem;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
tmp3 = isPrivate instanceof tmp;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let obj = { computedPermissions: null, hasBaseAccessPermissions: null, hasSendMessagesPermission: null };
obj[0] = permissions;
obj[1] = flag2;
obj[2] = flag;
2026-07-20 16:05:17 +00:00
return obj;
}
}
2026-08-24 06:08:38 +00:00
obj = { computedPermissions: fromStringAll.deserialize(0), hasBaseAccessPermissions: true, hasSendMessagesPermission: true };
2026-07-20 16:05:17 +00:00
return obj;
}
2026-07-29 08:29:29 +00:00
({ ChannelTypes: map1, Permissions: closure_14 } = ME);
2026-08-24 06:08:38 +00:00
const result = require("set").fileFinishedImporting("modules/application_commands/CommandPermissionContext.tsx");
2026-07-20 16:05:17 +00:00
export const buildPermissionContext = function buildPermissionContext(channel, items) {
2026-07-29 08:29:29 +00:00
let obj = channel;
2026-07-20 16:05:17 +00:00
if (channel instanceof ChannelRecordBase) {
2026-07-29 08:29:29 +00:00
obj = channel;
2026-07-20 16:05:17 +00:00
if (channel.isThread()) {
channel = channel.getChannel(channel.parent_id);
2026-07-29 08:29:29 +00:00
obj = channel;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
if (null == obj) {
2026-08-24 06:08:38 +00:00
let viewNsfwCommandsOrDefault = resolveNsfwTogglesWithDefaults.getViewNsfwCommandsOrDefault();
2026-07-29 08:29:29 +00:00
id = id.getId();
currentUser = currentUser.getCurrentUser();
let flag;
if (currentUser != null) {
flag = currentUser.nsfwAllowed;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (flag == null) {
flag = false;
}
if (null != undefined) {
member = member.getMember(undefined, id);
let roles;
if (member != null) {
roles = member.roles;
}
if (roles == null) {
roles = [];
}
items = roles;
} else {
items = [];
}
let isThreadResult = channel instanceof tmp;
2026-08-24 06:08:38 +00:00
const obj2 = resolveNsfwTogglesWithDefaults;
2026-07-29 08:29:29 +00:00
if (isThreadResult) {
isThreadResult = channel.isThread();
}
const isViewingRolesResult = viewingRoles.isViewingRoles(undefined);
const tmp17 = computePermissions;
obj = { context: null, userId: null, roleIds: null, isImpersonating: null, commandTypes: null, computedPermissions: null, hasBaseAccessPermissions: null, hasSendMessagesPermission: null, allowNsfw: null };
obj[0] = obj;
obj[1] = id;
obj[2] = items;
obj[3] = isViewingRolesResult;
obj[4] = items;
({ computedPermissions: obj3[5], hasBaseAccessPermissions: obj3[6], hasSendMessagesPermission: obj3[7] } = computePermissions(obj, isThreadResult));
let tmp24 = flag;
if (tmp24) {
let tmp25 = !(obj instanceof tmp);
if (!tmp25) {
if (null != obj.guild_id) {
viewNsfwCommandsOrDefault = obj.isNSFW() || tmp23;
const tmp26 = obj.isNSFW() || tmp23;
}
tmp25 = viewNsfwCommandsOrDefault;
}
tmp24 = tmp25;
}
obj[8] = tmp24;
return obj;
2026-07-20 16:05:17 +00:00
}
};
export const usePermissionContext = function usePermissionContext(channel, items) {
2026-07-23 10:11:24 +00:00
const _require = channel;
2026-08-24 06:08:38 +00:00
closure_1 = items;
2026-07-20 16:05:17 +00:00
items = [channel];
2026-07-23 10:11:24 +00:00
const memo = React.useMemo(() => {
2026-07-29 08:29:29 +00:00
let tmp = closure_0;
if (closure_0 instanceof stateFromStoresArray) {
tmp = obj;
if (obj.isThread()) {
2026-08-24 06:08:38 +00:00
channel = closure_1_8.getChannel(obj.parent_id);
2026-07-29 08:29:29 +00:00
if (channel == null) {
channel = obj;
}
tmp = channel;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
return tmp;
2026-07-20 16:05:17 +00:00
}, items);
2026-07-29 08:29:29 +00:00
if (null == memo) {
React = undefined;
let viewNsfwCommandsOrDefault = _require(memo[11]).useViewNsfwCommandsOrDefault();
const obj3 = _require(memo[11]);
2026-08-24 06:08:38 +00:00
const items1 = [viewNsfwCommandsOrDefault];
const stateFromStores = _require(memo[12]).useStateFromStores(items1, () => viewNsfwCommandsOrDefault.getId());
2026-07-29 08:29:29 +00:00
const obj4 = _require(memo[12]);
2026-08-24 06:08:38 +00:00
const items2 = [closure_12];
2026-07-29 08:29:29 +00:00
const stateFromStores1 = _require(memo[12]).useStateFromStores(items2, () => {
currentUser = currentUser.getCurrentUser();
let flag;
if (currentUser != null) {
flag = currentUser.nsfwAllowed;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (flag == null) {
flag = false;
}
return flag;
});
const obj5 = _require(memo[12]);
2026-08-24 06:08:38 +00:00
const items3 = [closure_9];
2026-07-29 08:29:29 +00:00
const stateFromStoresArray = _require(memo[12]).useStateFromStoresArray(items3, () => {
if (null != c3) {
2026-08-24 06:08:38 +00:00
const member = closure_1_9.getMember(tmp, stateFromStores);
2026-07-29 08:29:29 +00:00
let roles;
if (member != null) {
roles = member.roles;
}
if (roles == null) {
roles = [];
}
2026-08-24 06:08:38 +00:00
items = roles;
2026-07-29 08:29:29 +00:00
} else {
items = [];
}
return items;
});
const obj6 = _require(memo[12]);
const items4 = [stateFromStores];
const stateFromStores2 = _require(memo[12]).useStateFromStores(items4, () => stateFromStores.isViewingRoles(c3));
_require(memo[12]);
2026-08-24 06:08:38 +00:00
const items5 = [closure_10];
2026-07-29 08:29:29 +00:00
const items6 = [undefined];
let tmp17 = stateFromStores1;
if (tmp17) {
let tmp19 = !(memo instanceof stateFromStoresArray);
if (!tmp19) {
if (null != memo.guild_id) {
viewNsfwCommandsOrDefault = memo.isNSFW() || tmp16;
const tmp20 = memo.isNSFW() || tmp16;
}
tmp19 = viewNsfwCommandsOrDefault;
}
tmp17 = tmp19;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
viewNsfwCommandsOrDefault = tmp17;
2026-07-29 08:29:29 +00:00
const items7 = [items, memo, stateFromStores2, stateFromStoresArray, stateFromStores, tmp17, channel];
return React.useMemo(() => {
let obj = closure_0;
let isThreadResult = closure_0 instanceof stateFromStoresArray;
if (isThreadResult) {
isThreadResult = obj.isThread();
}
2026-08-24 06:08:38 +00:00
const tmpResult = closure_1_15(memo, isThreadResult);
obj = { context: tmp2, userId: stateFromStores, roleIds: stateFromStoresArray, commandTypes: closure_1, isImpersonating: stateFromStores2, computedPermissions: tmpResult.computedPermissions, hasBaseAccessPermissions: tmpResult.hasBaseAccessPermissions, hasSendMessagesPermission: tmpResult.hasSendMessagesPermission, allowNsfw: viewNsfwCommandsOrDefault };
2026-07-29 08:29:29 +00:00
return obj;
}, items7);
}
2026-07-20 16:05:17 +00:00
};
export const computeCommandContextType = function computeCommandContextType(channel, applicationId) {
if (channel instanceof ChannelRecordBase) {
let guild_id;
2026-07-29 08:29:29 +00:00
if (channel != null) {
2026-07-20 16:05:17 +00:00
guild_id = channel.guild_id;
}
if (null == guild_id) {
let type;
2026-07-29 08:29:29 +00:00
if (channel != null) {
2026-07-20 16:05:17 +00:00
type = channel.type;
}
if (type !== constants.DM) {
2026-08-24 06:08:38 +00:00
const PRIVATE_CHANNEL = PermissionOverwriteType.InteractionContextType.PRIVATE_CHANNEL;
2026-07-20 16:05:17 +00:00
} else {
let recipientId;
2026-07-29 08:29:29 +00:00
if (channel != null) {
2026-07-20 16:05:17 +00:00
recipientId = channel.getRecipientId();
}
}
2026-08-24 06:08:38 +00:00
const BOT_DM = PermissionOverwriteType.InteractionContextType.BOT_DM;
2026-07-20 16:05:17 +00:00
}
}
2026-08-24 06:08:38 +00:00
return PermissionOverwriteType.InteractionContextType.GUILD;
2026-07-29 08:29:29 +00:00
};
export const getContextGuildId = function getContextGuildId(context) {
return context instanceof ChannelRecordBase ? context.guild_id : context.id;
2026-07-20 16:05:17 +00:00
};