mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
fix: more missing typings and remove swap roles
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
|
import { DiscordUser } from "../../types/users/user.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";
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ export async function getReactions(
|
|||||||
"get",
|
"get",
|
||||||
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
|
||||||
options,
|
options,
|
||||||
)) as UserPayload[];
|
)) as DiscordUser[];
|
||||||
|
|
||||||
return new Collection(users.map((user) => [user.id, user]));
|
return new Collection(users.map((user) => [user.id, user]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ import { deleteRole } from "./roles/delete_role.ts";
|
|||||||
import { editRole } from "./roles/edit_role.ts";
|
import { editRole } from "./roles/edit_role.ts";
|
||||||
import { getRoles } from "./roles/get_roles.ts";
|
import { getRoles } from "./roles/get_roles.ts";
|
||||||
import { removeRole } from "./roles/remove_role.ts";
|
import { removeRole } from "./roles/remove_role.ts";
|
||||||
import { swapRoles } from "./roles/swap_roles.ts";
|
|
||||||
import { createGuildFromTemplate } from "./templates/create_guild_from_template.ts";
|
import { createGuildFromTemplate } from "./templates/create_guild_from_template.ts";
|
||||||
import { createGuildTemplate } from "./templates/create_guild_template.ts";
|
import { createGuildTemplate } from "./templates/create_guild_template.ts";
|
||||||
import { deleteGuildTemplate } from "./templates/delete_guild_template.ts";
|
import { deleteGuildTemplate } from "./templates/delete_guild_template.ts";
|
||||||
@@ -230,7 +229,6 @@ export {
|
|||||||
sendMessage,
|
sendMessage,
|
||||||
startTyping,
|
startTyping,
|
||||||
swapChannels,
|
swapChannels,
|
||||||
swapRoles,
|
|
||||||
syncGuildTemplate,
|
syncGuildTemplate,
|
||||||
syncIntegration,
|
syncIntegration,
|
||||||
unban,
|
unban,
|
||||||
@@ -350,7 +348,6 @@ export let helpers = {
|
|||||||
editRole,
|
editRole,
|
||||||
getRoles,
|
getRoles,
|
||||||
removeRole,
|
removeRole,
|
||||||
swapRoles,
|
|
||||||
// templates
|
// templates
|
||||||
createGuildFromTemplate,
|
createGuildFromTemplate,
|
||||||
createGuildTemplate,
|
createGuildTemplate,
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
|
||||||
import { endpoints } from "../../util/constants.ts";
|
|
||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
|
||||||
|
|
||||||
/** Modify the positions of a set of role objects for the guild. Requires the MANAGE_ROLES permission. */
|
|
||||||
export async function swapRoles(guildId: string, rolePositions: PositionSwap) {
|
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
|
||||||
"patch",
|
|
||||||
endpoints.GUILD_ROLES(guildId),
|
|
||||||
rolePositions,
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
@@ -47,7 +47,6 @@ import "./roles/create_role.ts";
|
|||||||
import "./roles/delete_role.ts";
|
import "./roles/delete_role.ts";
|
||||||
import "./roles/edit_role.ts";
|
import "./roles/edit_role.ts";
|
||||||
import "./roles/remove_role.ts";
|
import "./roles/remove_role.ts";
|
||||||
import "./roles/swap_roles.ts";
|
|
||||||
|
|
||||||
// Final cleanup
|
// Final cleanup
|
||||||
import "./guilds/delete_server.ts";
|
import "./guilds/delete_server.ts";
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
|
||||||
import {assertEquals, assertExists} from "../deps.ts";
|
|
||||||
import { cache } from "../../src/cache.ts";
|
|
||||||
import { delayUntil } from "../util/delay_until.ts";
|
|
||||||
import {addRole} from "../../src/helpers/roles/add_role.ts";
|
|
||||||
import {createRole} from "../../src/helpers/roles/create_role.ts";
|
|
||||||
import {botId} from "../../src/bot.ts";
|
|
||||||
import {swapRoles} from "../../src/helpers/roles/swap_roles.ts";
|
|
||||||
import {delay} from "../../src/util/utils.ts";
|
|
||||||
|
|
||||||
Deno.test({
|
|
||||||
name: "[role] swap roles",
|
|
||||||
async fn() {
|
|
||||||
const role = await createRole(tempData.guildId, {
|
|
||||||
name: "hoti",
|
|
||||||
});
|
|
||||||
|
|
||||||
assertExists(role);
|
|
||||||
|
|
||||||
const secondRole = await createRole(tempData.guildId, {
|
|
||||||
name: "not hoti",
|
|
||||||
});
|
|
||||||
|
|
||||||
assertExists(secondRole);
|
|
||||||
|
|
||||||
// Delay the execution by 5 seconds to allow GUILD_ROLE_CREATE event to be processed
|
|
||||||
await delayUntil(10000, () => cache.guilds.get(tempData.guildId)?.roles.has(role.id) && cache.guilds.get(tempData.guildId)?.roles.has(secondRole.id));
|
|
||||||
|
|
||||||
if (!cache.guilds.get(tempData.guildId)?.roles.has(role.id) || !cache.guilds.get(tempData.guildId)?.roles.has(secondRole.id)) {
|
|
||||||
throw new Error(`The role seemed to be created but it was not cached.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await swapRoles(tempData.guildId, [
|
|
||||||
{
|
|
||||||
id: role.id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: secondRole.id,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
assertExists(result);
|
|
||||||
},
|
|
||||||
...defaultTestOptions,
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user