From ce370aa97dba202763681bfd096344d7ad58fe6d Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Fri, 1 Dec 2023 23:44:04 -0500 Subject: [PATCH] Change command permissions and modify help to read permissions --- bun.lockb | Bin 16396 -> 16792 bytes config/roles.yml | 2 +- package.json | 1 + src/commands/commands/general/help.ts | 8 ++++++++ src/commands/commands/utility/cursor.ts | 3 +-- src/commands/commands/utility/ic.ts | 24 ++++++++++++++++++++++++ src/commands/commands/utility/id.ts | 4 +--- src/commands/commands/utility/math.ts | 1 - src/commands/commands/utility/memory.ts | 4 +--- src/commands/commands/utility/msg.ts | 6 ++---- src/commands/commands/utility/role.ts | 4 +--- src/commands/index.ts | 3 ++- src/permissions/default.ts | 3 +-- src/services/console/MicroHandler.ts | 18 ++++++++++++++++-- 14 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 src/commands/commands/utility/ic.ts diff --git a/bun.lockb b/bun.lockb index 41ad0ca6ce7232d8f896ddf1d0ec3d7d98d258df..18433abd50f50978d67b915f983ce8656861d905 100755 GIT binary patch delta 2556 zcmd5;eQZ-z6u*gHv4KQJ*BT4`}HS#e(VCvWeREFSc z1j7QNaH4{uB0&RDj5uPbNWx-7kdF}jL(v)kFeHvdz>lc)`*&X3L=Ew8Px5=`{m#AT z-gD1=_uRK7E_XaGpZ3>p82xElW3umwtG~@2ym;{0_X^)$cjnM{zutTE$boy*&v$NB zX9`mqw#6!x-+bHFR1W9BkS#>KH?1FDmFjYn6hedj95njG3lt%8p$Av?t?FMY#2)ZT z;0w`RhtBv7TT*-$bUy5>2JXC%hg@Jy`S%T`#&>~Z-r=}vOF6`#d7@z2@vggjA6$mM z{popqbDm(5=us?zD7!WxBoC)Hx!q;)MtN zkao&i*+pZrNqu=ryur8e?%vU>QdRU%Fy(agK!n0V((a={i>eez`o$8FJ=AVBrN~C_+9R@;l6JF$YRF48q#BAhi{4cuh&rhn+J-D4Zh()Z zF||#erynMTeF-mHNB2>CQJEBZiX>E2yZl^@Hp`BBO=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mic.command.color - cosmic.command.id - cosmic.command.math - - cosmic.command.memory - cosmic.command.role MODERATOR: displayName: Moderator @@ -21,6 +20,7 @@ ADMINISTRATOR: inherits: MODERATOR permissions: - cosmic.commandGroup.* + - cosmic.command.ic OWNER: displayName: Owner permissions: diff --git a/package.json b/package.json index 13df48d..ee1dbc3 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "mpp-client-xt": "^1.3.1", "prisma": "^5.4.2", "switchchat": "^3.2.1", + "typescript": "^5.3.2", "yaml": "^2.3.3", "zod": "^3.22.4" } diff --git a/src/commands/commands/general/help.ts b/src/commands/commands/general/help.ts index 4a69bc2..81ae79c 100644 --- a/src/commands/commands/general/help.ts +++ b/src/commands/commands/general/help.ts @@ -1,3 +1,4 @@ +import { hasPermission } from "../../../permissions"; import { Command } from "../../Command"; import { CommandHandler } from "../../CommandHandler"; @@ -31,6 +32,13 @@ export const help = new Command( commandGroup.commands .map(command => { if (!command.visible) return; + if ( + !hasPermission( + msg.user.role, + `cosmic.command.${command.id}` + ) + ) + return; return command.aliases[0]; }) .filter(val => { diff --git a/src/commands/commands/utility/cursor.ts b/src/commands/commands/utility/cursor.ts index 7575071..b79e247 100644 --- a/src/commands/commands/utility/cursor.ts +++ b/src/commands/commands/utility/cursor.ts @@ -12,6 +12,5 @@ export const cursor = new Command( const cursor = (agent as MPPAgent).cursor; cursor.props.currentAnimation = msg.argv[1]; - }, - false + } ); diff --git a/src/commands/commands/utility/ic.ts b/src/commands/commands/utility/ic.ts new file mode 100644 index 0000000..a166ae3 --- /dev/null +++ b/src/commands/commands/utility/ic.ts @@ -0,0 +1,24 @@ +import { MicroHandler } from "../../../services/console/MicroHandler"; +import { Command } from "../../Command"; + +export const ic = new Command( + "ic", + ["ic"], + "use an internal command bozo", + "ic ", + async (msg, agent) => { + let argcat = msg.argv.slice(1, msg.argv.length).join(" "); + let args = argcat.split(" "); + return (await MicroHandler.handleMicroCommand( + { + m: "command", + a: argcat, + argc: args.length, + argv: args, + originalMessage: msg, + p: msg.p + }, + agent + )) as string; + } +); diff --git a/src/commands/commands/utility/id.ts b/src/commands/commands/utility/id.ts index a64f0ac..54d46ee 100644 --- a/src/commands/commands/utility/id.ts +++ b/src/commands/commands/utility/id.ts @@ -1,4 +1,3 @@ -import { MPPAgent } from "../../../services/mpp"; import { Command } from "../../Command"; export const id = new Command( @@ -14,6 +13,5 @@ export const id = new Command( } else { return `Cosmic ID: \`${msg.p._id}\``; } - }, - false + } ); diff --git a/src/commands/commands/utility/math.ts b/src/commands/commands/utility/math.ts index d675555..91c70ad 100644 --- a/src/commands/commands/utility/math.ts +++ b/src/commands/commands/utility/math.ts @@ -1,5 +1,4 @@ import { Command } from "../../Command"; - import { evaluate } from "mathjs"; export const math = new Command( diff --git a/src/commands/commands/utility/memory.ts b/src/commands/commands/utility/memory.ts index 6eba019..444e30c 100644 --- a/src/commands/commands/utility/memory.ts +++ b/src/commands/commands/utility/memory.ts @@ -1,4 +1,3 @@ -import { MPPAgent } from "../../../services/mpp"; import { Command } from "../../Command"; export const memory = new Command( @@ -12,6 +11,5 @@ export const memory = new Command( )} MB used / ${(process.memoryUsage().heapTotal / 1000 / 1000).toFixed( 2 )} MB total`; - }, - false + } ); diff --git a/src/commands/commands/utility/msg.ts b/src/commands/commands/utility/msg.ts index 0eaecca..8d09059 100644 --- a/src/commands/commands/utility/msg.ts +++ b/src/commands/commands/utility/msg.ts @@ -1,4 +1,3 @@ -import { MPPAgent } from "../../../services/mpp"; import { Command } from "../../Command"; export const msg = new Command( @@ -7,8 +6,7 @@ export const msg = new Command( "get your msg bozo", "msg", (msg, agent) => { - if (!(agent as MPPAgent).client.isConnected) return; + if (agent.platform !== "mpp") return; return `${JSON.stringify(msg)}`; - }, - false + } ); diff --git a/src/commands/commands/utility/role.ts b/src/commands/commands/utility/role.ts index d02cb42..23da6a4 100644 --- a/src/commands/commands/utility/role.ts +++ b/src/commands/commands/utility/role.ts @@ -1,5 +1,4 @@ import { getRole } from "../../../permissions"; -import { MPPAgent } from "../../../services/mpp"; import { Command } from "../../Command"; export const role = new Command( @@ -11,6 +10,5 @@ export const role = new Command( const role = getRole(msg.user.role); if (!role) return `Your role: ${msg.user.role} (this role is broken)`; return `Your role: ${role.displayName} [${msg.user.role}]`; - }, - false + } ); diff --git a/src/commands/index.ts b/src/commands/index.ts index 788487e..bff9427 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -11,6 +11,7 @@ import { cursor } from "./commands/utility/cursor"; import { inventory } from "./commands/economy/inventory"; import { color } from "./commands/utility/color"; import { role } from "./commands/utility/role"; +import { ic } from "./commands/utility/ic"; export function loadCommands() { // cringe @@ -27,6 +28,6 @@ export function loadCommands() { CommandHandler.addCommandGroup(fun); const utility = new CommandGroup("utility", "🔨 Utility"); - utility.addCommands([math, memory, id, msg, cursor, color, role]); + utility.addCommands([math, memory, id, msg, cursor, color, role, ic]); CommandHandler.addCommandGroup(utility); } diff --git a/src/permissions/default.ts b/src/permissions/default.ts index 1904f93..d455eab 100644 --- a/src/permissions/default.ts +++ b/src/permissions/default.ts @@ -14,7 +14,6 @@ export const defaultConfig = { "cosmic.command.color", "cosmic.command.id", "cosmic.command.math", - "cosmic.command.memory", "cosmic.command.role" ] }, @@ -30,7 +29,7 @@ export const defaultConfig = { ADMINISTRATOR: { displayName: "Administrator", inherits: "MODERATOR", - permissions: ["cosmic.commandGroup.*"] + permissions: ["cosmic.commandGroup.*", "cosmic.command.ic"] }, OWNER: { displayName: "Owner", diff --git a/src/services/console/MicroHandler.ts b/src/services/console/MicroHandler.ts index 20d7e23..6244333 100644 --- a/src/services/console/MicroHandler.ts +++ b/src/services/console/MicroHandler.ts @@ -55,7 +55,7 @@ export class MicroHandler { case "commands": case "cmds": default: - return "Microcommands: /help | /js | /exit | /list | /view | /unview | /admin+ "; + return "Microcommands: /help | /js | /exit | /list | /view | /unview | /admin+ | /admin- | /owner+ "; break; case "js": case "eval": @@ -173,7 +173,6 @@ export class MicroHandler { 0, 6 )}...] an administrator`; - break; case "admin-": const userId2 = command.argv @@ -190,7 +189,22 @@ export class MicroHandler { 0, 6 )}...] a normal user.`; + break; + case "owner+": + const userId3 = command.argv + .slice(1, command.argv.length) + .join(" "); + let user3 = await readUser(userId3); + if (!user3) return "No such user."; + + user3.role = Role.OWNER; + await updateUser(user3); + + return `Made user "${user3.name}" [${user3.platformId.substring( + 0, + 6 + )}...] an owner`; break; } }