Files
discord-decomp/modules/rpc/server/commands/invites.tsx
T
2026-11-01 12:12:55 +02:00

98 lines
3.7 KiB
TypeScript

// Metro module 13534 (f13535).
import EmbeddedActivitiesStore from "../../../activities/EmbeddedActivitiesStore";
import ChannelStore from "../../../../stores/ChannelStore";
import { RPC_SCOPE_CONFIG } from "../../Constants";
import { InstantInviteSources } from "../../../../Constants";
import { RPCErrors, RPCCommands } from "../../../../_bundle/Module505";
import { createRPCCommand } from "../../../../_bundle/Module13535";
import { OAuth2Scopes } from "../../../../_bundle/Module8174";
import { RPCError } from "../../../../_bundle/Module10627";
import { EmbeddedActivityLocationKind } from "../../../../_bundle/Module10648";
import { validateOpenInviteDialog } from "../../helpers/validateOpenInviteDialog";
import { ChannelTypes } from "../../../../_bundle/Module692";
import { sendEmbeddedActivityInviteUser } from "../../../activities/EmbeddedActivitiesActionCreators";
const r32 = {};
const { INVITE_USER_EMBEDDED, INVITE_USER_EMBEDDED: INVITE_USER_EMBEDDED2 } = RPCCommands;
const scope = {};
scope[RPC_SCOPE_CONFIG.ANY] = [OAuth2Scopes.DM_CHANNELS_MESSAGES_WRITE, OAuth2Scopes.ACTIVITIES_INVITES_WRITE];
r32[INVITE_USER_EMBEDDED] = createRPCCommand(INVITE_USER_EMBEDDED2, {
scope,
handler: async ({ socket, args }) => {
let r80;
const { user_id, content } = args;
let c27496_2 = 0;
const r20 = "No eligible activity for application. Ensure an activity was set using setActivity.";
try {
const id = socket.application.id;
if (id == null) {
throw new RPCError({
errorCode: RPCErrors.INVALID_COMMAND
}, "No application.");
}
const connectedActivityLocation = EmbeddedActivitiesStore.getConnectedActivityLocation();
if (connectedActivityLocation == null) {
throw new RPCError({
errorCode: RPCErrors.NO_ELIGIBLE_ACTIVITY
}, r20);
}
L19: {
const kind = connectedActivityLocation.kind;
if (EmbeddedActivityLocationKind.GUILD_CHANNEL !== kind && EmbeddedActivityLocationKind.GUILD_CHANNEL_MESSAGE !== kind) {
if (EmbeddedActivityLocationKind.PRIVATE_CHANNEL !== kind && EmbeddedActivityLocationKind.PRIVATE_CHANNEL_MESSAGE !== kind) {
throw new RPCError({
errorCode: RPCErrors.NO_ELIGIBLE_ACTIVITY
}, "Unsupported activity location");
}
const channel = ChannelStore.getChannel(connectedActivityLocation.channel_id);
if (channel == null) {
throw new RPCError({
errorCode: RPCErrors.INVALID_CHANNEL
}, "Invalid channel");
}
const type = channel.type;
const DM = ChannelTypes.DM;
r80 = channel;
if (type !== DM) {
break L19;
}
throw new RPCError({
errorCode: RPCErrors.INVALID_CHANNEL
}, "Cannot send invite to a DM");
}
r80 = validateOpenInviteDialog().channel;
}
c27496_2 = 1;
await sendEmbeddedActivityInviteUser({
channelId: r80.id,
applicationId: id,
userId: user_id,
prefixedContent: content,
location: "RPC_ACTIVITY_INVITE_USER",
inviteAnalyticsMetadata: {
source: InstantInviteSources.ACTIVITY_INVITE
}
});
c27496_2 = 0;
} catch ($e) {
let r37 = $e;
if (c27496_2 !== 0) {
while (true) {
try {
c27496_2 = 0;
throw new RPCError({
errorCode: RPCErrors.UNKNOWN_ERROR
}, "Failed to invite user");
} catch ($e) {
r37 = $e;
if (c27496_2 === 0) {
break;
}
}
}
}
throw r37;
}
}
});
export default r32;