-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2df0e0
commit 2ef1a3a
Showing
16 changed files
with
340 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/discord.js/src/client/actions/GuildSoundboardSoundCreate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const Action = require('./Action'); | ||
const Events = require('../../util/Events'); | ||
|
||
class GuildSoundboardSoundCreateAction extends Action { | ||
handle(data) { | ||
const guild = this.client.guilds.cache.get(data.guild_id); | ||
|
||
let soundboardSound; | ||
|
||
if (guild) { | ||
const already = guild.soundboardSounds.cache.has(data.sound_id); | ||
|
||
soundboardSound = guild.soundboardSounds._add(data); | ||
|
||
/** | ||
* Emitted whenever a soundboard sound is created in a guild. | ||
* @event Client#guildSoundboardSoundCreate | ||
* @param {SoundboardSound} soundboardSound The soundboard sound that was created | ||
*/ | ||
if (!already) this.client.emit(Events.GuildSoundboardSoundCreate, soundboardSound); | ||
} | ||
|
||
return { soundboardSound }; | ||
} | ||
} | ||
|
||
module.exports = GuildSoundboardSoundCreateAction; |
29 changes: 29 additions & 0 deletions
29
packages/discord.js/src/client/actions/GuildSoundboardSoundDelete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const Action = require('./Action'); | ||
const Events = require('../../util/Events'); | ||
|
||
class GuildSoundboardSoundDeleteAction extends Action { | ||
handle(data) { | ||
const guild = this.client.guilds.cache.get(data.guild_id); | ||
|
||
let soundboardSound; | ||
|
||
if (guild) { | ||
soundboardSound = guild.soundboardSounds.cache._add(data, false); | ||
|
||
guild.soundboardSounds.cache.delete(soundboardSound.id); | ||
|
||
/** | ||
* Emitted whenever a soundboard sound is deleted in a guild. | ||
* @event Client#guildSoundboardSoundDelete | ||
* @param {SoundboardSound} soundboardSound The soundboard sound that was deleted | ||
*/ | ||
this.client.emit(Events.GuildSoundboardSoundDelete, soundboardSound); | ||
} | ||
|
||
return { soundboardSound }; | ||
} | ||
} | ||
|
||
module.exports = GuildSoundboardSoundDeleteAction; |
34 changes: 34 additions & 0 deletions
34
packages/discord.js/src/client/actions/GuildSoundboardSoundUpdate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const Action = require('./Action'); | ||
const Events = require('../../util/Events'); | ||
|
||
class GuildSoundboardSoundUpdateAction extends Action { | ||
handle(data) { | ||
const guild = this.client.guilds.cache.get(data.guild_id); | ||
|
||
if (guild) { | ||
let oldSoundboardSound = null; | ||
|
||
const newSoundboardSound = guild.soundboardSounds.cache.get(data.sound_id); | ||
|
||
if (newSoundboardSound) { | ||
oldSoundboardSound = newSoundboardSound._update(data); | ||
|
||
/** | ||
* Emitted whenever a soundboard sound is updated in a guild. | ||
* @event Client#guildSoundboardSoundUpdate | ||
* @param {?SoundboardSound} oldSoundboardSound The soundboard sound before the update | ||
* @param {SoundboardSound} newSoundboardSound The soundboard sound after the update | ||
*/ | ||
this.client.emit(Events.GuildSoundboardSoundUpdate, oldSoundboardSound, newSoundboardSound); | ||
} | ||
|
||
return { oldSoundboardSound, newSoundboardSound }; | ||
} | ||
|
||
return { oldSoundboardSound: null, newSoundboardSound: null }; | ||
} | ||
} | ||
|
||
module.exports = GuildSoundboardSoundUpdateAction; |
5 changes: 5 additions & 0 deletions
5
packages/discord.js/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (client, { d: data }) => { | ||
client.actions.GuildSoundboardSoundCreate.handle(data); | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/discord.js/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (client, { d: data }) => { | ||
client.actions.GuildSoundboardSoundDelete.handle(data); | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/discord.js/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (client, { d: data }) => { | ||
client.actions.GuildSoundboardSoundUpdate.handle(data); | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/discord.js/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const { Collection } = require('@discordjs/collection'); | ||
const Events = require('../../../util/Events'); | ||
|
||
module.exports = (client, { d: data }) => { | ||
const guild = client.guilds.cache.get(data.guild_id); | ||
|
||
if (!guild) return; | ||
|
||
const soundboardSounds = new Collection(); | ||
|
||
for (const soundboardSound of data.soundboard_sounds) { | ||
soundboardSounds.set(soundboardSound.sound_id, guild.soundboardSounds._add(soundboardSound)); | ||
} | ||
|
||
/** | ||
* Emitted whenever soundboard sounds are received (all soundboard sounds come from the same guild). | ||
* @event Client#soundboardSounds | ||
* @param {Collection<Snowflake, SoundboardSound>} soundboardSounds The sounds received | ||
* @param {Guild} guild The guild related to the soundboard sounds | ||
*/ | ||
client.emit(Events.SoundboardSounds, soundboardSounds, guild); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
'use strict'; | ||
|
||
const Base = require('./Base'); | ||
|
||
/** | ||
* Represents a soundboard sound. | ||
* @extends {Base} | ||
*/ | ||
class SoundboardSound extends Base { | ||
constructor(client, data) { | ||
super(client); | ||
|
||
/** | ||
* The id of the soundboard sound | ||
* @type {Snowflake|number} | ||
*/ | ||
this.soundId = data.sound_id; | ||
|
||
this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** | ||
* Whether this soundboard sound is available | ||
* @type {boolean} | ||
*/ | ||
this.available = data.available; | ||
|
||
/** | ||
* The name of the soundboard sound | ||
* @type {string} | ||
*/ | ||
this.name = data.name; | ||
|
||
/** | ||
* The volume of the soundboard sound | ||
* @type {number} | ||
*/ | ||
this.volume = data.volume; | ||
|
||
if ('emoji_id' in data) { | ||
/** | ||
* The emoji id of the soundboard sound | ||
* @type {?Snowflake} | ||
*/ | ||
this.emojiId = data.emojiId; | ||
} else { | ||
this.emojiId ??= null; | ||
} | ||
|
||
if ('emoji_name' in data) { | ||
/** | ||
* The emoji name of the soundboard sound | ||
* @type {?string} | ||
*/ | ||
this.emojiName = data.emojiName; | ||
} else { | ||
this.emojiName ??= null; | ||
} | ||
|
||
if ('guild_id' in data) { | ||
/** | ||
* The guild id of the soundboard sound | ||
* @type {?Snowflake} | ||
*/ | ||
this.guildId = data.guildId; | ||
} else { | ||
this.guildId ??= null; | ||
} | ||
|
||
if ('user' in data) { | ||
/** | ||
* The user who created this soundboard sound | ||
* @type {?User} | ||
*/ | ||
this.user = this.client.users._add(data.user); | ||
} else { | ||
this.user ??= null; | ||
} | ||
} | ||
|
||
/** | ||
* The guild this soundboard sound is part of | ||
* @type {?Guild} | ||
* @readonly | ||
*/ | ||
get guild() { | ||
return this.client.guilds.resolve(this.guildId); | ||
} | ||
|
||
/** | ||
* Whether this soundboard sound is the same as another one. | ||
* @param {SoundboardSound|APISoundboardSound} other The soundboard sound to compare it to | ||
* @returns {boolean} | ||
*/ | ||
equals(other) { | ||
if (other instanceof SoundboardSound) { | ||
return ( | ||
this.id === other.id && | ||
this.name === other.name && | ||
this.volume === other.volume && | ||
this.emojiId === other.emojiId && | ||
this.emojiName === other.emojiName && | ||
this.guildId === other.guildId && | ||
this.user?.id === other.user?.id | ||
); | ||
} | ||
|
||
return ( | ||
this.id === other.sound_id && | ||
this.name === other.name && | ||
this.volume === other.volume && | ||
this.emojiId === other.emoji_id && | ||
this.emojiName === other.emoji_name && | ||
this.guildId === other.guild_id && | ||
this.user?.id === other.user?.id | ||
); | ||
} | ||
} | ||
|
||
exports.SoundboardSound = SoundboardSound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.