mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
style: move to deno fmt (#1992)
* Create deno.json * run format * run format * ci: only check formatting * f * Update settings.json * Update settings.json
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
# permissions-plugin
|
||||
|
||||
This is an official plugin maintained by Discordeno. This plugin provides automatic permission checking and useful permission checking utility functions. Highly recommended to install this plugin for all users as you can use the utility functions. Enabling the permission plugin should not be done for big bot developers as it requires the cache plugin which will not work in a performance optimized fashion. This is designed mainly for the small beginner devs.
|
||||
This is an official plugin maintained by Discordeno. This plugin provides automatic permission checking and useful
|
||||
permission checking utility functions. Highly recommended to install this plugin for all users as you can use the
|
||||
utility functions. Enabling the permission plugin should not be done for big bot developers as it requires the cache
|
||||
plugin which will not work in a performance optimized fashion. This is designed mainly for the small beginner devs.
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -22,4 +25,3 @@ enablePermissionPlugin(bot);
|
||||
// Start your bot
|
||||
await startBot(bot);
|
||||
```
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ import getChannelWebhooks from "./getChannelWebhooks.ts";
|
||||
import swapChannels from "./swapChannels.ts";
|
||||
|
||||
export default function setupChannelPermChecks(bot: BotWithCache) {
|
||||
setupThreadPermChecks(bot);
|
||||
setupStagePermChecks(bot);
|
||||
deleteChannel(bot);
|
||||
deleteChannelOverwrite(bot);
|
||||
editChannel(bot);
|
||||
editChannelOverwrite(bot);
|
||||
followChannel(bot);
|
||||
getChannelWebhooks(bot);
|
||||
swapChannels(bot);
|
||||
}
|
||||
setupThreadPermChecks(bot);
|
||||
setupStagePermChecks(bot);
|
||||
deleteChannel(bot);
|
||||
deleteChannelOverwrite(bot);
|
||||
editChannel(bot);
|
||||
editChannelOverwrite(bot);
|
||||
followChannel(bot);
|
||||
getChannelWebhooks(bot);
|
||||
swapChannels(bot);
|
||||
}
|
||||
|
||||
@@ -53,4 +53,4 @@ export default function setupStagePermChecks(bot: BotWithCache) {
|
||||
createStageInstance(bot);
|
||||
deleteStageInstance(bot);
|
||||
updateStageInstance(bot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@ export default function getArchivedThreads(bot: BotWithCache) {
|
||||
await requireBotChannelPermissions(
|
||||
bot,
|
||||
channel,
|
||||
options?.type === "private"
|
||||
? ["READ_MESSAGE_HISTORY", "MANAGE_THREADS"]
|
||||
: ["READ_MESSAGE_HISTORY"],
|
||||
options?.type === "private" ? ["READ_MESSAGE_HISTORY", "MANAGE_THREADS"] : ["READ_MESSAGE_HISTORY"],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import leaveThread from "./leaveThread.ts";
|
||||
import removeThreadMember from "./removeThreadMember.ts";
|
||||
|
||||
export default function setupThreadPermChecks(bot: BotWithCache) {
|
||||
addToThread(bot);
|
||||
getArchivedThreads(bot);
|
||||
getThreadMembers(bot);
|
||||
joinThread(bot);
|
||||
leaveThread(bot);
|
||||
removeThreadMember(bot);
|
||||
}
|
||||
addToThread(bot);
|
||||
getArchivedThreads(bot);
|
||||
getThreadMembers(bot);
|
||||
joinThread(bot);
|
||||
leaveThread(bot);
|
||||
removeThreadMember(bot);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
Bot,
|
||||
ButtonStyles,
|
||||
MessageComponents,
|
||||
MessageComponentTypes,
|
||||
} from "../deps.ts";
|
||||
import { Bot, ButtonStyles, MessageComponents, MessageComponentTypes } from "../deps.ts";
|
||||
|
||||
export function validateComponents(bot: Bot, components: MessageComponents) {
|
||||
if (!components?.length) return;
|
||||
@@ -20,9 +15,7 @@ export function validateComponents(bot: Bot, components: MessageComponents) {
|
||||
throw new Error("Too many components.");
|
||||
} else if (
|
||||
component.components?.length > 1 &&
|
||||
component.components.some((subcomponent) =>
|
||||
subcomponent.type === MessageComponentTypes.SelectMenu
|
||||
)
|
||||
component.components.some((subcomponent) => subcomponent.type === MessageComponentTypes.SelectMenu)
|
||||
) {
|
||||
throw new Error("Select component must be alone.");
|
||||
}
|
||||
|
||||
@@ -7,17 +7,18 @@ export default function connectToVoiceChannel(bot: BotWithCache) {
|
||||
bot.helpers.connectToVoiceChannel = async function (
|
||||
guildId,
|
||||
channelId,
|
||||
options
|
||||
options,
|
||||
) {
|
||||
const channel = await bot.channels.get(channelId);
|
||||
if (!channel) throw new Error("CHANNEL_NOT_FOUND");
|
||||
|
||||
if (
|
||||
[ChannelTypes.GuildStageVoice, ChannelTypes.GuildVoice].includes(
|
||||
channel.type
|
||||
channel.type,
|
||||
)
|
||||
)
|
||||
) {
|
||||
throw new Error("INVALID_CHANNEL_TYPE");
|
||||
}
|
||||
|
||||
const guild = channel?.guildId && bot.guilds.get(channel.guildId);
|
||||
if (!guild) throw new Error("GUILD_NOT_FOUND");
|
||||
@@ -33,8 +34,9 @@ export default function connectToVoiceChannel(bot: BotWithCache) {
|
||||
channel.userLimit &&
|
||||
guild.voiceStates.filter((vs) => vs.channelId === channelId).size >=
|
||||
channel.userLimit
|
||||
)
|
||||
) {
|
||||
permsNeeded.push("MANAGE_CHANNELS");
|
||||
}
|
||||
|
||||
await requireBotChannelPermissions(bot, channel, permsNeeded);
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { BotWithCache, PermissionStrings } from "../deps.ts";
|
||||
import {
|
||||
requireBotChannelPermissions,
|
||||
requireBotGuildPermissions,
|
||||
} from "./permissions.ts";
|
||||
import { requireBotChannelPermissions, requireBotGuildPermissions } from "./permissions.ts";
|
||||
|
||||
export default function editMember(bot: BotWithCache) {
|
||||
const editMemberOld = bot.helpers.editMember;
|
||||
|
||||
@@ -34,5 +34,5 @@ export function editEmoji(bot: BotWithCache) {
|
||||
export default function setupEmojiPermChecks(bot: BotWithCache) {
|
||||
createEmoji(bot);
|
||||
deleteEmoji(bot);
|
||||
editEmoji(bot)
|
||||
editEmoji(bot);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export default function editGuild(bot: BotWithCache) {
|
||||
const editGuildOld = bot.helpers.editGuild;
|
||||
|
||||
bot.helpers.editGuild = function (guildId, options, shardId) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"])
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return editGuildOld(guildId, options, shardId);
|
||||
};
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { BotWithCache, ScheduledEventEntityType } from "../../deps.ts";
|
||||
import {
|
||||
requireBotChannelPermissions,
|
||||
requireBotGuildPermissions,
|
||||
} from "../permissions.ts";
|
||||
import { requireBotChannelPermissions, requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export function createScheduledEvent(bot: BotWithCache) {
|
||||
const createScheduledEventOld = bot.helpers.createScheduledEvent;
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
AllowedMentionsTypes,
|
||||
BotWithCache,
|
||||
ChannelTypes,
|
||||
PermissionStrings,
|
||||
} from "../../deps.ts";
|
||||
import { AllowedMentionsTypes, BotWithCache, ChannelTypes, PermissionStrings } from "../../deps.ts";
|
||||
import { validateComponents } from "../components.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
|
||||
@@ -17,12 +17,8 @@ export function calculateBasePermissions(
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
memberOrId: bigint | DiscordenoMember,
|
||||
) {
|
||||
const guild = typeof guildOrId === "bigint"
|
||||
? bot.guilds.get(guildOrId)
|
||||
: guildOrId;
|
||||
const member = typeof memberOrId === "bigint"
|
||||
? bot.members.get(memberOrId)
|
||||
: memberOrId;
|
||||
const guild = typeof guildOrId === "bigint" ? bot.guilds.get(guildOrId) : guildOrId;
|
||||
const member = typeof memberOrId === "bigint" ? bot.members.get(memberOrId) : memberOrId;
|
||||
|
||||
if (!guild || !member) return 8n;
|
||||
|
||||
@@ -49,16 +45,12 @@ export function calculateChannelOverwrites(
|
||||
channelOrId: bigint | DiscordenoChannel,
|
||||
memberOrId: bigint | DiscordenoMember,
|
||||
) {
|
||||
const channel = typeof channelOrId === "bigint"
|
||||
? bot.channels.get(channelOrId)
|
||||
: channelOrId;
|
||||
const channel = typeof channelOrId === "bigint" ? bot.channels.get(channelOrId) : channelOrId;
|
||||
|
||||
// This is a DM channel so return ADMINISTRATOR permission
|
||||
if (!channel?.guildId) return 8n;
|
||||
|
||||
const member = typeof memberOrId === "bigint"
|
||||
? bot.members.get(memberOrId)
|
||||
: memberOrId;
|
||||
const member = typeof memberOrId === "bigint" ? bot.members.get(memberOrId) : memberOrId;
|
||||
|
||||
if (!channel || !member) return 8n;
|
||||
|
||||
@@ -192,9 +184,7 @@ export function missingPermissions(
|
||||
) {
|
||||
if (permissionBits & 8n) return [];
|
||||
|
||||
return permissions.filter((permission) =>
|
||||
!(permissionBits & BigInt(BitwisePermissionFlags[permission]))
|
||||
);
|
||||
return permissions.filter((permission) => !(permissionBits & BigInt(BitwisePermissionFlags[permission])));
|
||||
}
|
||||
|
||||
/** Get the missing Guild permissions this member has */
|
||||
@@ -343,15 +333,12 @@ export function highestRole(
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
memberOrId: bigint | DiscordenoMember,
|
||||
) {
|
||||
const guild = typeof guildOrId === "bigint"
|
||||
? bot.guilds.get(guildOrId)
|
||||
: guildOrId;
|
||||
const guild = typeof guildOrId === "bigint" ? bot.guilds.get(guildOrId) : guildOrId;
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
|
||||
// Get the roles from the member
|
||||
const memberRoles =
|
||||
(typeof memberOrId === "bigint" ? bot.members.get(memberOrId) : memberOrId)
|
||||
?.roles;
|
||||
const memberRoles = (typeof memberOrId === "bigint" ? bot.members.get(memberOrId) : memberOrId)
|
||||
?.roles;
|
||||
// This member has no roles so the highest one is the @everyone role
|
||||
if (!memberRoles) return guild.roles.get(guild.id)!;
|
||||
|
||||
@@ -424,13 +411,12 @@ export function channelOverwriteHasPermission(
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
overwrites: bigint[],
|
||||
permissions: PermissionStrings[]
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
const overwrite =
|
||||
overwrites.find((perm) => {
|
||||
const [_, bitID] = separateOverwrites(perm);
|
||||
return id === bitID;
|
||||
}) ||
|
||||
const overwrite = overwrites.find((perm) => {
|
||||
const [_, bitID] = separateOverwrites(perm);
|
||||
return id === bitID;
|
||||
}) ||
|
||||
overwrites.find((perm) => {
|
||||
const [_, bitID] = separateOverwrites(perm);
|
||||
return bitID === guildId;
|
||||
|
||||
Reference in New Issue
Block a user