some moar fixes lol

This commit is contained in:
ayntee
2021-04-12 22:29:21 +04:00
parent 2a33db04fb
commit 9d5d0f0872
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);
} }
+13 -5
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(
"post",
endpoints.GUILD_ROLES(guildId),
{
...options, ...options,
permissions: calculateBits(options?.permissions || []), permissions: calculateBits(options?.permissions || []),
reason, 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);