Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for application command permissions v2 #415

Merged
merged 12 commits into from
May 12, 2022
1 change: 1 addition & 0 deletions deno/gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export enum GatewayIntentBits {
* https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
*/
export enum GatewayDispatchEvents {
ApplicationCommandPermissionsUpdate = 'APPLICATION_COMMAND_PERMISSIONS_UPDATE',
ChannelCreate = 'CHANNEL_CREATE',
ChannelDelete = 'CHANNEL_DELETE',
ChannelPinsUpdate = 'CHANNEL_PINS_UPDATE',
Expand Down
1 change: 1 addition & 0 deletions deno/gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export enum GatewayIntentBits {
* https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
*/
export enum GatewayDispatchEvents {
ApplicationCommandPermissionsUpdate = 'APPLICATION_COMMAND_PERMISSIONS_UPDATE',
ChannelCreate = 'CHANNEL_CREATE',
ChannelDelete = 'CHANNEL_DELETE',
ChannelPinsUpdate = 'CHANNEL_PINS_UPDATE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export interface APIGuildApplicationCommandPermissions {
*/
export interface APIApplicationCommandPermission {
/**
* The id of the role or user
* The id of the role, user or channel. Can also be a permission constant
*/
id: Snowflake;
/**
* Role or user
* Role, user or channel
*/
type: ApplicationCommandPermissionType;
/**
Expand All @@ -46,4 +46,13 @@ export interface APIApplicationCommandPermission {
export enum ApplicationCommandPermissionType {
Role = 1,
User,
Channel,
}

/**
* https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-constants
*/
export const APIApplicationCommandPermissionsConstant = {
Everyone: (guildId: string | bigint): Snowflake => String(guildId),
AllChannels: (guildId: string | bigint): Snowflake => String(BigInt(guildId) - 1n),
};
9 changes: 9 additions & 0 deletions deno/payloads/v10/_interactions/applicationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ export interface APIApplicationCommand {
* The parameters for the `CHAT_INPUT` command, max 25
*/
options?: APIApplicationCommandOption[];
/**
* Set of permissions represented as a bitset
*/
default_member_permissions?: Permissions | null;
/**
* Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible
*/
dm_permission?: boolean | null;
/**
* Whether the command is enabled by default when the app is added to a guild
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
*
* If missing, this property should be assumed as `true`
* @deprecated Use `dm_permission` and/or `default_member_permissions` instead
*/
default_permission?: boolean;
/**
Expand Down
15 changes: 15 additions & 0 deletions deno/payloads/v10/auditLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
GuildScheduledEventEntityType,
GuildScheduledEventStatus,
} from './guildScheduledEvent.ts';
import type { APIApplicationCommand } from './interactions.ts';
import type { APIRole } from './permissions.ts';
import type { StageInstancePrivacyLevel } from './stageInstance.ts';
import type { StickerFormatType } from './sticker.ts';
Expand All @@ -27,6 +28,12 @@ import type { Snowflake } from '../../globals.ts';
* https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
*/
export interface APIAuditLog {
/**
* List of application commands found in the audit log
*
* See https://discord.com/developers/docs/interactions/application-commands#application-command-object
*/
application_commands: APIApplicationCommand[];
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
/**
* Webhooks found in the audit log
*
Expand Down Expand Up @@ -171,6 +178,8 @@ export enum AuditLogEvent {
ThreadCreate = 110,
ThreadUpdate,
ThreadDelete,

ApplicationCommandPermissionUpdate = 121,
}

/**
Expand Down Expand Up @@ -517,6 +526,12 @@ export type APIAuditLogChangeKeyPermissions = AuditLogChangeData<'permissions',
*/
export type APIAuditLogChangeKeyColor = AuditLogChangeData<'color', number>;

/**
* Represents a change where the key is a snowflake.
* Currently, the only known instance of this is returned when permissions for a command were updated (<insert name of object here>)
*/
export type APIAuditLogChangeKeySnowflake = AuditLogChangeData<Snowflake, unknown>;

/**
* Returned when a role's hoist status is changed
*/
Expand Down
6 changes: 6 additions & 0 deletions deno/payloads/v10/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,10 @@ export enum OAuth2Scopes {
* See https://discord.com/developers/docs/interactions/application-commands
*/
ApplicationsCommandsUpdate = 'applications.commands.update',
/**
* Allows your app to update permissions for its commands using a Bearer token - client credentials grant only
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
*
* See https://discord.com/developers/docs/interactions/application-commands
*/
ApplicationCommandsPermissionsUpdate = 'applications.commands.permissions.update',
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export interface APIGuildApplicationCommandPermissions {
*/
export interface APIApplicationCommandPermission {
/**
* The id of the role or user
* The id of the role, user or channel. Can also be a permission constant
*/
id: Snowflake;
/**
* Role or user
* Role, user or channel
*/
type: ApplicationCommandPermissionType;
/**
Expand All @@ -46,4 +46,13 @@ export interface APIApplicationCommandPermission {
export enum ApplicationCommandPermissionType {
Role = 1,
User,
Channel,
}

/**
* https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-constants
*/
export const APIApplicationCommandPermissionsConstant = {
Everyone: (guildId: string | bigint): Snowflake => String(guildId),
AllChannels: (guildId: string | bigint): Snowflake => String(BigInt(guildId) - 1n),
};
9 changes: 9 additions & 0 deletions deno/payloads/v9/_interactions/applicationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ export interface APIApplicationCommand {
* The parameters for the `CHAT_INPUT` command, max 25
*/
options?: APIApplicationCommandOption[];
/**
* Set of permissions represented as a bitset
*/
default_member_permissions?: Permissions | null;
/**
* Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible
*/
dm_permission?: boolean | null;
/**
* Whether the command is enabled by default when the app is added to a guild
*
* If missing, this property should be assumed as `true`
* @deprecated Use `dm_permission` and/or `default_member_permissions` instead
*/
default_permission?: boolean;
/**
Expand Down
15 changes: 15 additions & 0 deletions deno/payloads/v9/auditLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
GuildScheduledEventEntityType,
GuildScheduledEventStatus,
} from './guildScheduledEvent.ts';
import type { APIApplicationCommand } from './interactions.ts';
import type { APIRole } from './permissions.ts';
import type { StageInstancePrivacyLevel } from './stageInstance.ts';
import type { StickerFormatType } from './sticker.ts';
Expand All @@ -27,6 +28,12 @@ import type { Snowflake } from '../../globals.ts';
* https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
*/
export interface APIAuditLog {
/**
* List of application commands found in the audit log
*
* See https://discord.com/developers/docs/interactions/application-commands#application-command-object
*/
application_commands: APIApplicationCommand[];
/**
* Webhooks found in the audit log
*
Expand Down Expand Up @@ -171,6 +178,8 @@ export enum AuditLogEvent {
ThreadCreate = 110,
ThreadUpdate,
ThreadDelete,

ApplicationCommandPermissionUpdate = 121,
}

/**
Expand Down Expand Up @@ -517,6 +526,12 @@ export type APIAuditLogChangeKeyPermissions = AuditLogChangeData<'permissions',
*/
export type APIAuditLogChangeKeyColor = AuditLogChangeData<'color', number>;

/**
* Represents a change where the key is a snowflake.
* Currently, the only known instance of this is returned when permissions for a command were updated (<insert name of object here>)
*/
export type APIAuditLogChangeKeySnowflake = AuditLogChangeData<Snowflake, unknown>;

/**
* Returned when a role's hoist status is changed
*/
Expand Down
6 changes: 6 additions & 0 deletions deno/payloads/v9/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,10 @@ export enum OAuth2Scopes {
* See https://discord.com/developers/docs/interactions/application-commands
*/
ApplicationsCommandsUpdate = 'applications.commands.update',
/**
* Allows your app to update permissions for its commands using a Bearer token - client credentials grant only
*
* See https://discord.com/developers/docs/interactions/application-commands
*/
ApplicationCommandsPermissionsUpdate = 'applications.commands.permissions.update',
}
1 change: 1 addition & 0 deletions deno/rest/v10/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type APIGuildCreatePartialChannel = StrictPartial<
| 'rate_limit_per_user'
| 'default_auto_archive_duration'
| 'position'
| 'flags'
>
> &
AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
Expand Down
17 changes: 11 additions & 6 deletions deno/rest/v10/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,29 @@ export type RESTPutAPIApplicationCommandsResult = APIApplicationCommand[];
/**
* https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands
*/
export type RESTGetAPIApplicationGuildCommandsResult = APIApplicationCommand[];
export type RESTGetAPIApplicationGuildCommandsResult = Omit<APIApplicationCommand, 'dm_permission'>[];

/**
* https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands
*/
export type RESTGetAPIApplicationGuildCommandResult = APIApplicationCommand;
export type RESTGetAPIApplicationGuildCommandResult = Omit<APIApplicationCommand, 'dm_permission'>;

/**
* https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
*/
export type RESTPostAPIApplicationGuildCommandsJSONBody = RESTPostAPIApplicationCommandsJSONBody;
export type RESTPostAPIApplicationGuildCommandsJSONBody = Omit<RESTPostAPIApplicationCommandsJSONBody, 'dm_permission'>;

/**
* https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
*/
export type RESTPostAPIApplicationGuildCommandsResult = APIApplicationCommand;
export type RESTPostAPIApplicationGuildCommandsResult = Omit<APIApplicationCommand, 'dm_permission'>;

/**
* https://discord.com/developers/docs/interactions/application-commands#edit-guild-application-command
*/
export type RESTPatchAPIApplicationGuildCommandJSONBody = StrictPartial<RESTPostAPIApplicationCommandsJSONBody>;
export type RESTPatchAPIApplicationGuildCommandJSONBody = StrictPartial<
Omit<RESTPostAPIApplicationCommandsJSONBody, 'dm_permission'>
>;

/**
* https://discord.com/developers/docs/interactions/application-commands#edit-guild-application-command
Expand All @@ -121,7 +123,10 @@ export type RESTPatchAPIApplicationGuildCommandResult = APIApplicationCommand;
/**
* https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands
*/
export type RESTPutAPIApplicationGuildCommandsJSONBody = RESTPostAPIApplicationCommandsJSONBody[];
export type RESTPutAPIApplicationGuildCommandsJSONBody = Omit<
RESTPostAPIApplicationCommandsJSONBody,
'dm_permission'
>[];

/**
* https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands
Expand Down
1 change: 1 addition & 0 deletions deno/rest/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type APIGuildCreatePartialChannel = StrictPartial<
| 'rate_limit_per_user'
| 'default_auto_archive_duration'
| 'position'
| 'flags'
>
> &
AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
Expand Down
12 changes: 7 additions & 5 deletions deno/rest/v9/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,29 @@ export type RESTPutAPIApplicationCommandsResult = APIApplicationCommand[];
/**
* https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands
*/
export type RESTGetAPIApplicationGuildCommandsResult = APIApplicationCommand[];
export type RESTGetAPIApplicationGuildCommandsResult = Omit<APIApplicationCommand, 'dm_permission'>[];

/**
* https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands
*/
export type RESTGetAPIApplicationGuildCommandResult = APIApplicationCommand;
export type RESTGetAPIApplicationGuildCommandResult = Omit<APIApplicationCommand, 'dm_permission'>;

/**
* https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
*/
export type RESTPostAPIApplicationGuildCommandsJSONBody = RESTPostAPIApplicationCommandsJSONBody;
export type RESTPostAPIApplicationGuildCommandsJSONBody = Omit<RESTPostAPIApplicationCommandsJSONBody, 'dm_permission'>;

/**
* https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
*/
export type RESTPostAPIApplicationGuildCommandsResult = APIApplicationCommand;
export type RESTPostAPIApplicationGuildCommandsResult = Omit<APIApplicationCommand, 'dm_permission'>;

/**
* https://discord.com/developers/docs/interactions/application-commands#edit-guild-application-command
*/
export type RESTPatchAPIApplicationGuildCommandJSONBody = StrictPartial<RESTPostAPIApplicationCommandsJSONBody>;
export type RESTPatchAPIApplicationGuildCommandJSONBody = StrictPartial<
Omit<RESTPostAPIApplicationCommandsJSONBody, 'dm_permission'>
>;

/**
* https://discord.com/developers/docs/interactions/application-commands#edit-guild-application-command
Expand Down
1 change: 1 addition & 0 deletions gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export enum GatewayIntentBits {
* https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
*/
export enum GatewayDispatchEvents {
ApplicationCommandPermissionsUpdate = 'APPLICATION_COMMAND_PERMISSIONS_UPDATE',
ChannelCreate = 'CHANNEL_CREATE',
ChannelDelete = 'CHANNEL_DELETE',
ChannelPinsUpdate = 'CHANNEL_PINS_UPDATE',
Expand Down
1 change: 1 addition & 0 deletions gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export enum GatewayIntentBits {
* https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
*/
export enum GatewayDispatchEvents {
ApplicationCommandPermissionsUpdate = 'APPLICATION_COMMAND_PERMISSIONS_UPDATE',
ChannelCreate = 'CHANNEL_CREATE',
ChannelDelete = 'CHANNEL_DELETE',
ChannelPinsUpdate = 'CHANNEL_PINS_UPDATE',
Expand Down
13 changes: 11 additions & 2 deletions payloads/v10/_interactions/_applicationCommands/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export interface APIGuildApplicationCommandPermissions {
*/
export interface APIApplicationCommandPermission {
/**
* The id of the role or user
* The id of the role, user or channel. Can also be a permission constant
*/
id: Snowflake;
/**
* Role or user
* Role, user or channel
*/
type: ApplicationCommandPermissionType;
/**
Expand All @@ -46,4 +46,13 @@ export interface APIApplicationCommandPermission {
export enum ApplicationCommandPermissionType {
Role = 1,
User,
Channel,
}

/**
* https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-constants
*/
export const APIApplicationCommandPermissionsConstant = {
Everyone: (guildId: string | bigint): Snowflake => String(guildId),
AllChannels: (guildId: string | bigint): Snowflake => String(BigInt(guildId) - 1n),
};
9 changes: 9 additions & 0 deletions payloads/v10/_interactions/applicationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ export interface APIApplicationCommand {
* The parameters for the `CHAT_INPUT` command, max 25
*/
options?: APIApplicationCommandOption[];
/**
* Set of permissions represented as a bitset
*/
default_member_permissions?: Permissions | null;
/**
* Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible
*/
dm_permission?: boolean | null;
/**
* Whether the command is enabled by default when the app is added to a guild
*
* If missing, this property should be assumed as `true`
* @deprecated Use `dm_permission` and/or `default_member_permissions` instead
*/
default_permission?: boolean;
/**
Expand Down
Loading