mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
feat: all role-related endpoints
This commit is contained in:
parent
b99218bdc3
commit
5b0d124380
@ -81,6 +81,11 @@ export interface BeginGuildPrune {
|
||||
includeRoles?: Snowflake[];
|
||||
}
|
||||
|
||||
export interface ModifyRolePositions {
|
||||
id: Snowflake;
|
||||
position?: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a guild
|
||||
* @link https://discord.com/developers/docs/resources/guild#guild-object
|
||||
@ -212,6 +217,40 @@ export class Guild extends BaseGuild implements Model {
|
||||
return new Role(this.session, role, this.id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
async addRole(memberId: Snowflake, roleId: Snowflake, { reason }: { reason?: string } = {}) {
|
||||
await this.session.rest.runMethod<undefined>(
|
||||
this.session.rest,
|
||||
"PUT",
|
||||
Routes.GUILD_MEMBER_ROLE(this.id, memberId, roleId),
|
||||
{ reason },
|
||||
);
|
||||
}
|
||||
|
||||
async removeRole(memberId: Snowflake, roleId: Snowflake, { reason }: { reason?: string } = {}) {
|
||||
await this.session.rest.runMethod<undefined>(
|
||||
this.session.rest,
|
||||
"DELETE",
|
||||
Routes.GUILD_MEMBER_ROLE(this.id, memberId, roleId),
|
||||
{ reason },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the roles moved
|
||||
* */
|
||||
async moveRoles(options: ModifyRolePositions[]) {
|
||||
const roles = await this.session.rest.runMethod<DiscordRole[]>(
|
||||
this.session.rest,
|
||||
"PATCH",
|
||||
Routes.GUILD_ROLES(this.id),
|
||||
options,
|
||||
);
|
||||
|
||||
return roles.map((role) => new Role(this.session, role, this.id));
|
||||
}
|
||||
|
||||
async deleteInvite(inviteCode: string): Promise<void> {
|
||||
await this.session.rest.runMethod<undefined>(
|
||||
this.session.rest,
|
||||
|
@ -82,6 +82,14 @@ export class Member implements Model {
|
||||
return member;
|
||||
}
|
||||
|
||||
async addRole(roleId: Snowflake, options: { reason?: string } = {}) {
|
||||
await Guild.prototype.addRole.call({ id: this.guildId, session: this.session }, this.user.id, roleId, options);
|
||||
}
|
||||
|
||||
async removeRole(roleId: Snowflake, options: { reason?: string } = {}) {
|
||||
await Guild.prototype.removeRole.call({ id: this.guildId, session: this.session }, this.user.id, roleId, options);
|
||||
}
|
||||
|
||||
/** gets the user's avatar */
|
||||
avatarUrl(options: { format?: ImageFormat; size?: ImageSize } = { size: 128 }) {
|
||||
let url: string;
|
||||
|
@ -56,6 +56,14 @@ export class Role implements Model {
|
||||
return role;
|
||||
}
|
||||
|
||||
async add(memberId: Snowflake, options: { reason?: string } = {}) {
|
||||
await Guild.prototype.addRole.call({ id: this.guildId, session: this.session }, memberId, this.id, options);
|
||||
}
|
||||
|
||||
async remove(memberId: Snowflake, options: { reason?: string } = {}) {
|
||||
await Guild.prototype.removeRole.call({ id: this.guildId, session: this.session }, memberId, this.id, options);
|
||||
}
|
||||
|
||||
toString() {
|
||||
switch (this.id) {
|
||||
case this.guildId:
|
||||
|
@ -220,3 +220,7 @@ export function CHANNEL_MESSAGE_REACTION(
|
||||
export function CHANNEL_MESSAGE_CROSSPOST(channelId: Snowflake, messageId: Snowflake) {
|
||||
return `/channels/${channelId}/messages/${messageId}/crosspost`;
|
||||
}
|
||||
|
||||
export function GUILD_MEMBER_ROLE(guildId: Snowflake, memberId: Snowflake, roleId: Snowflake) {
|
||||
return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user