This commit is contained in:
Skillz4Killz
2021-11-08 19:09:41 +00:00
committed by GitHub
parent 56e2163d6d
commit 3f60b0da40
4 changed files with 49 additions and 2 deletions

View File

@@ -110,6 +110,7 @@ import { AsyncCache, AsyncCacheHandler, Cache, CacheHandler, createCache, TableN
import { transformThread } from "./transformers/thread.ts";
import { transformWebhook } from "./transformers/webhook.ts";
import { transformAuditlogEntry } from "./transformers/auditlogEntry.ts";
import { transformApplicationCommandPermission } from "./transformers/applicationCommandPermission.ts";
type CacheOptions =
| {
@@ -847,6 +848,7 @@ export interface Transformers {
thread: typeof transformThread;
webhook: typeof transformWebhook;
auditlogEntry: typeof transformAuditlogEntry;
applicationCommandPermission: typeof transformApplicationCommandPermission
}
export function createTransformers(options: Partial<Transformers>) {
@@ -873,6 +875,7 @@ export function createTransformers(options: Partial<Transformers>) {
snowflake: options.snowflake || snowflakeToBigint,
webhook: options.webhook || transformWebhook,
auditlogEntry: options.auditlogEntry || transformAuditlogEntry,
applicationCommandPermission: transformApplicationCommandPermission
};
}

View File

@@ -1,5 +1,6 @@
import type { Bot } from "../../../bot.ts";
import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts";
import { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts";
/** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */
export async function batchEditSlashCommandPermissions(
@@ -7,10 +8,12 @@ export async function batchEditSlashCommandPermissions(
guildId: bigint,
options: { id: string; permissions: ApplicationCommandPermissions[] }[]
) {
return await bot.rest.runMethod(
const result = await bot.rest.runMethod<GuildApplicationCommandPermissions[]>(
bot.rest,
"put",
bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId),
options
);
return result.map((res) => bot.transformers.applicationCommandPermission(bot, res));
}

View File

@@ -1,5 +1,6 @@
import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts";
import type { Bot } from "../../../bot.ts";
import { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts";
/** Edits command permissions for a specific command for your application in a guild. */
export async function editSlashCommandPermissions(
@@ -8,7 +9,7 @@ export async function editSlashCommandPermissions(
commandId: bigint,
options: ApplicationCommandPermissions[]
) {
return await bot.rest.runMethod(
const result = await bot.rest.runMethod<GuildApplicationCommandPermissions>(
bot.rest,
"put",
bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId),
@@ -16,4 +17,6 @@ export async function editSlashCommandPermissions(
permissions: options,
}
);
return bot.transformers.applicationCommandPermission(bot, result);
}

View File

@@ -0,0 +1,38 @@
import { Bot } from "../bot.ts";
import { DiscordApplicationCommandPermissionTypes } from "../types/interactions/commands/application_command_permission_types.ts";
import { GuildApplicationCommandPermissions } from "../types/interactions/commands/guild_application_command_permissions.ts";
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
export function transformApplicationCommandPermission(
bot: Bot,
payload: SnakeCasedPropertiesDeep<GuildApplicationCommandPermissions>
): DiscordenoApplicationCommandPermission {
return {
id: bot.transformers.snowflake(payload.id),
applicationId: bot.transformers.snowflake(payload.application_id),
guildId: bot.transformers.snowflake(payload.guild_id),
permissions: payload.permissions.map((perm) => ({
id: bot.transformers.snowflake(perm.id),
type: perm.type,
permission: perm.permission,
})),
};
}
export interface DiscordenoApplicationCommandPermission {
/** The id of the command */
id: bigint;
/** The id of the application to command belongs to */
applicationId: bigint;
/** The id of the guild */
guildId: bigint;
/** The permissions for the command in the guild */
permissions: {
/** The id of the role or user */
id: bigint;
/** Role or User */
type: DiscordApplicationCommandPermissionTypes;
/** `true` to allow, `false`, to disallow */
permission: boolean;
}[];
}