Skip to content

Commit

Permalink
feat: voice message support (#67)
Browse files Browse the repository at this point in the history
* feat: voice message support

Ref: discord/discord-api-docs#6082

* keep the waveform as-is

While currently the docs specify it is a base64 byte array, it might be
more worthwhile to give the API consumer a raw string and let them deal
with it appropriately. Let alone this is probably a more future-proof
variant, as (although very unlikely) the format could change in the future.
  • Loading branch information
TTtie committed May 11, 2023
1 parent b15d968 commit cbc8839
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 6 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,7 @@ declare namespace Dysnomia {
LOADING: 128;
FAILED_TO_MENTION_SOME_ROLES_IN_THREAD: 256;
SUPPRESS_NOTIFICATIONS: 4096;
IS_VOICE_MESSAGE: 8192;
};
MessageTypes: {
DEFAULT: 0;
Expand Down Expand Up @@ -2328,10 +2329,11 @@ declare namespace Dysnomia {
moderateMembers: 1099511627776n;
viewCreatorMonetizationAnalytics: 2199023255552n;
useSoundboard: 4398046511104n;
sendVoiceMessages: 70368744177664n;
allGuild: 3309205717182n;
allText: 535529258065n;
allText: 70904273435729n;
allVoice: 4952431789841n;
all: 8796093022207n;
all: 79164837199871n;
};
PremiumTiers: {
NONE: 0;
Expand Down Expand Up @@ -2534,13 +2536,15 @@ declare namespace Dysnomia {
export class Attachment extends Base {
contentType?: string;
description?: string;
durationSecs?: number;
ephemeral?: boolean;
filename: string;
height?: number;
id: string;
proxyURL: string;
size: number;
url: string;
waveform?: string;
width?: number;
constructor(data: BaseData);
}
Expand Down
9 changes: 6 additions & 3 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ module.exports.MessageFlags = {
EPHEMERAL: 1 << 6,
LOADING: 1 << 7,
FAILED_TO_MENTION_SOME_ROLES_IN_THREAD: 1 << 8,
SUPPRESS_NOTIFICATIONS: 1 << 12
SUPPRESS_NOTIFICATIONS: 1 << 12,
IS_VOICE_MESSAGE: 1 << 13
};

module.exports.MessageTypes = {
Expand Down Expand Up @@ -502,7 +503,8 @@ const Permissions = {
startEmbeddedActivities: 1n << 39n,
moderateMembers: 1n << 40n,
viewCreatorMonetizationAnalytics: 1n << 41n,
useSoundboard: 1n << 42n
useSoundboard: 1n << 42n,
sendVoiceMessages: 1n << 46n
};
Permissions.allGuild = Permissions.kickMembers
| Permissions.banMembers
Expand Down Expand Up @@ -538,7 +540,8 @@ Permissions.allText = Permissions.createInstantInvite
| Permissions.createPublicThreads
| Permissions.createPrivateThreads
| Permissions.useExternalStickers
| Permissions.sendMessagesInThreads;
| Permissions.sendMessagesInThreads
| Permissions.sendVoiceMessages;
Permissions.allVoice = Permissions.createInstantInvite
| Permissions.manageChannels
| Permissions.voicePrioritySpeaker
Expand Down
6 changes: 6 additions & 0 deletions lib/structures/Attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const Base = require("./Base");
* Represents an attachment
* @prop {String?} contentType The content type of the attachment
* @prop {String?} description The description of the attachment
* @prop {Number?} durationSecs The duration of the audio file (voice messages only)
* @prop {Boolean?} ephemeral Whether the attachment is ephemeral
* @prop {String} filename The filename of the attachment
* @prop {Number?} height The height of the attachment
* @prop {String} id The attachment ID
* @prop {String} proxyURL The proxy URL of the attachment
* @prop {Number} size The size of the attachment
* @prop {String} url The URL of the attachment
* @prop {String?} waveform A Base64-encoded byte array representing the sampled waveform of the audio file (voice messages only)
* @prop {Number?} width The width of the attachment
*/
class Attachment extends Base {
Expand All @@ -23,6 +25,8 @@ class Attachment extends Base {
this.size = data.size;
this.url = data.url;
this.proxyURL = data.proxy_url;
this.durationSecs = data.duration_secs;
this.waveform = data.waveform;
this.update(data);
}

Expand Down Expand Up @@ -55,6 +59,8 @@ class Attachment extends Base {
"height",
"width",
"ephemeral",
"durationSecs",
"waveform",
...props
]);
}
Expand Down

0 comments on commit cbc8839

Please sign in to comment.