Skip to content

Commit

Permalink
feat(bans): Seconds Support (#1430)
Browse files Browse the repository at this point in the history
Co-authored-by: Donovan Daniels <hewwo@yiff.rocks>
  • Loading branch information
bsian03 and DonovanDMC authored Jan 7, 2024
1 parent 6ca661c commit bd88d30
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
12 changes: 12 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,12 @@ declare namespace Eris {
deaf?: boolean;
mute?: boolean;
}
interface BanMemberOptions {
/** @deprecated */
deleteMessageDays?: number;
deleteMessageSeconds?: number;
reason?: string;
}
interface CreateGuildOptions {
afkChannelID?: string;
afkTimeout?: number;
Expand Down Expand Up @@ -2265,6 +2271,8 @@ declare namespace Eris {
addMessageReaction(channelID: string, messageID: string, reaction: string, userID: string): Promise<void>;
addRelationship(userID: string, block?: boolean): Promise<void>;
addSelfPremiumSubscription(token: string, plan: string): Promise<void>;
banGuildMember(guildID: string, userID: string, options?: BanMemberOptions): Promise<void>;
/** @deprecated */
banGuildMember(guildID: string, userID: string, deleteMessageDays?: number, reason?: string): Promise<void>;
bulkEditCommandPermissions(guildID: string, permissions: { id: string; permissions: ApplicationCommandPermissions[] }[]): Promise<GuildApplicationCommandPermissions[]>;
bulkEditCommands(commands: ApplicationCommandStructure[]): Promise<ApplicationCommand[]>;
Expand Down Expand Up @@ -2831,6 +2839,8 @@ declare namespace Eris {
addDiscoverySubcategory(categoryID: string, reason?: string): Promise<DiscoverySubcategoryResponse>;
addMember(userID: string, accessToken: string, options?: AddGuildMemberOptions): Promise<void>;
addMemberRole(memberID: string, roleID: string, reason?: string): Promise<void>;
banMember(userID: string, options?: BanMemberOptions): Promise<void>;
/** @deprecated */
banMember(userID: string, deleteMessageDays?: number, reason?: string): Promise<void>;
bulkEditCommands(commands: ApplicationCommandStructure[]): Promise<ApplicationCommand[]>;
createChannel(name: string): Promise<TextChannel>;
Expand Down Expand Up @@ -3275,6 +3285,8 @@ declare namespace Eris {
voiceState: VoiceState;
constructor(data: BaseData, guild?: Guild, client?: Client);
addRole(roleID: string, reason?: string): Promise<void>;
ban(options?: BanMemberOptions): Promise<void>;
/** @deprecated */
ban(deleteMessageDays?: number, reason?: string): Promise<void>;
dynamicAvatarURL(format?: ImageFormat, size?: number): string;
edit(options: MemberOptions, reason?: string): Promise<void>;
Expand Down
38 changes: 25 additions & 13 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,29 @@ class Client extends EventEmitter {
* Ban a user from a guild
* @arg {String} guildID The ID of the guild
* @arg {String} userID The ID of the user
* @arg {Number} [deleteMessageDays=0] Number of days to delete messages for, between 0-7 inclusive
* @arg {String} [reason] The reason to be displayed in audit logs
* @arg {Number} [options.deleteMessageDays=0] [DEPRECATED] Number of days to delete messages for, between 0-7 inclusive
* @arg {Number} [options.deleteMessageSeconds=0] Number of seconds to delete messages for, between 0 and 604800 inclusive
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @arg {String} [reason] [DEPRECATED] The reason to be displayed in audit logs
* @returns {Promise}
*/
banGuildMember(guildID, userID, deleteMessageDays, reason) {
if(!isNaN(deleteMessageDays) && (deleteMessageDays < 0 || deleteMessageDays > 7)) {
return Promise.reject(new Error(`Invalid deleteMessageDays value (${deleteMessageDays}), should be a number between 0-7 inclusive`));
banGuildMember(guildID, userID, options, reason) {
if(!options || typeof options !== "object") {
options = {
deleteMessageDays: options
};
}
if(reason !== undefined) {
options.reason = reason;
}
if(options.deleteMessageDays && !isNaN(options.deleteMessageDays) && !Object.hasOwnProperty.call(options, "deleteMessageSeconds")) {
options.deleteMessageSeconds = options.deleteMessageDays * 24 * 60 * 60;
emitDeprecation("DELETE_MESSAGE_DAYS");
this.emit("warn", "[DEPRECATED] banGuildMember() was called with the deleteMessageDays argument");
}
return this.requestHandler.request("PUT", Endpoints.GUILD_BAN(guildID, userID), true, {
delete_message_days: deleteMessageDays || 0,
reason: reason
delete_message_seconds: options.deleteMessageSeconds || 0,
reason: options.reason
});
}

Expand Down Expand Up @@ -831,7 +843,7 @@ class Client extends EventEmitter {
options.data.embeds.push(options.data.embed);
}
if(file) {
options = { payload_json: options }
options = {payload_json: options};
}
return this.requestHandler.request("POST", Endpoints.INTERACTION_RESPOND(interactionID, interactionToken), true, options, file, "/interactions/:id/:token/callback");
}
Expand Down Expand Up @@ -1849,7 +1861,7 @@ class Client extends EventEmitter {
}
}
const file = content.file;
delete content.file
delete content.file;
return this.requestHandler.request("PATCH", Endpoints.CHANNEL_MESSAGE(channelID, messageID), true, file ? {payload_json: content} : content, file).then((message) => new Message(message, this));
}

Expand Down Expand Up @@ -2244,12 +2256,12 @@ class Client extends EventEmitter {
delete options.file;

if(options.embed) {
if(!data.embeds) {
data.embeds = [];
if(!options.embeds) {
options.embeds = [];
}
data.embeds.push(options.embed);
options.embeds.push(options.embed);
}
options.avatar_url = options.avatarURL
options.avatar_url = options.avatarURL;
return this.requestHandler.request("POST", Endpoints.WEBHOOK_TOKEN(webhookID, token) + (qs ? "?" + qs : ""), !!options.auth, options.file ? {payload_json: options} : options, file).then((response) => options.wait ? new Message(response, this) : undefined);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,14 @@ class Guild extends Base {
/**
* Ban a user from the guild
* @arg {String} userID The ID of the member
* @arg {Number} [deleteMessageDays=0] Number of days to delete messages for, between 0-7 inclusive
* @arg {String} [reason] Reason for the ban
* @arg {Number} [options.deleteMessageDays=0] [DEPRECATED] Number of days to delete messages for, between 0-7 inclusive
* @arg {Number} [options.deleteMessageSeconds=0] Number of seconds to delete messages for, between 0 and 604,800 inclusive
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @arg {String} [reason] [DEPRECATED] The reason to be displayed in audit logs
* @returns {Promise}
*/
banMember(userID, deleteMessageDays, reason) {
return this._client.banGuildMember.call(this._client, this.id, userID, deleteMessageDays, reason);
banMember(userID, options, reason) {
return this._client.banGuildMember.call(this._client, this.id, userID, options, reason);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions lib/structures/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,14 @@ class Member extends Base {

/**
* Ban the user from the guild
* @arg {Number} [deleteMessageDays=0] Number of days to delete messages for, between 0-7 inclusive
* @arg {String} [reason] The reason to be displayed in audit logs
* @arg {Number} [options.deleteMessageDays=0] [DEPRECATED] Number of days to delete messages for, between 0-7 inclusive
* @arg {Number} [options.deleteMessageSeconds=0] Number of seconds to delete messages for, between 0 and 604,800 inclusive
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @arg {String} [reason] [DEPRECATED] The reason to be displayed in audit logs
* @returns {Promise}
*/
ban(deleteMessageDays, reason) {
return this.guild.shard.client.banGuildMember.call(this.guild.shard.client, this.guild.id, this.id, deleteMessageDays, reason);
ban(options, reason) {
return this.guild.shard.client.banGuildMember.call(this.guild.shard.client, this.guild.id, this.id, options, reason);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/util/emitDeprecation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const warningMessages = {
CREATE_CHANNEL_OPTIONS: "Passing parentID or reason string arguments directly to createChannel() is deprecated. Use an options object instead.",
DELETE_MESSAGE_DAYS: "Passing the deleteMessageDays parameter to banGuildMember is deprecated. Use an options object with deleteMessageSeconds instead.",
DM_REACTION_REMOVE: "Passing a userID when using removeMessageReaction() in a PrivateChannel is deprecated. This behavior is no longer supported by Discord.",
GET_REACTION_BEFORE: "Passing the before parameter to getMessageReaction() is deprecated. Discord no longer supports this parameter.",
MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead.",
Expand Down

0 comments on commit bd88d30

Please sign in to comment.