change: use bigint for ids

This commit is contained in:
ITOH
2021-05-21 18:40:25 +02:00
parent 5943c88027
commit 4c98b73cd0
2 changed files with 15 additions and 2 deletions
@@ -1,14 +1,21 @@
import { applicationId } from "../../../bot.ts"; import { applicationId } from "../../../bot.ts";
import { rest } from "../../../rest/rest.ts"; import { rest } from "../../../rest/rest.ts";
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
import { snowflakeToBigint } from "../../../util/bigint.ts";
import { endpoints } from "../../../util/constants.ts"; import { endpoints } from "../../../util/constants.ts";
/** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */ /** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */
export async function getSlashCommand(commandId: bigint, guildId?: bigint) { export async function getSlashCommand(commandId: bigint, guildId?: bigint) {
return await rest.runMethod<ApplicationCommand>( const result = await rest.runMethod<ApplicationCommand>(
"get", "get",
guildId guildId
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId) ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
: endpoints.COMMANDS_ID(applicationId, commandId) : endpoints.COMMANDS_ID(applicationId, commandId)
); );
return {
...result,
id: snowflakeToBigint(result.id),
applicationId: snowflakeToBigint(result.applicationId),
};
} }
@@ -1,6 +1,7 @@
import { applicationId } from "../../../bot.ts"; import { applicationId } from "../../../bot.ts";
import { rest } from "../../../rest/rest.ts"; import { rest } from "../../../rest/rest.ts";
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
import { snowflakeToBigint } from "../../../util/bigint.ts";
import { Collection } from "../../../util/collection.ts"; import { Collection } from "../../../util/collection.ts";
import { endpoints } from "../../../util/constants.ts"; import { endpoints } from "../../../util/constants.ts";
@@ -11,5 +12,10 @@ export async function getSlashCommands(guildId?: bigint) {
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId) guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId)
); );
return new Collection(result.map((command) => [command.name, command])); return new Collection(
result.map((command) => [
command.name,
{ ...command, id: snowflakeToBigint(command.id), applicationId: snowflakeToBigint(command.applicationId) },
])
);
} }