mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
Closes #1529
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
38
src/transformers/applicationCommandPermission.ts
Normal file
38
src/transformers/applicationCommandPermission.ts
Normal 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;
|
||||
}[];
|
||||
}
|
||||
Reference in New Issue
Block a user