Skip to content

Commit

Permalink
feat(timeout): Timeout and Moderate Members permission (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 authored Jan 7, 2022
1 parent 29a3a63 commit 1a6e043
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
8 changes: 6 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ declare namespace Eris {
}
interface OldMember {
avatar: string | null;
communicationDisabledUntil: number | null;
nick: string | null;
pending?: boolean;
premiumSince: number;
Expand Down Expand Up @@ -1033,6 +1034,7 @@ declare namespace Eris {
}
interface MemberOptions {
channelID?: string | null;
communicationDisabledUntil?: Date | null;
deaf?: boolean;
mute?: boolean;
nick?: string | null;
Expand Down Expand Up @@ -1803,10 +1805,11 @@ declare namespace Eris {
useExternalStickers: 137438953472n;
sendMessagesInThreads: 274877906944n;
startEmbeddedActivities: 549755813888n;
allGuild: 2080899262n;
moderateMembers: 1099511627776n;
allGuild: 1101592527038n;
allText: 518349388881n;
allVoice: 554385278737n;
all: 1073741823999n;
all: 1228360646655n;
};
PremiumTiers: {
NONE: 0;
Expand Down Expand Up @@ -3029,6 +3032,7 @@ declare namespace Eris {
bannerURL: string | null;
bot: boolean;
clientStatus?: ClientStatus;
communicationDisabledUntil: number | null;
createdAt: number;
defaultAvatar: string;
defaultAvatarURL: string;
Expand Down
2 changes: 2 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,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 +1518,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
6 changes: 4 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,8 @@ Permissions.allGuild = Permissions.kickMembers
| Permissions.manageNicknames
| Permissions.manageRoles
| Permissions.manageWebhooks
| Permissions.manageEmojisAndStickers;
| Permissions.manageEmojisAndStickers
| Permissions.moderateMembers;
Permissions.allText = Permissions.createInstantInvite
| Permissions.manageChannels
| Permissions.addReactions
Expand Down
2 changes: 2 additions & 0 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,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 +1159,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
1 change: 1 addition & 0 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,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
10 changes: 10 additions & 0 deletions lib/structures/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const VoiceState = require("./VoiceState");
* @prop {String} clientStatus.web The member's status on web. Either "online", "idle", "dnd", or "offline". Will be "online" for bots
* @prop {String} clientStatus.desktop The member's status on desktop. Either "online", "idle", "dnd", or "offline". Will be "offline" for bots
* @prop {String} clientStatus.mobile The member's status on mobile. Either "online", "idle", "dnd", or "offline". Will be "offline" for bots
* @prop {Number?} communicationDisabledUntil Timestamp of timeout expiry. If `null`, the member is not timed out
* @prop {Number} createdAt Timestamp of user creation
* @prop {String} defaultAvatar The hash for the default avatar of a user if there is no avatar set
* @prop {String} defaultAvatarURL The URL of the user's default avatar
Expand Down Expand Up @@ -105,6 +106,13 @@ class Member extends Base {
if(data.avatar !== undefined) {
this.avatar = data.avatar;
}
if(data.communication_disabled_until !== undefined) {
if(data.communication_disabled_until !== null) {
this.communicationDisabledUntil = Date.parse(data.communication_disabled_until);
} else {
this.communicationDisabledUntil = data.communication_disabled_until;
}
}
}

get accentColor() {
Expand Down Expand Up @@ -202,6 +210,7 @@ class Member extends Base {
* Edit the guild member
* @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 user
* @arg {Boolean} [options.mute] Server mute the user
* @arg {String} [options.nick] Set the user's server nickname, "" to remove
Expand Down Expand Up @@ -244,6 +253,7 @@ class Member extends Base {
toJSON(props = []) {
return super.toJSON([
"activities",
"communicationDisabledUntil",
"joinedAt",
"nick",
"pending",
Expand Down

0 comments on commit 1a6e043

Please sign in to comment.