|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const Base = require('./Base'); |
| 4 | + |
| 5 | +/** |
| 6 | + * Represents a soundboard sound. |
| 7 | + * @extends {Base} |
| 8 | + */ |
| 9 | +class SoundboardSound extends Base { |
| 10 | + constructor(client, data) { |
| 11 | + super(client); |
| 12 | + |
| 13 | + /** |
| 14 | + * The id of the soundboard sound |
| 15 | + * @type {Snowflake|number} |
| 16 | + */ |
| 17 | + this.soundId = data.sound_id; |
| 18 | + |
| 19 | + this._patch(data); |
| 20 | + } |
| 21 | + |
| 22 | + _patch(data) { |
| 23 | + /** |
| 24 | + * Whether this soundboard sound is available |
| 25 | + * @type {boolean} |
| 26 | + */ |
| 27 | + this.available = data.available; |
| 28 | + |
| 29 | + /** |
| 30 | + * The name of the soundboard sound |
| 31 | + * @type {string} |
| 32 | + */ |
| 33 | + this.name = data.name; |
| 34 | + |
| 35 | + /** |
| 36 | + * The volume of the soundboard sound |
| 37 | + * @type {number} |
| 38 | + */ |
| 39 | + this.volume = data.volume; |
| 40 | + |
| 41 | + if ('emoji_id' in data) { |
| 42 | + /** |
| 43 | + * The emoji id of the soundboard sound |
| 44 | + * @type {?Snowflake} |
| 45 | + */ |
| 46 | + this.emojiId = data.emojiId; |
| 47 | + } else { |
| 48 | + this.emojiId ??= null; |
| 49 | + } |
| 50 | + |
| 51 | + if ('emoji_name' in data) { |
| 52 | + /** |
| 53 | + * The emoji name of the soundboard sound |
| 54 | + * @type {?string} |
| 55 | + */ |
| 56 | + this.emojiName = data.emojiName; |
| 57 | + } else { |
| 58 | + this.emojiName ??= null; |
| 59 | + } |
| 60 | + |
| 61 | + if ('guild_id' in data) { |
| 62 | + /** |
| 63 | + * The guild id of the soundboard sound |
| 64 | + * @type {?Snowflake} |
| 65 | + */ |
| 66 | + this.guildId = data.guildId; |
| 67 | + } else { |
| 68 | + this.guildId ??= null; |
| 69 | + } |
| 70 | + |
| 71 | + if ('user' in data) { |
| 72 | + /** |
| 73 | + * The user who created this soundboard sound |
| 74 | + * @type {?User} |
| 75 | + */ |
| 76 | + this.user = this.client.users._add(data.user); |
| 77 | + } else { |
| 78 | + this.user ??= null; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * The guild this soundboard sound is part of |
| 84 | + * @type {?Guild} |
| 85 | + * @readonly |
| 86 | + */ |
| 87 | + get guild() { |
| 88 | + return this.client.guilds.resolve(this.guildId); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Whether this soundboard sound is the same as another one. |
| 93 | + * @param {SoundboardSound|APISoundboardSound} other The soundboard sound to compare it to |
| 94 | + * @returns {boolean} |
| 95 | + */ |
| 96 | + equals(other) { |
| 97 | + if (other instanceof SoundboardSound) { |
| 98 | + return ( |
| 99 | + this.id === other.id && |
| 100 | + this.name === other.name && |
| 101 | + this.volume === other.volume && |
| 102 | + this.emojiId === other.emojiId && |
| 103 | + this.emojiName === other.emojiName && |
| 104 | + this.guildId === other.guildId && |
| 105 | + this.user?.id === other.user?.id |
| 106 | + ); |
| 107 | + } |
| 108 | + |
| 109 | + return ( |
| 110 | + this.id === other.sound_id && |
| 111 | + this.name === other.name && |
| 112 | + this.volume === other.volume && |
| 113 | + this.emojiId === other.emoji_id && |
| 114 | + this.emojiName === other.emoji_name && |
| 115 | + this.guildId === other.guild_id && |
| 116 | + this.user?.id === other.user?.id |
| 117 | + ); |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +exports.SoundboardSound = SoundboardSound; |
0 commit comments