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

68 lines
2.2 KiB
TypeScript

// Metro module 8949 (f8950).
import ChannelStore from "../../stores/ChannelStore";
import SelectedGuildStore from "../../stores/SelectedGuildStore";
import { EMPTY_NUX_SERVER, FAVORITES, ME } from "../../Constants";
import { RemovedScopes } from "./scopes";
import { OAuth2Scopes } from "../../_bundle/Module8174";
import { parse } from "../../_bundle/keysSorter";
import * as _PermissionUtils from "../../utils/PermissionUtils";
import { deserialize } from "../../_bundle/HighLow";
export function filterScopes(a0) {
const r8 = a0.filter((item) => !RemovedScopes.includes(item));
if (r8.includes(OAuth2Scopes.BOT) && !r8.includes(OAuth2Scopes.APPLICATIONS_COMMANDS)) {
r8.push(OAuth2Scopes.APPLICATIONS_COMMANDS);
}
return r8;
}
export function parseOAuth2AuthorizeProps(a0) {
const r13 = parse(a0, {
arrayFormat: "bracket"
});
let NONE = _PermissionUtils.NONE;
try {
NONE = deserialize(r13.permissions != null ? r13.permissions !== "" ? r13.permissions : "0" : "0");
} catch ($e) {}
const channel_id = r13.channel_id;
let guild_id = r13.guild_id;
if (guild_id == null) {
guild_id = ChannelStore.getChannel(channel_id)?.guild_id;
}
if (guild_id == null) {
guild_id = SelectedGuildStore.getGuildId();
}
const guildId = (function sanitizeOAuthGuild(a0) {
let r1 = a0;
if ([ME, FAVORITES, EMPTY_NUX_SERVER].includes(a0)) {
return void 0;
}
if (a0 == null) {
r1 = void 0;
}
return r1;
})(guild_id);
let client_id = r13.client_id;
if (client_id == null) {
client_id = "";
}
let scope = r13.scope;
if (scope == null) {
scope = "";
}
return {
clientId: client_id,
scopes: scope.replace(/\+/g, " ").split(" ").filter((item) => item.length > 0),
responseType: r13.response_type,
redirectUri: r13.redirect_uri,
codeChallenge: r13.code_challenge,
codeChallengeMethod: r13.code_challenge_method,
state: r13.state,
permissions: NONE,
channelId: channel_id,
guildId,
prompt: r13.prompt,
disableGuildSelect: r13.disable_guild_select === "true",
integrationType: r13.integration_type == null ? void 0 : Number(r13.integration_type),
nonce: r13.nonce
};
}