Skip to content

Commit

Permalink
Merge branch 'main' into audit-log-types
Browse files Browse the repository at this point in the history
  • Loading branch information
cobaltt7 authored Nov 17, 2024
2 parents 1217d9c + 51a017a commit 1a36991
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 26 deletions.
1 change: 0 additions & 1 deletion packages/builders/__tests__/components/button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
type APIButtonComponentWithURL,
} from 'discord-api-types/v10';
import { describe, test, expect } from 'vitest';
import { ButtonBuilder } from '../../src/components/button/Button.js';
import { PrimaryButtonBuilder, PremiumButtonBuilder, LinkButtonBuilder } from '../../src/index.js';

const longStr =
Expand Down
4 changes: 2 additions & 2 deletions packages/builders/__tests__/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ type BuilderPropsOnly<Type = ChatInputCommandBuilder> = Pick<
}
>;

expectTypeOf(getBuilder().addStringOption(getStringOption())).toMatchTypeOf<BuilderPropsOnly>();
expectTypeOf(getBuilder().addStringOptions(getStringOption())).toMatchTypeOf<BuilderPropsOnly>();

expectTypeOf(getBuilder().addSubcommand(getSubcommand())).toMatchTypeOf<BuilderPropsOnly>();
expectTypeOf(getBuilder().addSubcommands(getSubcommand())).toMatchTypeOf<BuilderPropsOnly>();
2 changes: 0 additions & 2 deletions packages/collection/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,6 @@ export class Collection<Key, Value> extends Map<Key, Value> {

/**
* The sort method sorts the items of a collection in place and returns it.
* The sort is not necessarily stable in Node 10 or older.
* The default sort order is according to string Unicode code points.
*
* @param compareFunction - Specifies a function that defines the sort order.
Expand Down Expand Up @@ -1026,7 +1025,6 @@ export class Collection<Key, Value> extends Map<Key, Value> {

/**
* The sorted method sorts the items of a collection and returns it.
* The sort is not necessarily stable in Node 10 or older.
* The default sort order is according to string Unicode code points.
*
* @param compareFunction - Specifies a function that defines the sort order.
Expand Down
50 changes: 45 additions & 5 deletions packages/core/src/api/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,17 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/message#get-reactions}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to get the reactions for
* @param emoji - The emoji to get the reactions for
* @param emoji - The emoji to get the reactions for. URL encoding happens internally
* @param query - The query options for fetching the reactions
* @param options - The options for fetching the message reactions
* @example
* ```ts
* // Unicode.
* await api.channels.getMessageReactions('1234567890', '1234567890', '👍');
*
* // Custom emoji.
* await api.channels.getMessageReactions('1234567890', '1234567890', 'emoji_name:1234567890');
* ```
*/
public async getMessageReactions(
channelId: Snowflake,
Expand All @@ -115,8 +123,16 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/message#delete-own-reaction}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reaction for
* @param emoji - The emoji to delete the reaction for
* @param emoji - The emoji to delete the reaction for. URL encoding happens internally
* @param options - The options for deleting the reaction
* @example
* ```ts
* // Unicode.
* await api.channels.deleteOwnMessageReaction('1234567890', '1234567890', '👍');
*
* // Custom emoji.
* await api.channels.deleteOwnMessageReaction('1234567890', '1234567890', 'emoji_name:1234567890');
* ```
*/
public async deleteOwnMessageReaction(
channelId: Snowflake,
Expand All @@ -135,9 +151,17 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/message#delete-user-reaction}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reaction for
* @param emoji - The emoji to delete the reaction for
* @param emoji - The emoji to delete the reaction for. URL encoding happens internally
* @param userId - The id of the user to delete the reaction for
* @param options - The options for deleting the reaction
* @example
* ```ts
* // Unicode.
* await api.channels.deleteUserMessageReaction('1234567890', '1234567890', '👍', '1234567890');
*
* // Custom emoji.
* await api.channels.deleteUserMessageReaction('1234567890', '1234567890', 'emoji_name:1234567890', '1234567890');
* ```
*/
public async deleteUserMessageReaction(
channelId: Snowflake,
Expand Down Expand Up @@ -173,8 +197,16 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/message#delete-all-reactions-for-emoji}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reactions for
* @param emoji - The emoji to delete the reactions for
* @param emoji - The emoji to delete the reactions for. URL encoding happens internally
* @param options - The options for deleting the reactions
* @example
* ```ts
* // Unicode.
* await api.channels.deleteAllMessageReactionsForEmoji('1234567890', '1234567890', '👍');
*
* // Custom emoji.
* await api.channels.deleteAllMessageReactionsForEmoji('1234567890', '1234567890', 'emoji_name:1234567890');
* ```
*/
public async deleteAllMessageReactionsForEmoji(
channelId: Snowflake,
Expand All @@ -191,8 +223,16 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/message#create-reaction}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to add the reaction to
* @param emoji - The emoji to add the reaction with
* @param emoji - The emoji to add the reaction with. URL encoding happens internally
* @param options - The options for adding the reaction
* @example
* ```ts
* // Unicode.
* await api.channels.addMessageReaction('1234567890', '1234567890', '👍');
*
* // Custom emoji.
* await api.channels.addMessageReaction('1234567890', '1234567890', 'emoji_name:1234567890');
* ```
*/
public async addMessageReaction(
channelId: Snowflake,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const VoiceChannelEffect = require('../../../structures/VoiceChannelEffect');
const Events = require('../../../util/Events');

module.exports = (client, { d: data }) => {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;

/**
* Emmited when someone sends an effect, such as an emoji reaction, in a voice channel the client is connected to.
* @event Client#voiceChannelEffectSend
* @param {VoiceChannelEffect} voiceChannelEffect The sent voice channel effect
*/
client.emit(Events.VoiceChannelEffectSend, new VoiceChannelEffect(data, guild));
};
1 change: 1 addition & 0 deletions packages/discord.js/src/client/websocket/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const handlers = Object.fromEntries([
['THREAD_UPDATE', require('./THREAD_UPDATE')],
['TYPING_START', require('./TYPING_START')],
['USER_UPDATE', require('./USER_UPDATE')],
['VOICE_CHANNEL_EFFECT_SEND', require('./VOICE_CHANNEL_EFFECT_SEND')],
['VOICE_SERVER_UPDATE', require('./VOICE_SERVER_UPDATE')],
['VOICE_STATE_UPDATE', require('./VOICE_STATE_UPDATE')],
['WEBHOOKS_UPDATE', require('./WEBHOOKS_UPDATE')],
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ exports.ThreadOnlyChannel = require('./structures/ThreadOnlyChannel');
exports.Typing = require('./structures/Typing');
exports.User = require('./structures/User');
exports.UserContextMenuCommandInteraction = require('./structures/UserContextMenuCommandInteraction');
exports.VoiceChannelEffect = require('./structures/VoiceChannelEffect');
exports.VoiceChannel = require('./structures/VoiceChannel');
exports.VoiceRegion = require('./structures/VoiceRegion');
exports.VoiceState = require('./structures/VoiceState');
Expand Down
10 changes: 9 additions & 1 deletion packages/discord.js/src/structures/GuildAuditLogsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const Partials = require('../util/Partials');
const { flatten } = require('../util/Util');

const Targets = {
All: 'All',
Guild: 'Guild',
GuildScheduledEvent: 'GuildScheduledEvent',
Channel: 'Channel',
Expand Down Expand Up @@ -513,6 +512,15 @@ class GuildAuditLogsEntry {
return new Date(this.createdTimestamp);
}

/**
* Checks whether this GuildAuditLogsEntry is of the specified {@link AuditLogEvent} type.
* @param {AuditLogEvent} action The type to check for
* @returns {boolean}
*/
isAction(action) {
return this.action === action;
}

toJSON() {
return flatten(this, { createdTimestamp: true });
}
Expand Down
69 changes: 69 additions & 0 deletions packages/discord.js/src/structures/VoiceChannelEffect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';

const { Emoji } = require('./Emoji');

/**
* Represents an effect used in a {@link VoiceChannel}.
*/
class VoiceChannelEffect {
constructor(data, guild) {
/**
* The guild where the effect was sent from.
* @type {Guild}
*/
this.guild = guild;

/**
* The id of the channel the effect was sent in.
* @type {Snowflake}
*/
this.channelId = data.channel_id;

/**
* The id of the user that sent the effect.
* @type {Snowflake}
*/
this.userId = data.user_id;

/**
* The emoji of the effect.
* @type {?Emoji}
*/
this.emoji = data.emoji ? new Emoji(guild.client, data.emoji) : null;

/**
* The animation type of the effect.
* @type {?VoiceChannelEffectSendAnimationType}
*/
this.animationType = data.animation_type ?? null;

/**
* The animation id of the effect.
* @type {?number}
*/
this.animationId = data.animation_id ?? null;

/**
* The id of the soundboard sound for soundboard effects.
* @type {?(Snowflake|number)}
*/
this.soundId = data.sound_id ?? null;

/**
* The volume of the soundboard sound [0-1] for soundboard effects.
* @type {?number}
*/
this.soundVolume = data.sound_volume ?? null;
}

/**
* The channel the effect was sent in.
* @type {?VoiceChannel}
* @readonly
*/
get channel() {
return this.guild.channels.cache.get(this.channelId) ?? null;
}
}

module.exports = VoiceChannelEffect;
5 changes: 5 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/VideoQualityMode}
*/

/**
* @external VoiceChannelEffectSendAnimationType
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/VoiceChannelEffectSendAnimationType}
*/

/**
* @external WebhookType
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/WebhookType}
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/src/util/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
* @property {string} ThreadUpdate threadUpdate
* @property {string} TypingStart typingStart
* @property {string} UserUpdate userUpdate
* @property {string} VoiceChannelEffectSend voiceChannelEffectSend
* @property {string} VoiceServerUpdate voiceServerUpdate
* @property {string} VoiceStateUpdate voiceStateUpdate
* @property {string} Warn warn
Expand Down Expand Up @@ -154,6 +155,7 @@ module.exports = {
ThreadUpdate: 'threadUpdate',
TypingStart: 'typingStart',
UserUpdate: 'userUpdate',
VoiceChannelEffectSend: 'voiceChannelEffectSend',
VoiceServerUpdate: 'voiceServerUpdate',
VoiceStateUpdate: 'voiceStateUpdate',
Warn: 'warn',
Expand Down
Loading

0 comments on commit 1a36991

Please sign in to comment.