diff --git a/src/helpers/roles/add_role.ts b/src/helpers/roles/add_role.ts index 6213823c3..6bf738ede 100644 --- a/src/helpers/roles/add_role.ts +++ b/src/helpers/roles/add_role.ts @@ -25,11 +25,9 @@ export async function addRole( await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + return await rest.runMethod( "put", endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId), { reason }, ); - - return result; } diff --git a/src/helpers/roles/create_role.ts b/src/helpers/roles/create_role.ts index b8cdf1079..0c107ccd7 100644 --- a/src/helpers/roles/create_role.ts +++ b/src/helpers/roles/create_role.ts @@ -2,7 +2,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { CreateGuildRole } from "../../types/guilds/create_guild_role.ts"; -import { DiscordRole } from "../../types/permissions/role.ts"; +import { Role } from "../../types/permissions/role.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, @@ -17,7 +17,7 @@ export async function createRole( ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result: DiscordRole = await rest.runMethod( + const result = await rest.runMethod( "post", endpoints.GUILD_ROLES(guildId), { @@ -34,5 +34,6 @@ export async function createRole( const guild = await cacheHandlers.get("guilds", guildId); guild?.roles.set(role.id, role); + // TODO: ADD TO CACHE? return role; } diff --git a/src/helpers/roles/delete_role.ts b/src/helpers/roles/delete_role.ts index dd8c9300b..f9d134545 100644 --- a/src/helpers/roles/delete_role.ts +++ b/src/helpers/roles/delete_role.ts @@ -6,10 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function deleteRole(guildId: string, id: string) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.GUILD_ROLE(guildId, id), ); - - return result; } diff --git a/src/helpers/roles/edit_role.ts b/src/helpers/roles/edit_role.ts index 351b6314a..61373b852 100644 --- a/src/helpers/roles/edit_role.ts +++ b/src/helpers/roles/edit_role.ts @@ -1,5 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { CreateGuildRole } from "../../types/mod.ts"; +import { structures } from "../../structures/mod.ts"; +import { CreateGuildRole, Role } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, @@ -14,7 +15,7 @@ export async function editRole( ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + const result = await rest.runMethod( "patch", endpoints.GUILD_ROLE(guildId, id), { @@ -25,5 +26,5 @@ export async function editRole( }, ); - return result; + return await structures.createDiscordenoRole(result); } diff --git a/src/helpers/roles/get_roles.ts b/src/helpers/roles/get_roles.ts index 29b08998b..ace6fe351 100644 --- a/src/helpers/roles/get_roles.ts +++ b/src/helpers/roles/get_roles.ts @@ -1,9 +1,8 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordRole, Role } from "../../types/permissions/role.ts"; +import { Role } from "../../types/permissions/role.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns a list of role objects for the guild. * @@ -12,12 +11,14 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function getRoles(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.GUILD_ROLES(guildId), - )) as DiscordRole[]; + ); + + // TODO: addToCache return new Collection( - result.map((role) => [role.id, snakeKeysToCamelCase(role)]), + result.map((role) => [role.id, role]), ); } diff --git a/src/helpers/roles/remove_role.ts b/src/helpers/roles/remove_role.ts index 786b0136e..5a98501ef 100644 --- a/src/helpers/roles/remove_role.ts +++ b/src/helpers/roles/remove_role.ts @@ -27,11 +27,9 @@ export async function removeRole( await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId), { reason }, ); - - return result; }