diff --git a/.env.example b/.env.example index d2d2a2b2..a794dc46 100644 --- a/.env.example +++ b/.env.example @@ -9,6 +9,9 @@ BOT_TOKEN= DASHBOARD_URL=https://localhost:3300 API_URL=https://localhost:3300/api +# Comma-separated list of user IDs who should have access to the bot's global commands +STAFF= + # When using the Docker-based development environment, this is only used internally. The API will be available at localhost:DOCKER_DEV_WEB_PORT/api. API_PORT=3000 diff --git a/backend/src/pluginUtils.ts b/backend/src/pluginUtils.ts index 031d1fa7..17cd7631 100644 --- a/backend/src/pluginUtils.ts +++ b/backend/src/pluginUtils.ts @@ -14,6 +14,7 @@ import { TZeppelinKnub } from "./types"; import { deepKeyIntersect, errorMessage, successMessage, tDeepPartial, tNullable } from "./utils"; import { Tail } from "./utils/typeUtils"; import { decodeAndValidateStrict, StrictValidationError, validate } from "./validatorUtils"; +import { isStaff } from "./staff"; const { getMemberLevel } = helpers; @@ -242,8 +243,8 @@ export function isOwner(pluginData: AnyPluginData, userId: string) { return owners.includes(userId); } -export const isOwnerPreFilter = (_, context: CommandContext) => { - return isOwner(context.pluginData, context.message.author.id); +export const isStaffPreFilter = (_, context: CommandContext) => { + return isStaff(context.message.author.id); }; type AnyFn = (...args: any[]) => any; diff --git a/backend/src/plugins/BotControl/commands/AddDashboardUserCmd.ts b/backend/src/plugins/BotControl/commands/AddDashboardUserCmd.ts index b417fec6..531016a3 100644 --- a/backend/src/plugins/BotControl/commands/AddDashboardUserCmd.ts +++ b/backend/src/plugins/BotControl/commands/AddDashboardUserCmd.ts @@ -1,14 +1,14 @@ import { ApiPermissions } from "@shared/apiPermissions"; import { TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { botControlCmd } from "../types"; export const AddDashboardUserCmd = botControlCmd({ trigger: ["add_dashboard_user"], permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, signature: { diff --git a/backend/src/plugins/BotControl/commands/AddServerFromInviteCmd.ts b/backend/src/plugins/BotControl/commands/AddServerFromInviteCmd.ts index 5bdb2ace..1f29e822 100644 --- a/backend/src/plugins/BotControl/commands/AddServerFromInviteCmd.ts +++ b/backend/src/plugins/BotControl/commands/AddServerFromInviteCmd.ts @@ -1,7 +1,7 @@ import { ApiPermissions } from "@shared/apiPermissions"; import { TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { DBDateFormat, isGuildInvite, isSnowflake, resolveInvite } from "../../../utils"; import { botControlCmd } from "../types"; import moment from "moment-timezone"; diff --git a/backend/src/plugins/BotControl/commands/AllowServerCmd.ts b/backend/src/plugins/BotControl/commands/AllowServerCmd.ts index 9e786b71..1aa665b5 100644 --- a/backend/src/plugins/BotControl/commands/AllowServerCmd.ts +++ b/backend/src/plugins/BotControl/commands/AllowServerCmd.ts @@ -1,7 +1,7 @@ import { ApiPermissions } from "@shared/apiPermissions"; import { TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { DBDateFormat, isSnowflake } from "../../../utils"; import { botControlCmd } from "../types"; import moment from "moment-timezone"; @@ -10,7 +10,7 @@ export const AllowServerCmd = botControlCmd({ trigger: ["allow_server", "allowserver", "add_server", "addserver"], permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, signature: { diff --git a/backend/src/plugins/BotControl/commands/ChannelToServerCmd.ts b/backend/src/plugins/BotControl/commands/ChannelToServerCmd.ts index 5e9dcbb8..49f0ff73 100644 --- a/backend/src/plugins/BotControl/commands/ChannelToServerCmd.ts +++ b/backend/src/plugins/BotControl/commands/ChannelToServerCmd.ts @@ -1,6 +1,6 @@ import { Guild, GuildChannel, TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { GuildInvite, isGuildInvite, resolveInvite, verboseUserMention } from "../../../utils"; import { botControlCmd } from "../types"; import { isEligible } from "../functions/isEligible"; @@ -9,7 +9,7 @@ export const ChannelToServerCmd = botControlCmd({ trigger: ["channel_to_server", "channel2server"], permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, signature: { diff --git a/backend/src/plugins/BotControl/commands/DisallowServerCmd.ts b/backend/src/plugins/BotControl/commands/DisallowServerCmd.ts index 1a9cf64a..c7067341 100644 --- a/backend/src/plugins/BotControl/commands/DisallowServerCmd.ts +++ b/backend/src/plugins/BotControl/commands/DisallowServerCmd.ts @@ -1,6 +1,6 @@ import { Snowflake, TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { noop } from "../../../utils"; import { botControlCmd } from "../types"; @@ -8,7 +8,7 @@ export const DisallowServerCmd = botControlCmd({ trigger: ["disallow_server", "disallowserver", "remove_server", "removeserver"], permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, signature: { diff --git a/backend/src/plugins/BotControl/commands/LeaveServerCmd.ts b/backend/src/plugins/BotControl/commands/LeaveServerCmd.ts index b502c08f..20d0b14b 100644 --- a/backend/src/plugins/BotControl/commands/LeaveServerCmd.ts +++ b/backend/src/plugins/BotControl/commands/LeaveServerCmd.ts @@ -1,13 +1,13 @@ import { Snowflake, TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { botControlCmd } from "../types"; export const LeaveServerCmd = botControlCmd({ trigger: ["leave_server", "leave_guild"], permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, signature: { diff --git a/backend/src/plugins/BotControl/commands/ListDashboardPermsCmd.ts b/backend/src/plugins/BotControl/commands/ListDashboardPermsCmd.ts index dcfb166c..590522f1 100644 --- a/backend/src/plugins/BotControl/commands/ListDashboardPermsCmd.ts +++ b/backend/src/plugins/BotControl/commands/ListDashboardPermsCmd.ts @@ -2,7 +2,7 @@ import { TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { AllowedGuild } from "../../../data/entities/AllowedGuild"; import { ApiPermissionAssignment } from "../../../data/entities/ApiPermissionAssignment"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { resolveUser } from "../../../utils"; import { botControlCmd } from "../types"; diff --git a/backend/src/plugins/BotControl/commands/ListDashboardUsersCmd.ts b/backend/src/plugins/BotControl/commands/ListDashboardUsersCmd.ts index a97efca6..90fee6ff 100644 --- a/backend/src/plugins/BotControl/commands/ListDashboardUsersCmd.ts +++ b/backend/src/plugins/BotControl/commands/ListDashboardUsersCmd.ts @@ -1,6 +1,6 @@ import { TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { resolveUser } from "../../../utils"; import { botControlCmd } from "../types"; diff --git a/backend/src/plugins/BotControl/commands/ReloadGlobalPluginsCmd.ts b/backend/src/plugins/BotControl/commands/ReloadGlobalPluginsCmd.ts index 1b3629ce..0cd4ec0b 100644 --- a/backend/src/plugins/BotControl/commands/ReloadGlobalPluginsCmd.ts +++ b/backend/src/plugins/BotControl/commands/ReloadGlobalPluginsCmd.ts @@ -1,5 +1,5 @@ import { TextChannel } from "discord.js"; -import { isOwnerPreFilter } from "../../../pluginUtils"; +import { isStaffPreFilter } from "../../../pluginUtils"; import { getActiveReload, setActiveReload } from "../activeReload"; import { botControlCmd } from "../types"; @@ -7,7 +7,7 @@ export const ReloadGlobalPluginsCmd = botControlCmd({ trigger: "bot_reload_global_plugins", permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, async run({ pluginData, message }) { diff --git a/backend/src/plugins/BotControl/commands/ReloadServerCmd.ts b/backend/src/plugins/BotControl/commands/ReloadServerCmd.ts index 88193fba..645e4cf4 100644 --- a/backend/src/plugins/BotControl/commands/ReloadServerCmd.ts +++ b/backend/src/plugins/BotControl/commands/ReloadServerCmd.ts @@ -1,13 +1,13 @@ import { Snowflake, TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { botControlCmd } from "../types"; export const ReloadServerCmd = botControlCmd({ trigger: ["reload_server", "reload_guild"], permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, signature: { diff --git a/backend/src/plugins/BotControl/commands/RemoveDashboardUserCmd.ts b/backend/src/plugins/BotControl/commands/RemoveDashboardUserCmd.ts index dff4928d..d5dd674b 100644 --- a/backend/src/plugins/BotControl/commands/RemoveDashboardUserCmd.ts +++ b/backend/src/plugins/BotControl/commands/RemoveDashboardUserCmd.ts @@ -1,13 +1,13 @@ import { TextChannel } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; +import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { botControlCmd } from "../types"; export const RemoveDashboardUserCmd = botControlCmd({ trigger: ["remove_dashboard_user"], permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, signature: { diff --git a/backend/src/plugins/BotControl/commands/ServersCmd.ts b/backend/src/plugins/BotControl/commands/ServersCmd.ts index f8c91b61..cee486d2 100644 --- a/backend/src/plugins/BotControl/commands/ServersCmd.ts +++ b/backend/src/plugins/BotControl/commands/ServersCmd.ts @@ -1,7 +1,7 @@ import { TextChannel } from "discord.js"; import escapeStringRegexp from "escape-string-regexp"; import { commandTypeHelpers as ct } from "../../../commandTypes"; -import { isOwnerPreFilter } from "../../../pluginUtils"; +import { isStaffPreFilter } from "../../../pluginUtils"; import { createChunkedMessage, getUser, sorter } from "../../../utils"; import { botControlCmd } from "../types"; @@ -9,7 +9,7 @@ export const ServersCmd = botControlCmd({ trigger: ["servers", "guilds"], permission: null, config: { - preFilters: [isOwnerPreFilter], + preFilters: [isStaffPreFilter], }, signature: {