244 lines
9.5 KiB
TypeScript
244 lines
9.5 KiB
TypeScript
// Module ID: 8362
|
|
// Function ID: 8363
|
|
// Name: computeAllowedForUser
|
|
// Dependencies: [1395, 1910, 4904, 676, 8363, 8083, 7201, 1955, 506, 8365, 38, 7199, 7200, 2]
|
|
// Exports: computeAllowedForChannel, hasAccess
|
|
|
|
// Module 8362 (computeAllowedForUser)
|
|
import set from "set" /* 2 */;
|
|
import _modDef38 from "module_38" /* 38 */;
|
|
import fromStringAll from "fromString" /* 506 */;
|
|
import ME from "ME" /* 676 */;
|
|
import createChannelRecord from "createChannelRecord" /* 1395 */;
|
|
import TRUE_OPTION_NAME from "TRUE_OPTION_NAME" /* 4904 */;
|
|
import buildCommand from "buildCommand" /* 7199 */;
|
|
import commandPermissions from "commandPermissions" /* 7200 */;
|
|
import ApplicationCommandSectionType from "ApplicationCommandSectionType" /* 7201 */;
|
|
import computePermissions from "computePermissions" /* 8083 */;
|
|
import ApplicationIntegrationType from "ApplicationIntegrationType" /* 8365 */;
|
|
import closure_5 from "createGuildRecordFromRust" /* 1910 */;
|
|
|
|
function computeAllowedForUser(permissions, guild_id, userId, roleIds, isImpersonating) {
|
|
if (null == permissions) {
|
|
return null;
|
|
} else {
|
|
if (!isImpersonating) {
|
|
obj = commandPermissions;
|
|
const tmp4 = permissions[obj.toPermissionKey(obj, userId, ApplicationCommandSectionType.ApplicationCommandPermissionType.USER)];
|
|
if (null != tmp4) {
|
|
return tmp4.permission;
|
|
}
|
|
}
|
|
let flag2 = false;
|
|
const obj2 = roleIds[Symbol.iterator]();
|
|
while (obj2 !== undefined) {
|
|
let tmp10 = require;
|
|
let tmp11 = dependencyMap;
|
|
let obj3 = commandPermissions;
|
|
let tmp12 = permissions[obj3.toPermissionKey(obj3, tmp8, ApplicationCommandSectionType.ApplicationCommandPermissionType.ROLE)];
|
|
if (null != tmp12) {
|
|
let tmp14 = tmp12;
|
|
if (tmp13.permission) {
|
|
let tmp15 = obj2;
|
|
obj2.return();
|
|
return true;
|
|
} else {
|
|
flag2 = true;
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
if (flag2) {
|
|
return false;
|
|
} else {
|
|
let tmp17 = null;
|
|
if (null != guild_id) {
|
|
const obj4 = commandPermissions;
|
|
tmp17 = permissions[obj4.toPermissionKey(obj4, guild_id, ApplicationCommandSectionType.ApplicationCommandPermissionType.ROLE)];
|
|
}
|
|
let permission = null;
|
|
if (null != tmp17) {
|
|
permission = tmp17.permission;
|
|
}
|
|
return permission;
|
|
}
|
|
}
|
|
}
|
|
const ChannelRecordBase = createChannelRecord.ChannelRecordBase;
|
|
const BuiltInSectionId = TRUE_OPTION_NAME.BuiltInSectionId;
|
|
const Permissions = ME.Permissions;
|
|
let obj = { ALLOWED: 0, [0]: "ALLOWED", NSFW_NOT_ALLOWED: 1, [1]: "NSFW_NOT_ALLOWED", WRONG_COMMAND_TYPE: 2, [2]: "WRONG_COMMAND_TYPE", PREDICATE_FAILED: 3, [3]: "PREDICATE_FAILED", CONTEXT_NOT_ALLOWED: 4, [4]: "CONTEXT_NOT_ALLOWED", MISSING_BASE_PERMISSIONS: 5, [5]: "MISSING_BASE_PERMISSIONS", CHANNEL_DENIED: 6, [6]: "CHANNEL_DENIED", USER_DENIED: 7, [7]: "USER_DENIED" };
|
|
const result = set.fileFinishedImporting("modules/application_commands/CommandPermissionUtils.tsx");
|
|
|
|
export const HasAccessResult = obj;
|
|
export const hasAccess = function hasAccess(type, arg1, applicationAllowedForChannel) {
|
|
({ context, commandTypes, computedPermissions, userId, roleIds, isImpersonating } = arg1);
|
|
applicationAllowedForChannel = applicationAllowedForChannel.applicationAllowedForChannel;
|
|
({ allowNsfw, hasBaseAccessPermissions, hasSendMessagesPermission } = arg1);
|
|
({ applicationAllowedForUser, isGuildInstalled, isUserInstalled, commandBotId } = applicationAllowedForChannel);
|
|
if (commandTypes.includes(type.type)) {
|
|
if (type.nsfw) {
|
|
if (!allowNsfw) {
|
|
return obj.NSFW_NOT_ALLOWED;
|
|
}
|
|
}
|
|
if (null != context) {
|
|
obj = computePermissions;
|
|
const commandContextType = obj.computeCommandContextType(context, commandBotId);
|
|
}
|
|
if (null != type.contexts) {
|
|
if (null != commandContextType) {
|
|
const contexts = type.contexts;
|
|
if (!contexts.includes(commandContextType)) {
|
|
return obj.CONTEXT_NOT_ALLOWED;
|
|
}
|
|
}
|
|
} else if (type.inputType === ApplicationCommandSectionType.ApplicationCommandInputType.BOT) {
|
|
if (false === type.dmPermission) {
|
|
if (commandContextType === tmp51(1955).InteractionContextType.BOT_DM) {
|
|
return obj.CONTEXT_NOT_ALLOWED;
|
|
}
|
|
}
|
|
if (commandContextType === tmp51(1955).InteractionContextType.PRIVATE_CHANNEL) {
|
|
return obj.CONTEXT_NOT_ALLOWED;
|
|
}
|
|
}
|
|
if (null != type.predicate) {
|
|
if (context instanceof ChannelRecordBase) {
|
|
obj = { channel: null, guild: null };
|
|
obj[0] = context;
|
|
obj[1] = guild.getGuild(context.guild_id);
|
|
if (!type.predicate(obj)) {
|
|
return obj.PREDICATE_FAILED;
|
|
}
|
|
}
|
|
}
|
|
if (type.applicationId === BuiltInSectionId.BUILT_IN) {
|
|
return obj.ALLOWED;
|
|
} else {
|
|
let contextGuildId;
|
|
if (null != context) {
|
|
contextGuildId = computePermissions.getContextGuildId(context);
|
|
const obj3 = computePermissions;
|
|
}
|
|
if (null == contextGuildId) {
|
|
return obj.ALLOWED;
|
|
} else {
|
|
if (obj9.has(computedPermissions, Permissions.ADMINISTRATOR)) {
|
|
return obj.ALLOWED;
|
|
} else {
|
|
if (isUserInstalled) {
|
|
const integration_types = type.integration_types;
|
|
let hasItem;
|
|
if (integration_types != null) {
|
|
hasItem = integration_types.includes(ApplicationIntegrationType.ApplicationIntegrationType.USER_INSTALL);
|
|
}
|
|
if (hasItem) {
|
|
return obj.ALLOWED;
|
|
}
|
|
}
|
|
if (!hasBaseAccessPermissions) {
|
|
if (isGuildInstalled) {
|
|
if (null != type.integration_types) {
|
|
const integration_types2 = type.integration_types;
|
|
}
|
|
return obj.MISSING_BASE_PERMISSIONS;
|
|
}
|
|
}
|
|
if (context instanceof ChannelRecordBase) {
|
|
_modDef38(undefined !== applicationAllowedForChannel, "missing applicationAllowedForChannel");
|
|
const permissions = type.permissions;
|
|
let permission = null;
|
|
if (null != permissions) {
|
|
let id = context.id;
|
|
if (context.isThread()) {
|
|
let id2 = context.parent_id;
|
|
if (id2 == null) {
|
|
id2 = context.id;
|
|
}
|
|
id = id2;
|
|
}
|
|
const obj4 = commandPermissions;
|
|
const tmp28 = permissions[obj4.toPermissionKey(obj4, id, ApplicationCommandSectionType.ApplicationCommandPermissionType.CHANNEL)];
|
|
if (null != tmp28) {
|
|
permission = tmp28.permission;
|
|
} else {
|
|
let tmp27Result = tmp27(7200);
|
|
tmp27Result = tmp27(7199);
|
|
const tmp30 = permissions[tmp27Result.toPermissionKey(tmp27Result, tmp27Result.allChannelsSentinel(contextGuildId), tmp27(undefined, 7201).ApplicationCommandPermissionType.CHANNEL)];
|
|
let permission1 = null;
|
|
if (null != tmp30) {
|
|
permission1 = tmp30.permission;
|
|
}
|
|
permission = permission1;
|
|
const allChannelsSentinelResult = tmp27Result.allChannelsSentinel(contextGuildId);
|
|
}
|
|
}
|
|
if (false === permission) {
|
|
return obj.CHANNEL_DENIED;
|
|
} else if (true !== permission) {
|
|
if (false === applicationAllowedForChannel) {
|
|
return obj.CHANNEL_DENIED;
|
|
}
|
|
}
|
|
}
|
|
const tmp38 = computeAllowedForUser(type.permissions, contextGuildId, userId, roleIds, isImpersonating);
|
|
if (true === tmp38) {
|
|
let USER_DENIED = obj.ALLOWED;
|
|
} else {
|
|
if (false !== tmp38) {
|
|
if (false !== applicationAllowedForUser) {
|
|
if (null != type.defaultMemberPermissions) {
|
|
let tmp53Result = tmp53(506);
|
|
if (!tmp53Result.equals(type.defaultMemberPermissions, buildCommand.DISABLED_BY_DEFAULT_PERMISSION_FLAG)) {
|
|
tmp53Result = tmp53(506);
|
|
if (tmp53Result.has(computedPermissions, type.defaultMemberPermissions)) {
|
|
let USER_DENIED2 = obj.ALLOWED;
|
|
}
|
|
}
|
|
USER_DENIED2 = obj.USER_DENIED;
|
|
} else {
|
|
USER_DENIED = obj.ALLOWED;
|
|
}
|
|
}
|
|
}
|
|
USER_DENIED = obj.USER_DENIED;
|
|
}
|
|
return USER_DENIED;
|
|
}
|
|
obj9 = fromStringAll;
|
|
}
|
|
}
|
|
} else {
|
|
return obj.WRONG_COMMAND_TYPE;
|
|
}
|
|
};
|
|
export const computeAllowedForChannel = function computeAllowedForChannel(permissions, context, guild_id) {
|
|
if (null == permissions) {
|
|
return null;
|
|
} else {
|
|
let id2 = context.id;
|
|
if (context.isThread()) {
|
|
let id = context.parent_id;
|
|
if (id == null) {
|
|
id = context.id;
|
|
}
|
|
id2 = id;
|
|
}
|
|
obj = commandPermissions;
|
|
const tmp3 = permissions[obj.toPermissionKey(obj, id2, ApplicationCommandSectionType.ApplicationCommandPermissionType.CHANNEL)];
|
|
if (null != tmp3) {
|
|
return tmp3.permission;
|
|
} else {
|
|
let tmpResult = tmp(7200);
|
|
tmpResult = tmp(7199);
|
|
const tmp6 = permissions[tmpResult.toPermissionKey(tmpResult, tmpResult.allChannelsSentinel(guild_id), tmp(undefined, 7201).ApplicationCommandPermissionType.CHANNEL)];
|
|
let permission = null;
|
|
if (null != tmp6) {
|
|
permission = tmp6.permission;
|
|
}
|
|
return permission;
|
|
}
|
|
}
|
|
};
|
|
export { computeAllowedForUser };
|