diff --git a/structures/Guild.ts b/structures/Guild.ts index b3d387f..9466149 100644 --- a/structures/Guild.ts +++ b/structures/Guild.ts @@ -26,6 +26,14 @@ export interface CreateRole { mentionable?: boolean; } +export interface ModifyGuildRole { + name?: string; + color?: number; + hoist?: boolean; + mentionable?: boolean; + unicodeEmoji?: string; +} + export interface CreateGuildEmoji { name: string; image: string; @@ -138,7 +146,21 @@ export class Guild extends BaseGuild implements Model { await this.session.rest.runMethod(this.session.rest, "DELETE", Routes.GUILD_ROLE(this.id, roleId)); } - // TODO: edit role + async editRole(roleId: Snowflake, options: ModifyGuildRole): Promise { + const role = await this.session.rest.runMethod( + this.session.rest, + "PATCH", + Routes.GUILD_ROLE(this.id, roleId), + { + name: options.name, + color: options.color, + hoist: options.hoist, + mentionable: options.mentionable, + } + ); + + return new Role(this.session, role, this.id); + } async deleteInvite(inviteCode: string): Promise { await this.session.rest.runMethod( @@ -158,6 +180,16 @@ export class Guild extends BaseGuild implements Model { return new Invite(this.session, inviteMetadata); } + + async fetchInvites(): Promise { + const invites = await this.session.rest.runMethod( + this.session.rest, + "GET", + Routes.GUILD_INVITES(this.id), + ); + + return invites.map((invite) => new Invite(this.session, invite)); + } } export default Guild; diff --git a/structures/Role.ts b/structures/Role.ts index 64365e5..b8a53cf 100644 --- a/structures/Role.ts +++ b/structures/Role.ts @@ -4,7 +4,7 @@ import type { Session } from "../session/Session.ts"; import { Snowflake } from "../util/Snowflake.ts"; import { iconHashToBigInt } from "../util/hash.ts"; import Permissions from "./Permissions.ts"; -import Guild from "./Guild.ts"; +import Guild, { ModifyGuildRole } from "./Guild.ts"; export class Role implements Model { constructor(session: Session, data: DiscordRole, guildId: Snowflake) { @@ -52,6 +52,11 @@ export class Role implements Model { await Guild.prototype.deleteRole.call({ id: this.guildId, session: this.session }, this.id); } + async edit(options: ModifyGuildRole) { + const role = await Guild.prototype.editRole.call({ id: this.guildId, session: this.session }, this.id, options); + return role; + } + toString() { switch (this.id) { case this.guildId: diff --git a/util/Routes.ts b/util/Routes.ts index 73166e7..03442a7 100644 --- a/util/Routes.ts +++ b/util/Routes.ts @@ -135,3 +135,7 @@ export function INVITE(inviteCode: string, options?: GetInvite) { return url; } + +export function GUILD_INVITES(guildId: Snowflake) { + return `/guilds/${guildId}/invites`; +}