From 30457a0e812a21eeca80ebd3742917eb222dcb6e Mon Sep 17 00:00:00 2001
From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com>
Date: Tue, 25 Apr 2023 18:18:55 +0700
Subject: [PATCH] feat: voice messages
#9444 djs
---
package.json | 10 +++++-----
src/structures/MessageAttachment.js | 22 ++++++++++++++++++++++
src/util/Constants.js | 6 ++++++
src/util/MessageFlags.js | 2 ++
src/util/Permissions.js | 1 +
typings/index.d.ts | 13 +++++++++++--
6 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/package.json b/package.json
index 5f15164..e2dde61 100644
--- a/package.json
+++ b/package.json
@@ -61,7 +61,7 @@
"@types/ws": "^8.5.4",
"axios": "1.1",
"chalk": "^4.1.2",
- "discord-api-types": "^0.37.37",
+ "discord-api-types": "^0.37.40",
"form-data": "^4.0.0",
"json-bigint": "^1.0.0",
"lodash.permutations": "^1.0.0",
@@ -82,10 +82,10 @@
"@commitlint/config-angular": "^16.0.0",
"@discordjs/docgen": "^0.11.1",
"@favware/npm-deprecate": "^1.0.7",
- "@types/node": "^18.15.11",
+ "@types/node": "^18.16.0",
"conventional-changelog-cli": "^2.2.2",
"dtslint": "^4.2.1",
- "eslint": "^8.36.0",
+ "eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
@@ -93,8 +93,8 @@
"is-ci": "^3.0.1",
"jest": "^28.1.3",
"lint-staged": "^12.1.4",
- "prettier": "^2.8.7",
- "tsd": "^0.25.0",
+ "prettier": "^2.8.8",
+ "tsd": "^0.28.1",
"tslint": "^6.1.3",
"typescript": "^4.9.5"
}
diff --git a/src/structures/MessageAttachment.js b/src/structures/MessageAttachment.js
index 3426a17..4be74c8 100644
--- a/src/structures/MessageAttachment.js
+++ b/src/structures/MessageAttachment.js
@@ -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
+ * This will only be available if the attachment is an audio file.
+ * @type {?number}
+ */
+ this.duration = data.duration_secs;
+ } else {
+ this.duration ??= null;
+ }
+
+ if ('waveform' in data) {
+ /**
+ * The base64 encoded byte array representing a sampled waveform
+ * This will only be available if the attachment is an audio file.
+ * @type {?string}
+ */
+ this.waveform = data.waveform;
+ } else {
+ this.waveform ??= null;
+ }
}
/**
diff --git a/src/util/Constants.js b/src/util/Constants.js
index 954d0c2..0be13f6 100644
--- a/src/util/Constants.js
+++ b/src/util/Constants.js
@@ -1201,6 +1201,7 @@ exports.VerificationLevels = createEnum(['NONE', 'LOW', 'MEDIUM', 'HIGH', 'VERY_
* * FAILED_TO_CREATE_STAGE_NEEDED_FOR_STAGE_EVENT
* @typedef {string} APIError
* @see {@link https://discord.com/developers/docs/topics/opcodes-and-status-codes#json-json-error-codes}
+ * @see {@link https://gist.github.com/Dziurwa14/de2498e5ee28d2089f095aa037957cbb}
*/
exports.APIErrors = {
UNKNOWN_ACCOUNT: 10001,
@@ -1356,6 +1357,11 @@ exports.APIErrors = {
INVALID_FILE_ASSET_SIZE_RESIZE_GIF: 50138,
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_ENABLED: 60001,
TWO_FACTOR_DISABLED: 60002,
TWO_FACTOR_REQUIRED: 60003,
diff --git a/src/util/MessageFlags.js b/src/util/MessageFlags.js
index da271b8..2e75fe7 100644
--- a/src/util/MessageFlags.js
+++ b/src/util/MessageFlags.js
@@ -33,6 +33,7 @@ class MessageFlags extends BitField {}
* * `LOADING`
* * `FAILED_TO_MENTION_SOME_ROLES_IN_THREAD`
* * `SUPPRESS_NOTIFICATIONS`
+ * * `IS_VOICE_MESSAGE`
* @type {Object}
* @see {@link https://discord.com/developers/docs/resources/channel#message-object-message-flags}
*/
@@ -47,6 +48,7 @@ MessageFlags.FLAGS = {
LOADING: 1 << 7,
FAILED_TO_MENTION_SOME_ROLES_IN_THREAD: 1 << 8,
SUPPRESS_NOTIFICATIONS: 1 << 12,
+ IS_VOICE_MESSAGE: 1 << 13,
};
module.exports = MessageFlags;
diff --git a/src/util/Permissions.js b/src/util/Permissions.js
index 32f6831..4ec12b6 100644
--- a/src/util/Permissions.js
+++ b/src/util/Permissions.js
@@ -160,6 +160,7 @@ Permissions.FLAGS = {
MODERATE_MEMBERS: 1n << 40n,
VIEW_CREATOR_MONETIZATION_ANALYTICS: 1n << 41n,
USE_SOUNDBOARD: 1n << 42n,
+ SEND_VOICE_MESSAGES: 1n << 46n,
};
/**
diff --git a/typings/index.d.ts b/typings/index.d.ts
index 81255cb..3dd3887 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -2157,6 +2157,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;
@@ -2165,6 +2166,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;
@@ -4671,6 +4673,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;
INVALID_TWO_FACTOR_CODE: 60008;
@@ -6807,7 +6814,8 @@ export type MessageFlagsString =
| 'EPHEMERAL'
| 'LOADING'
| 'FAILED_TO_MENTION_SOME_ROLES_IN_THREAD'
- | 'SUPPRESS_NOTIFICATIONS';
+ | 'SUPPRESS_NOTIFICATIONS'
+ | 'IS_VOICE_MESSAGE';
export interface MessageInteraction {
id: Snowflake;
@@ -7023,7 +7031,8 @@ export type PermissionString =
| 'MODERATE_MEMBERS'
| 'MANAGE_EVENTS'
| 'VIEW_CREATOR_MONETIZATION_ANALYTICS'
- | 'USE_SOUNDBOARD';
+ | 'USE_SOUNDBOARD'
+ | 'SEND_VOICE_MESSAGES';
export type RecursiveArray = ReadonlyArray>;