This commit is contained in:
Skillz4Killz
2021-04-12 18:30:30 +00:00
committed by GitHub
2 changed files with 21 additions and 10 deletions
+5 -2
View File
@@ -1,9 +1,12 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { DiscordUser } from "../../types/users/user.ts";
import { User } from "../../types/users/user.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */ /** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */
export async function getUser(userId: string) { export async function getUser(userId: string) {
const result = await rest.runMethod("get", endpoints.USER(userId)); const result: User = await rest.runMethod("get", endpoints.USER(userId));
return result as UserPayload; return snakeKeysToCamelCase<DiscordUser>(result);
} }
+16 -8
View File
@@ -1,6 +1,8 @@
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { CreateGuildRole } from "../../types/guilds/create_guild_role.ts";
import { DiscordRole } from "../../types/permissions/role.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { import {
calculateBits, calculateBits,
@@ -10,19 +12,25 @@ import {
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */ /** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
export async function createRole( export async function createRole(
guildId: string, guildId: string,
options: CreateRoleOptions, options: CreateGuildRole,
reason?: string, reason?: string,
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod("post", endpoints.GUILD_ROLES(guildId), { const result: DiscordRole = await rest.runMethod(
...options, "post",
permissions: calculateBits(options?.permissions || []), endpoints.GUILD_ROLES(guildId),
reason, {
}); ...options,
permissions: calculateBits(options?.permissions || []),
reason,
},
);
const roleData = result as RoleData; const role = await structures.createDiscordenoRole({
const role = await structures.createDiscordenoRole({role: roleData, guild_id: guildId}); role: result,
guild_id: guildId,
});
const guild = await cacheHandlers.get("guilds", guildId); const guild = await cacheHandlers.get("guilds", guildId);
guild?.roles.set(role.id, role); guild?.roles.set(role.id, role);