mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
roles
This commit is contained in:
@@ -25,11 +25,9 @@ export async function addRole(
|
|||||||
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"put",
|
"put",
|
||||||
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
|
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
|
||||||
{ reason },
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ 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 { 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 { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
calculateBits,
|
calculateBits,
|
||||||
@@ -17,7 +17,7 @@ export async function createRole(
|
|||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result: DiscordRole = await rest.runMethod(
|
const result = await rest.runMethod<Role>(
|
||||||
"post",
|
"post",
|
||||||
endpoints.GUILD_ROLES(guildId),
|
endpoints.GUILD_ROLES(guildId),
|
||||||
{
|
{
|
||||||
@@ -34,5 +34,6 @@ export async function createRole(
|
|||||||
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);
|
||||||
|
|
||||||
|
// TODO: ADD TO CACHE?
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|||||||
export async function deleteRole(guildId: string, id: string) {
|
export async function deleteRole(guildId: string, id: string) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.GUILD_ROLE(guildId, id),
|
endpoints.GUILD_ROLE(guildId, id),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
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 { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
calculateBits,
|
calculateBits,
|
||||||
@@ -14,7 +15,7 @@ export async function editRole(
|
|||||||
) {
|
) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
const result = await rest.runMethod<Role>(
|
||||||
"patch",
|
"patch",
|
||||||
endpoints.GUILD_ROLE(guildId, id),
|
endpoints.GUILD_ROLE(guildId, id),
|
||||||
{
|
{
|
||||||
@@ -25,5 +26,5 @@ export async function editRole(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return await structures.createDiscordenoRole(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
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 { Collection } from "../../util/collection.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
|
||||||
|
|
||||||
/** Returns a list of role objects for the guild.
|
/** 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) {
|
export async function getRoles(guildId: string) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = (await rest.runMethod(
|
const result = await rest.runMethod<Role[]>(
|
||||||
"get",
|
"get",
|
||||||
endpoints.GUILD_ROLES(guildId),
|
endpoints.GUILD_ROLES(guildId),
|
||||||
)) as DiscordRole[];
|
);
|
||||||
|
|
||||||
|
// TODO: addToCache
|
||||||
|
|
||||||
return new Collection(
|
return new Collection(
|
||||||
result.map((role) => [role.id, snakeKeysToCamelCase<Role>(role)]),
|
result.map((role) => [role.id, role]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,11 +27,9 @@ export async function removeRole(
|
|||||||
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
|
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
|
||||||
{ reason },
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user