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: voice messages #9444

Merged
merged 2 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/structures/MessageAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ class MessageAttachment {
* @type {boolean}
*/
this.ephemeral = data.ephemeral ?? false;

if ('duration_secs' in data) {
/**
* The duration of this attachment in seconds
* <info>This will only be available if the attachment is an audio file.</info>
* @type {?number}
*/
this.duration = data.duration_secs;
} else {
this.duration ??= null;
}

if ('waveform' in data) {
/**
* The base64 encoded byte array representing a sampled waveform
* <info>This will only be available if the attachment is an audio file.</info>
* @type {?string}
*/
this.waveform = data.waveform;
} else {
this.waveform ??= null;
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@
'role_connections.write',
];

// TODO: change Integration#expireBehavior to this and clean up Integration

Check warning on line 536 in src/util/Constants.js

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected 'todo' comment: 'TODO: change Integration#expireBehavior...'
/**
* The behavior of expiring subscribers for Integrations. This can be:
* * REMOVE_ROLE
Expand Down Expand Up @@ -1141,6 +1141,11 @@
INVALID_JSON: 50109,
CANNOT_MIX_SUBSCRIPTION_AND_NON_SUBSCRIPTION_ROLES_FOR_EMOJI: 50144,
CANNOT_CONVERT_PREMIUM_EMOJI_TO_NORMAL_EMOJI: 50145,
VOICE_MESSAGES_DO_NOT_SUPPORT_ADDITIONAL_CONTENT: 50159,
VOICE_MESSAGES_MUST_HAVE_A_SINGLE_AUDIO_ATTACHMENT: 50160,
VOICE_MESSAGES_MUST_HAVE_SUPPORTING_METADATA: 50161,
VOICE_MESSAGES_CANNOT_BE_EDITED: 50162,
YOU_CANNOT_SEND_VOICE_MESSAGES_IN_THIS_CHANNEL: 50173,
TWO_FACTOR_REQUIRED: 60003,
NO_USERS_WITH_DISCORDTAG_EXIST: 80004,
REACTION_BLOCKED: 90001,
Expand Down
1 change: 1 addition & 0 deletions src/util/MessageFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ MessageFlags.FLAGS = {
EPHEMERAL: 1 << 6,
LOADING: 1 << 7,
SUPPRESS_NOTIFICATIONS: 1 << 12,
IS_VOICE_MESSAGE: 1 << 13,
};

module.exports = MessageFlags;
1 change: 1 addition & 0 deletions src/util/Permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
REQUEST_TO_SPEAK: 1n << 32n,
MANAGE_EVENTS: 1n << 33n,
MANAGE_THREADS: 1n << 34n,
// TODO: Remove deprecated USE_*_THREADS flags in v14

Check warning on line 152 in src/util/Permissions.js

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected 'todo' comment: 'TODO: Remove deprecated USE_*_THREADS...'
USE_PUBLIC_THREADS: 1n << 35n,
CREATE_PUBLIC_THREADS: 1n << 35n,
USE_PRIVATE_THREADS: 1n << 36n,
Expand All @@ -160,6 +160,7 @@
MODERATE_MEMBERS: 1n << 40n,
VIEW_CREATOR_MONETIZATION_ANALYTICS: 1n << 41n,
USE_SOUNDBOARD: 1n << 42n,
SEND_VOICE_MESSAGES: 1n << 46n,
};

/**
Expand Down
13 changes: 11 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,7 @@ export class MessageAttachment {
public attachment: BufferResolvable | Stream;
public contentType: string | null;
public description: string | null;
public duration: number | null;
public ephemeral: boolean;
public height: number | null;
public id: Snowflake;
Expand All @@ -1713,6 +1714,7 @@ export class MessageAttachment {
public size: number;
public readonly spoiler: boolean;
public url: string;
public waveform: string | null;
public width: number | null;
public setDescription(description: string): this;
public setFile(attachment: BufferResolvable | Stream, name?: string): this;
Expand Down Expand Up @@ -3933,6 +3935,11 @@ export interface APIErrors {
INSUFFICIENT_BOOSTS: 50101;
INVALID_JSON: 50109;
CANNOT_MIX_SUBSCRIPTION_AND_NON_SUBSCRIPTION_ROLES_FOR_EMOJI: 50144;
VOICE_MESSAGES_DO_NOT_SUPPORT_ADDITIONAL_CONTENT: 50159;
VOICE_MESSAGES_MUST_HAVE_A_SINGLE_AUDIO_ATTACHMENT: 50160;
VOICE_MESSAGES_MUST_HAVE_SUPPORTING_METADATA: 50161;
VOICE_MESSAGES_CANNOT_BE_EDITED: 50162;
YOU_CANNOT_SEND_VOICE_MESSAGES_IN_THIS_CHANNEL: 50173;
CANNOT_CONVERT_PREMIUM_EMOJI_TO_NORMAL_EMOJI: 50145;
TWO_FACTOR_REQUIRED: 60003;
NO_USERS_WITH_DISCORDTAG_EXIST: 80004;
Expand Down Expand Up @@ -5864,7 +5871,8 @@ export type MessageFlagsString =
| 'HAS_THREAD'
| 'EPHEMERAL'
| 'LOADING'
| 'SUPPRESS_NOTIFICATIONS';
| 'SUPPRESS_NOTIFICATIONS'
| 'IS_VOICE_MESSAGE';

export interface MessageInteraction {
id: Snowflake;
Expand Down Expand Up @@ -6056,7 +6064,8 @@ export type PermissionString =
| 'MODERATE_MEMBERS'
| 'MANAGE_EVENTS'
| 'VIEW_CREATOR_MONETIZATION_ANALYTICS'
| 'USE_SOUNDBOARD';
| 'USE_SOUNDBOARD'
| 'SEND_VOICE_MESSAGES';

export type RecursiveArray<T> = ReadonlyArray<T | RecursiveArray<T>>;

Expand Down
16 changes: 14 additions & 2 deletions typings/rawDataTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
APIApplication,
APIApplicationCommand,
APIApplicationCommandInteraction,
APIAttachment,
APIAuditLog,
APIAuditLogEntry,
APIBan,
Expand Down Expand Up @@ -169,7 +168,20 @@ export type RawInviteStageInstance = APIInviteStageInstance;
export type RawMessageData = APIMessage;
export type RawPartialMessageData = GatewayMessageUpdateDispatchData;

export type RawMessageAttachmentData = APIAttachment;
export interface RawMessageAttachmentData {
id: Snowflake;
filename: string;
description?: string;
content_type?: string;
size: number;
url: string;
proxy_url: string;
height?: number | null;
width?: number | null;
ephemeral?: boolean;
duration_secs?: number;
waveform?: string;
}

export type RawMessagePayloadData =
| RESTPostAPIChannelMessageJSONBody
Expand Down