58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
// Metro module 13532 (f13533).
|
|
import { getGuildIconURL } from "../../../../records/GuildRecord";
|
|
import GuildStore from "../../../../stores/GuildStore";
|
|
import { RPCErrors, RPCCommands } from "../../../../Constants";
|
|
import { OAuth2Scopes } from "../../../../_bundle/Module8174";
|
|
import createRpcJoiSchemaObject from "../../helpers/createRpcJoiSchemaObject";
|
|
import RPCError from "../../RPCError";
|
|
const r21 = {};
|
|
r21[RPCCommands.GET_GUILD] = {
|
|
scope: OAuth2Scopes.RPC,
|
|
validation: (a0) => createRpcJoiSchemaObject(a0).required().keys({
|
|
guild_id: a0.string(),
|
|
timeout: a0.number().min(0).max(60)
|
|
}),
|
|
handler: ({ socket, server, args }) => {
|
|
const { guild_id, timeout = 0 } = args;
|
|
return server.storeWait(socket, () => GuildStore.getGuild(guild_id), timeout).catch(() => {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.GET_GUILD_TIMED_OUT
|
|
}, "Request to get guild timed out.");
|
|
}).then((result) => {
|
|
if (result == null) {
|
|
throw new RPCError({
|
|
errorCode: RPCErrors.INVALID_GUILD
|
|
}, `Invalid guild id: ${guild_id}`);
|
|
}
|
|
let icon_url = getGuildIconURL(result, 128);
|
|
if (icon_url == null) {
|
|
icon_url = null;
|
|
}
|
|
return {
|
|
id: result.id,
|
|
name: result.name,
|
|
icon_url,
|
|
members: [],
|
|
vanity_url_code: result.vanityURLCode
|
|
};
|
|
});
|
|
}
|
|
};
|
|
r21[RPCCommands.GET_GUILDS] = {
|
|
scope: OAuth2Scopes.RPC,
|
|
handler: () => ({
|
|
guilds: GuildStore.getGuildsArray().map((item) => {
|
|
let icon_url = getGuildIconURL(item, 128);
|
|
if (icon_url == null) {
|
|
icon_url = null;
|
|
}
|
|
return {
|
|
id: item.id,
|
|
name: item.name,
|
|
icon_url
|
|
};
|
|
})
|
|
})
|
|
};
|
|
export default r21;
|