mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat:add modifyGuildMfaLevel (#2416)
* add modifyGuildMfaLevel * plugins/permissions: editGuildMfaLevel * tests/guilds: editGuildMfaLevel * helpers/guilds: editGuuldMfaLevel return void * editGuildMfaLevel return void * Update plugins/permissions/src/guilds/editGuildMfaLevel.ts * tests/guilds: fix editGuildMfaLevel CACHED_COMMUNITY_GUILD_ID is not owned by the bot Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
This commit is contained in:
co-authored by
Skillz4Killz
parent
15f34f6d17
commit
ec91822a73
@@ -0,0 +1,12 @@
|
||||
import type { Bot } from "../../mod.ts";
|
||||
import type { MfaLevels } from "../../types/shared.ts";
|
||||
|
||||
/** Modify a guild's MFA level. Requires guild ownership. */
|
||||
export async function editGuildMfaLevel(bot: Bot, guildId: bigint, mfaLevel: MfaLevels, reason?: string) {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
"POST",
|
||||
bot.constants.routes.GUILD_MFA_LEVEL(guildId),
|
||||
{ level: mfaLevel, reason },
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
export * from "./automod/mod.ts";
|
||||
export * from "./scheduledEvents/mod.ts";
|
||||
|
||||
export * from "./createGuild.ts";
|
||||
export * from "./deleteGuild.ts";
|
||||
export * from "./editGuild.ts";
|
||||
export * from "./editGuildMfaLevel.ts";
|
||||
export * from "./editWelcomeScreen.ts";
|
||||
export * from "./editWidget.ts";
|
||||
export * from "./getAuditLogs.ts";
|
||||
@@ -23,3 +22,4 @@ export * from "./getWidget.ts";
|
||||
export * from "./getWidgetImageUrl.ts";
|
||||
export * from "./getWidgetSettings.ts";
|
||||
export * from "./leaveGuild.ts";
|
||||
export * from "./scheduledEvents/mod.ts";
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
|
||||
export default function editGuildMfaLevel(bot: BotWithCache) {
|
||||
const editGuildMfaLevelOld = bot.helpers.editGuildMfaLevel;
|
||||
|
||||
bot.helpers.editGuildMfaLevel = async function (guildId, mfaLevel, reason) {
|
||||
const guild = bot.guilds.get(guildId);
|
||||
if (guild?.ownerId !== bot.id) throw new Error("The bot is not the owner of the guild");
|
||||
return await editGuildMfaLevelOld(guildId, mfaLevel, reason);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { MfaLevels } from "../../mod.ts";
|
||||
import { assertEquals } from "../deps.ts";
|
||||
import { loadBot } from "../mod.ts";
|
||||
|
||||
Deno.test("[guild] edit guild mfa level", async () => {
|
||||
const bot = loadBot();
|
||||
const guild = await bot.helpers.createGuild({ name: "test" });
|
||||
await bot.helpers.editGuildMfaLevel(guild.id, MfaLevels.Elevated, "test");
|
||||
assertEquals((await bot.helpers.getGuild(guild.id)).mfaLevel, MfaLevels.Elevated);
|
||||
await bot.helpers.editGuildMfaLevel(guild.id, MfaLevels.None, "revert test");
|
||||
assertEquals((await bot.helpers.getGuild(guild.id)).mfaLevel, MfaLevels.None);
|
||||
await bot.helpers.deleteGuild(guild.id);
|
||||
});
|
||||
@@ -348,6 +348,7 @@ export const routes = {
|
||||
|
||||
return url;
|
||||
},
|
||||
GUILD_MFA_LEVEL: (guildId: bigint) => `/guilds/${guildId}/mfa`,
|
||||
// Voice
|
||||
VOICE_REGIONS: () => {
|
||||
return `/voice/regions`;
|
||||
|
||||
Reference in New Issue
Block a user