mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
patch: move Member.ban() to Guild.banMember()
This commit is contained in:
parent
60484dab40
commit
fcf8c60cca
2
mod.ts
2
mod.ts
@ -3,11 +3,13 @@ export * from "./structures/Attachment.ts";
|
|||||||
export * from "./structures/Base.ts";
|
export * from "./structures/Base.ts";
|
||||||
export * from "./structures/BaseGuild.ts";
|
export * from "./structures/BaseGuild.ts";
|
||||||
export * from "./structures/Channel.ts";
|
export * from "./structures/Channel.ts";
|
||||||
|
export * from "./structures/Component.ts";
|
||||||
export * from "./structures/DMChannel.ts";
|
export * from "./structures/DMChannel.ts";
|
||||||
export * from "./structures/Emoji.ts";
|
export * from "./structures/Emoji.ts";
|
||||||
export * from "./structures/Guild.ts";
|
export * from "./structures/Guild.ts";
|
||||||
export * from "./structures/GuildChannel.ts";
|
export * from "./structures/GuildChannel.ts";
|
||||||
export * from "./structures/GuildEmoji.ts";
|
export * from "./structures/GuildEmoji.ts";
|
||||||
|
export * from "./structures/Interaction.ts";
|
||||||
export * from "./structures/Invite.ts";
|
export * from "./structures/Invite.ts";
|
||||||
export * from "./structures/InviteGuild.ts";
|
export * from "./structures/InviteGuild.ts";
|
||||||
export * from "./structures/Member.ts";
|
export * from "./structures/Member.ts";
|
||||||
|
@ -46,6 +46,16 @@ export interface ModifyGuildEmoji {
|
|||||||
roles?: Snowflake[];
|
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
|
* Represents a guild
|
||||||
* @link https://discord.com/developers/docs/resources/guild#guild-object
|
* @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));
|
return invites.map((invite) => new Invite(this.session, invite));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bans the member
|
||||||
|
*/
|
||||||
|
async banMember(memberId: Snowflake, options: CreateGuildBan) {
|
||||||
|
await this.session.rest.runMethod<undefined>(
|
||||||
|
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<undefined>(
|
||||||
|
this.session.rest,
|
||||||
|
"DELETE",
|
||||||
|
Routes.GUILD_MEMBER(this.id, memebrId),
|
||||||
|
{ reason },
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Guild;
|
export default Guild;
|
||||||
|
@ -3,20 +3,12 @@ import type { Snowflake } from "../util/Snowflake.ts";
|
|||||||
import type { Session } from "../session/Session.ts";
|
import type { Session } from "../session/Session.ts";
|
||||||
import type { DiscordMemberWithUser } from "../vendor/external.ts";
|
import type { DiscordMemberWithUser } from "../vendor/external.ts";
|
||||||
import type { ImageFormat, ImageSize } from "../util/shared/images.ts";
|
import type { ImageFormat, ImageSize } from "../util/shared/images.ts";
|
||||||
|
import type { CreateGuildBan } from "./Guild.ts";
|
||||||
import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts";
|
import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts";
|
||||||
import User from "./User.ts";
|
import User from "./User.ts";
|
||||||
|
import Guild from "./Guild.ts";
|
||||||
import * as Routes from "../util/Routes.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
|
* Represents a guild member
|
||||||
* TODO: add a `guild` property somehow
|
* TODO: add a `guild` property somehow
|
||||||
@ -64,35 +56,14 @@ export class Member implements Model {
|
|||||||
return new Date(this.joinedTimestamp);
|
return new Date(this.joinedTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Bans the member
|
|
||||||
*/
|
|
||||||
async ban(options: CreateGuildBan): Promise<Member> {
|
async ban(options: CreateGuildBan): Promise<Member> {
|
||||||
await this.session.rest.runMethod<undefined>(
|
await Guild.prototype.banMember.call({ id: this.guildId }, this.user.id, options);
|
||||||
this.session.rest,
|
|
||||||
"PUT",
|
|
||||||
Routes.GUILD_BAN(this.guildId, this.id),
|
|
||||||
options
|
|
||||||
? {
|
|
||||||
delete_message_days: options.deleteMessageDays,
|
|
||||||
reason: options.reason,
|
|
||||||
}
|
|
||||||
: {},
|
|
||||||
);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
async kick(options: { reason?: string }): Promise<Member> {
|
||||||
* Kicks the member
|
await Guild.prototype.kickMember.call({ id: this.guildId }, this.user.id, options);
|
||||||
*/
|
|
||||||
async kick({ reason }: { reason?: string }): Promise<Member> {
|
|
||||||
await this.session.rest.runMethod<undefined>(
|
|
||||||
this.session.rest,
|
|
||||||
"DELETE",
|
|
||||||
Routes.GUILD_MEMBER(this.guildId, this.id),
|
|
||||||
{ reason },
|
|
||||||
);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -104,7 +75,7 @@ export class Member implements Model {
|
|||||||
if (!this.avatarHash) {
|
if (!this.avatarHash) {
|
||||||
url = Routes.USER_DEFAULT_AVATAR(Number(this.user.discriminator) % 5);
|
url = Routes.USER_DEFAULT_AVATAR(Number(this.user.discriminator) % 5);
|
||||||
} else {
|
} 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}`;
|
return `${url}.${options.format ?? (url.includes("/a_") ? "gif" : "jpg")}?size=${options.size}`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user