From fcf8c60cca8a4988d1997555691e8ce9e43a3525 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Fri, 1 Jul 2022 10:09:29 -0500 Subject: [PATCH] patch: move Member.ban() to Guild.banMember() --- mod.ts | 2 ++ structures/Guild.ts | 40 ++++++++++++++++++++++++++++++++++++++++ structures/Member.ts | 41 ++++++----------------------------------- 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/mod.ts b/mod.ts index b462a6d..559e08d 100644 --- a/mod.ts +++ b/mod.ts @@ -3,11 +3,13 @@ export * from "./structures/Attachment.ts"; export * from "./structures/Base.ts"; export * from "./structures/BaseGuild.ts"; export * from "./structures/Channel.ts"; +export * from "./structures/Component.ts"; export * from "./structures/DMChannel.ts"; export * from "./structures/Emoji.ts"; export * from "./structures/Guild.ts"; export * from "./structures/GuildChannel.ts"; export * from "./structures/GuildEmoji.ts"; +export * from "./structures/Interaction.ts"; export * from "./structures/Invite.ts"; export * from "./structures/InviteGuild.ts"; export * from "./structures/Member.ts"; diff --git a/structures/Guild.ts b/structures/Guild.ts index 8cf752d..936e3f3 100644 --- a/structures/Guild.ts +++ b/structures/Guild.ts @@ -46,6 +46,16 @@ export interface ModifyGuildEmoji { roles?: Snowflake[]; } +/** + * @link https://discord.com/developers/docs/resources/guild#create-guild-ban + */ +export interface CreateGuildBan { + /** Number of days to delete messages for (0-7) */ + deleteMessageDays?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; + /** Reason for the ban */ + reason?: string; +} + /** * Represents a guild * @link https://discord.com/developers/docs/resources/guild#guild-object @@ -190,6 +200,36 @@ export class Guild extends BaseGuild implements Model { return invites.map((invite) => new Invite(this.session, invite)); } + + + /** + * Bans the member + */ + async banMember(memberId: Snowflake, options: CreateGuildBan) { + await this.session.rest.runMethod( + this.session.rest, + "PUT", + Routes.GUILD_BAN(this.id, memberId), + options + ? { + delete_message_days: options.deleteMessageDays, + reason: options.reason, + } + : {}, + ); + } + + /** + * Kicks the member + */ + async kickMember(memebrId: Snowflake, { reason }: { reason?: string }) { + await this.session.rest.runMethod( + this.session.rest, + "DELETE", + Routes.GUILD_MEMBER(this.id, memebrId), + { reason }, + ); + } } export default Guild; diff --git a/structures/Member.ts b/structures/Member.ts index e3d302e..9d12de1 100644 --- a/structures/Member.ts +++ b/structures/Member.ts @@ -3,20 +3,12 @@ import type { Snowflake } from "../util/Snowflake.ts"; import type { Session } from "../session/Session.ts"; import type { DiscordMemberWithUser } from "../vendor/external.ts"; import type { ImageFormat, ImageSize } from "../util/shared/images.ts"; +import type { CreateGuildBan } from "./Guild.ts"; import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts"; import User from "./User.ts"; +import Guild from "./Guild.ts"; import * as Routes from "../util/Routes.ts"; -/** - * @link https://discord.com/developers/docs/resources/guild#create-guild-ban - */ -export interface CreateGuildBan { - /** Number of days to delete messages for (0-7) */ - deleteMessageDays?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; - /** Reason for the ban */ - reason?: string; -} - /** * Represents a guild member * TODO: add a `guild` property somehow @@ -64,35 +56,14 @@ export class Member implements Model { return new Date(this.joinedTimestamp); } - /** - * Bans the member - */ async ban(options: CreateGuildBan): Promise { - await this.session.rest.runMethod( - this.session.rest, - "PUT", - Routes.GUILD_BAN(this.guildId, this.id), - options - ? { - delete_message_days: options.deleteMessageDays, - reason: options.reason, - } - : {}, - ); + await Guild.prototype.banMember.call({ id: this.guildId }, this.user.id, options); return this; } - /** - * Kicks the member - */ - async kick({ reason }: { reason?: string }): Promise { - await this.session.rest.runMethod( - this.session.rest, - "DELETE", - Routes.GUILD_MEMBER(this.guildId, this.id), - { reason }, - ); + async kick(options: { reason?: string }): Promise { + await Guild.prototype.kickMember.call({ id: this.guildId }, this.user.id, options); return this; } @@ -104,7 +75,7 @@ export class Member implements Model { if (!this.avatarHash) { url = Routes.USER_DEFAULT_AVATAR(Number(this.user.discriminator) % 5); } else { - url = Routes.USER_AVATAR(this.id, iconBigintToHash(this.avatarHash)); + url = Routes.USER_AVATAR(this.user.id, iconBigintToHash(this.avatarHash)); } return `${url}.${options.format ?? (url.includes("/a_") ? "gif" : "jpg")}?size=${options.size}`;