Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream Update (premiumSince) #29

Open
wants to merge 26 commits into
base: premiumSince
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1a6e043
feat(timeout): Timeout and Moderate Members permission (#1317)
bsian03 Jan 7, 2022
6ba5b05
fix(threads): nullable m.presence in THREAD_MEMBERS_UPDATE (#1306)
ZixeSea Feb 10, 2022
4c631f5
fix(typings): extra messageID param in Message#createThreadWithMessag…
frobinsonj Feb 10, 2022
6619b17
fix(Member): User property reference (#1313)
Feb 10, 2022
1a79ef6
fix(threads): pass guild when updating member on THREAD_MEMBERS_UPDAT…
GweeKwee Feb 10, 2022
4ca306d
fix(threads): Snake case discord payload owner id (#1326)
dd-pardal Feb 10, 2022
c6b380b
fix(interactions): static function client reference (#1334)
doomestee Feb 10, 2022
f4db90e
fix(docs): editStatus url type (#1337)
DonovanDMC Feb 10, 2022
98c5c8b
fix(typings): static keyword for Interaction.from (#1305)
bsian03 Feb 11, 2022
9a55be5
Fix missing file redirect in interaction createMessage (#1314)
bsian03 Feb 11, 2022
90fad3a
fix(interactions): Snake case defaultPermissions in payload (#1325)
bsian03 Feb 11, 2022
bb8a45e
Add position to `CreateChannelOptions` (#1340)
frobinsonj Mar 9, 2022
c1f1f86
Use maxShards instead of lastShardID (#1339)
GweeKwee Mar 9, 2022
072db2e
presence update ratelimit (#1345)
Awoocado Mar 9, 2022
52db153
fix(voice): avoid bitwise overflow error (#1323)
james58899 Mar 27, 2022
44dba49
chore(typings): reorganise (#1303)
bsian03 Apr 12, 2022
cb8971a
fix(typings): presence offline/invisible indicators
reinacchi Apr 13, 2022
a9b8ad4
fix(gateway): remove message listener on disconnect (#1364)
davidffa Apr 19, 2022
42e713b
fix(typings): Added "proxy_url" to EmbedVideo (#1361)
ray-1337 Apr 19, 2022
f163a56
fix(typings): Outdated channelCreate event typings (#1351)
May 10, 2022
b485352
fix(constants): Include manageThreads, manageEvents in Permissions.al…
eritbh May 10, 2022
c223725
fix(userUpdate): Uncached users throwing undefined (#1366)
Dramex May 10, 2022
017c18a
fix(deleteMessages): Pass reason param into subsequent calls (#1373)
DonovanDMC May 10, 2022
b7a1189
docs(Voice state): Update to new caveat URL (#1375)
frobinsonj May 15, 2022
2f7526a
fix(Message): Jumplink throwing on DM messages (#1359)
bsian03 May 27, 2022
e963166
feat(Permissions): Add bigint support for perm check (#1374)
bsian03 May 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
423 changes: 214 additions & 209 deletions index.d.ts

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ class Client extends EventEmitter {
* @arg {Boolean} [options.nsfw] The nsfw status of the channel
* @arg {String?} [options.parentID] The ID of the parent category channel for this channel
* @arg {Array} [options.permissionOverwrites] An array containing permission overwrite objects
* @arg {Number} [options.position] The sorting position of the channel
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (does not affect bots or users with manageMessages/manageChannel permissions) (text channels only)
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @arg {String} [options.topic] The topic of the channel (text channels only)
Expand Down Expand Up @@ -497,6 +498,7 @@ class Client extends EventEmitter {
nsfw: options.nsfw,
parent_id: options.parentID,
permission_overwrites: options.permissionOverwrites,
position: options.position,
rate_limit_per_user: options.rateLimitPerUser,
reason: options.reason,
topic: options.topic,
Expand Down Expand Up @@ -564,6 +566,7 @@ class Client extends EventEmitter {
}
}
}
command.default_permission = command.defaultPermission;
return this.requestHandler.request("POST", Endpoints.COMMANDS(this.application.id), true, command);
}

Expand Down Expand Up @@ -633,6 +636,7 @@ class Client extends EventEmitter {
}
}
}
command.default_permission = command.defaultPermission;
return this.requestHandler.request("POST", Endpoints.GUILD_COMMANDS(this.application.id, guildID), true, command);
}

Expand Down Expand Up @@ -1089,7 +1093,7 @@ class Client extends EventEmitter {
return Promise.resolve();
}
if(messageIDs.length === 1) {
return this.deleteMessage(channelID, messageIDs[0]);
return this.deleteMessage(channelID, messageIDs[0], reason);
}

const oldestAllowedSnowflake = (Date.now() - 1421280000000) * 4194304;
Expand All @@ -1102,7 +1106,7 @@ class Client extends EventEmitter {
return this.requestHandler.request("POST", Endpoints.CHANNEL_BULK_DELETE(channelID), true, {
messages: messageIDs.splice(0, 100),
reason: reason
}).then(() => this.deleteMessages(channelID, messageIDs));
}).then(() => this.deleteMessages(channelID, messageIDs, reason));
}
return this.requestHandler.request("POST", Endpoints.CHANNEL_BULK_DELETE(channelID), true, {
messages: messageIDs,
Expand Down Expand Up @@ -1237,6 +1241,7 @@ class Client extends EventEmitter {
* @arg {Boolean} [options.nsfw] The nsfw status of the channel (guild channels only)
* @arg {String} [options.ownerID] The ID of the channel owner (group channels only)
* @arg {String?} [options.parentID] The ID of the parent channel category for this channel (guild text/voice channels only)
* @arg {Number} [options.position] The sorting position of the channel (guild channels only)
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (does not affect bots or users with manageMessages/manageChannel permissions) (guild text and thread channels only)
* @arg {String?} [options.rtcRegion] The RTC region ID of the channel (automatic if `null`) (guild voice channels only)
* @arg {String} [options.topic] The topic of the channel (guild text channels only)
Expand All @@ -1258,6 +1263,7 @@ class Client extends EventEmitter {
nsfw: options.nsfw,
owner_id: options.ownerID,
parent_id: options.parentID,
position: options.position,
rate_limit_per_user: options.rateLimitPerUser,
rtc_region: options.rtcRegion,
topic: options.topic,
Expand Down Expand Up @@ -1350,6 +1356,7 @@ class Client extends EventEmitter {
}
}
}
command.default_permission = command.defaultPermission;
return this.requestHandler.request("PATCH", Endpoints.COMMAND(this.application.id, commandID), true, command);
}

Expand Down Expand Up @@ -1442,6 +1449,7 @@ class Client extends EventEmitter {
}
}
}
command.default_permission = command.defaultPermission;
return this.requestHandler.request("PATCH", Endpoints.GUILD_COMMAND(this.application.id, guildID, commandID), true, command);
}

Expand Down Expand Up @@ -1503,6 +1511,7 @@ class Client extends EventEmitter {
* @arg {String} memberID The ID of the member (you can use "@me" if you are only editing the bot user's nickname)
* @arg {Object} options The properties to edit
* @arg {String?} [options.channelID] The ID of the voice channel to move the member to (must be in voice). Set to `null` to disconnect the member
* @arg {Date?} [options.communicationDisabledUntil] When the user's timeout should expire. Set to `null` to instantly remove timeout
* @arg {Boolean} [options.deaf] Server deafen the member
* @arg {Boolean} [options.mute] Server mute the member
* @arg {String} [options.nick] Set the member's server nickname, "" to remove
Expand All @@ -1517,6 +1526,7 @@ class Client extends EventEmitter {
mute: options.mute,
deaf: options.deaf,
channel_id: options.channelID,
communication_disabled_until: options.communicationDisabledUntil,
reason: reason
}).then((member) => new Member(member, this.guilds.get(guildID), this));
}
Expand Down Expand Up @@ -1561,7 +1571,7 @@ class Client extends EventEmitter {
});
}
/**
* Update a user's voice state - See [caveats](https://discord.com/developers/docs/resources/guild#update-others-voice-state-caveats)
* Update a user's voice state - See [caveats](https://discord.com/developers/docs/resources/guild#modify-user-voice-state-caveats)
* @arg {String} guildID The ID of the guild
* @arg {Object} options The properties to edit
* @arg {String} options.channelID The ID of the channel the user is currently in
Expand Down Expand Up @@ -1846,8 +1856,7 @@ class Client extends EventEmitter {
* @arg {Array | Object} [activities] Sets the bot's activities. A single activity object is also accepted for backwards compatibility
* @arg {String} activities[].name The name of the activity
* @arg {Number} activities[].type The type of the activity. 0 is playing, 1 is streaming (Twitch only), 2 is listening, 3 is watching, 5 is competing in
* @arg {Number} [activities[].url] The URL of the activity
* @arg {String} [game.url] Sets the url of the shard's active game
* @arg {String} [activities[].url] The URL of the activity
*/
editStatus(status, activities) {
if(activities === undefined && typeof status === "object") {
Expand Down
8 changes: 6 additions & 2 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ const Permissions = {
createPrivateThreads: 1n << 36n,
useExternalStickers: 1n << 37n,
sendMessagesInThreads: 1n << 38n,
startEmbeddedActivities: 1n << 39n
startEmbeddedActivities: 1n << 39n,
moderateMembers: 1n << 40n
};
Permissions.allGuild = Permissions.kickMembers
| Permissions.banMembers
Expand All @@ -394,7 +395,9 @@ Permissions.allGuild = Permissions.kickMembers
| Permissions.manageNicknames
| Permissions.manageRoles
| Permissions.manageWebhooks
| Permissions.manageEmojisAndStickers;
| Permissions.manageEmojisAndStickers
| Permissions.manageEvents
| Permissions.moderateMembers;
Permissions.allText = Permissions.createInstantInvite
| Permissions.manageChannels
| Permissions.addReactions
Expand All @@ -410,6 +413,7 @@ Permissions.allText = Permissions.createInstantInvite
| Permissions.manageRoles
| Permissions.manageWebhooks
| Permissions.useApplicationCommands
| Permissions.manageThreads
| Permissions.createPublicThreads
| Permissions.createPrivateThreads
| Permissions.useExternalStickers
Expand Down
33 changes: 21 additions & 12 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class Shard extends EventEmitter {
}

if(this.ws.readyState !== WebSocket.CLOSED) {
this.ws.removeListener("message", this._onWSMessage);
this.ws.removeListener("close", this._onWSClose);
try {
if(options.reconnect && this.sessionID) {
Expand Down Expand Up @@ -213,7 +214,7 @@ class Shard extends EventEmitter {
* @arg {Array | Object} [activities] Sets the bot's activities. A single activity object is also accepted for backwards compatibility
* @arg {String} activities[].name The name of the activity
* @arg {Number} activities[].type The type of the activity. 0 is playing, 1 is streaming (Twitch only), 2 is listening, 3 is watching, 5 is competing in
* @arg {Number} [activities[].url] The URL of the activity
* @arg {String} [activities[].url] The URL of the activity
*/
editStatus(status, activities) {
if(activities === undefined && typeof status === "object") {
Expand Down Expand Up @@ -278,7 +279,7 @@ class Shard extends EventEmitter {
this.heartbeatInterval = null;
this.guildCreateTimeout = null;
this.globalBucket = new Bucket(120, 60000, {reservedTokens: 5});
this.presenceUpdateBucket = new Bucket(5, 60000);
this.presenceUpdateBucket = new Bucket(5, 20000);
this.presence = JSON.parse(JSON.stringify(this.client.presence)); // Fast copy
Object.defineProperty(this, "_token", {
configurable: true,
Expand Down Expand Up @@ -620,7 +621,7 @@ class Shard extends EventEmitter {
* Fired when a user's avatar, discriminator or username changes
* @event Client#userUpdate
* @prop {User} user The updated user
* @prop {Object?} oldUser The old user data
* @prop {Object?} oldUser The old user data. If the user was uncached, this will be null
* @prop {String} oldUser.username The username of the user
* @prop {String} oldUser.discriminator The discriminator of the user
* @prop {String?} oldUser.avatar The hash of the user's avatar, or null if no avatar
Expand Down Expand Up @@ -1144,6 +1145,7 @@ class Shard extends EventEmitter {
if(member) {
oldMember = {
avatar: member.avatar,
communicationDisabledUntil: member.communicationDisabledUntil,
roles: member.roles,
nick: member.nick,
premiumSince: member.premiumSince,
Expand All @@ -1158,6 +1160,7 @@ class Shard extends EventEmitter {
* @prop {Member} member The updated member
* @prop {Object?} oldMember The old member data, or null if the member wasn't cached
* @prop {String?} oldMember.avatar The hash of the member's guild avatar, or null if no guild avatar
* @prop {Number?} communicationDisabledUntil Timestamp of previous timeout expiry. If `null`, the member was not timed out
* @prop {Array<String>} oldMember.roles An array of role IDs this member is a part of
* @prop {String?} oldMember.nick The server nickname of the member
* @prop {Number} oldMember.premiumSince Timestamp of when the member boosted the guild
Expand Down Expand Up @@ -1956,13 +1959,17 @@ class Shard extends EventEmitter {
break;
}
case "USER_UPDATE": {
const user = this.client.users.get(packet.d.id);
const oldUser = {
username: user.username,
discriminator: user.discriminator,
avatar: user.avatar
};
this.emit("userUpdate", user.update(packet.d), oldUser);
let user = this.client.users.get(packet.d.id);
let oldUser = null;
if(user) {
oldUser = {
username: user.username,
discriminator: user.discriminator,
avatar: user.avatar
};
}
user = this.client.users.update(packet.d, this.client);
this.emit("userUpdate", user, oldUser);
break;
}
case "RELATIONSHIP_ADD": {
Expand Down Expand Up @@ -2243,8 +2250,10 @@ class Shard extends EventEmitter {
m.member.id = m.member.user.id;
const guild = this.client.guilds.get(packet.d.guild_id);
if(guild) {
guild.members.update(m.presence, guild);
guild.members.update(m.member);
if(m.presence) {
guild.members.update(m.presence, guild);
}
guild.members.update(m.member, guild);
}
return channel.members.update(m, this.client);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class CommandInteraction extends Interaction {
*/
async createMessage(content, file) {
if(this.acknowledged === true) {
return this.createFollowup(content);
return this.createFollowup(content, file);
}
if(content !== undefined) {
if(typeof content !== "object" || content === null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/ComponentInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class ComponentInteraction extends Interaction {
*/
async createMessage(content, file) {
if(this.acknowledged === true) {
return this.createFollowup(content);
return this.createFollowup(content, file);
}
if(content !== undefined) {
if(typeof content !== "object" || content === null) {
Expand Down
6 changes: 4 additions & 2 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Guild extends Base {
constructor(data, client) {
super(data.id);
this._client = client;
this.shard = client.shards.get(client.guildShardMap[this.id] || (Base.getDiscordEpoch(data.id) % client.options.lastShardID) || 0);
this.shard = client.shards.get(client.guildShardMap[this.id] || (Base.getDiscordEpoch(data.id) % client.options.maxShards) || 0);
this.unavailable = !!data.unavailable;
this.joinedAt = Date.parse(data.joined_at);
this.voiceStates = new Collection(VoiceState);
Expand Down Expand Up @@ -393,6 +393,7 @@ class Guild extends Base {
* @arg {Boolean} [options.nsfw] The nsfw status of the channel
* @arg {String?} [options.parentID] The ID of the parent category channel for this channel
* @arg {Array} [options.permissionOverwrites] An array containing permission overwrite objects
* @arg {Number} [options.position] The sorting position of the channel
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (does not affect bots or users with manageMessages/manageChannel permissions) (text channels only)
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @arg {String} [options.topic] The topic of the channel (text channels only)
Expand Down Expand Up @@ -685,6 +686,7 @@ class Guild extends Base {
* @arg {String} memberID The ID of the member (use "@me" to edit the current bot user)
* @arg {Object} options The properties to edit
* @arg {String?} [options.channelID] The ID of the voice channel to move the member to (must be in voice). Set to `null` to disconnect the member
* @arg {Date?} [options.communicationDisabledUntil] When the user's timeout should expire. Set to `null` to instantly remove timeout
* @arg {Boolean} [options.deaf] Server deafen the member
* @arg {Boolean} [options.mute] Server mute the member
* @arg {String} [options.nick] Set the member's guild nickname, "" to remove
Expand Down Expand Up @@ -759,7 +761,7 @@ class Guild extends Base {
}

/**
* Update a user's voice state - See [caveats](https://discord.com/developers/docs/resources/guild#update-others-voice-state-caveats)
* Update a user's voice state - See [caveats](https://discord.com/developers/docs/resources/guild#modify-user-voice-state-caveats)
* @arg {Object} options The properties to edit
* @arg {String} options.channelID The ID of the channel the user is currently in
* @arg {Date?} [options.requestToSpeakTimestamp] Sets the user's request to speak - this can only be used when the `userID` param is "@me"
Expand Down
11 changes: 6 additions & 5 deletions lib/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@ class GuildChannel extends Channel {
* @arg {Object} options The properties to edit
* @arg {Boolean} [options.archived] The archive status of the channel (thread channels only)
* @arg {Number} [options.autoArchiveDuration] The duration in minutes to automatically archive the thread after recent activity, either 60, 1440, 4320 or 10080 (thread channels only)
* @arg {Number} [options.bitrate] The bitrate of the channel (guild voice channels only)
* @arg {Number?} [options.defaultAutoArchiveDuration] The default duration of newly created threads in minutes to automatically archive the thread after inactivity (60, 1440, 4320, 10080) (guild text/news channels only)
* @arg {Boolean} [options.invitable] Whether non-moderators can add other non-moderators to the channel (private thread channels only)
* @arg {Boolean} [options.locked] The lock status of the channel (thread channels only)
* @arg {String} [options.name] The name of the channel
* @arg {Boolean} [options.nsfw] The nsfw status of the channel
* @arg {Number?} [options.parentID] The ID of the parent channel category for this channel (guild text/voice channels only) or the channel ID where the thread originated from (thread channels only)
* @arg {Number} [options.position] The sorting position of the channel
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (does not affect bots or users with manageMessages/manageChannel permissions) (guild text and thread channels only)
* @arg {String?} [options.rtcRegion] The RTC region ID of the channel (automatic if `null`) (guild voice channels only)
* @arg {String} [options.topic] The topic of the channel (guild text channels only)
* @arg {Number} [options.bitrate] The bitrate of the channel (guild voice channels only)
* @arg {Number} [options.userLimit] The channel user limit (guild voice channels only)
* @arg {Number} [options.videoQualityMode] The camera video quality mode of the channel (guild voice channels only). `1` is auto, `2` is 720p
* @arg {Number} [options.rateLimitPerUser] The time in seconds a user has to wait before sending another message (does not affect bots or users with manageMessages/manageChannel permissions) (guild text and thread channels only)
* @arg {String?} [options.rtcRegion] The RTC region ID of the channel (automatic if `null`) (guild voice channels only)
* @arg {Boolean} [options.nsfw] The nsfw status of the channel
* @arg {Number?} [options.parentID] The ID of the parent channel category for this channel (guild text/voice channels only) or the channel ID where the thread originated from (thread channels only)
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<CategoryChannel | GroupChannel | TextChannel | VoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Interaction extends Base {
}
}

this._client.emit("warn", new Error(`Unknown interaction type: ${data.type}\n${JSON.stringify(data)}`));
client.emit("warn", new Error(`Unknown interaction type: ${data.type}\n${JSON.stringify(data)}`));
return new UnknownInteraction(data, client);
}
}
Expand Down
Loading