Change command permissions and modify help to read permissions

This commit is contained in:
Hri7566 2023-12-01 23:44:04 -05:00
parent bd98acab2a
commit ce370aa97d
14 changed files with 59 additions and 22 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -7,7 +7,6 @@ NONE:
- cosmic.command.color - cosmic.command.color
- cosmic.command.id - cosmic.command.id
- cosmic.command.math - cosmic.command.math
- cosmic.command.memory
- cosmic.command.role - cosmic.command.role
MODERATOR: MODERATOR:
displayName: Moderator displayName: Moderator
@ -21,6 +20,7 @@ ADMINISTRATOR:
inherits: MODERATOR inherits: MODERATOR
permissions: permissions:
- cosmic.commandGroup.* - cosmic.commandGroup.*
- cosmic.command.ic
OWNER: OWNER:
displayName: Owner displayName: Owner
permissions: permissions:

View File

@ -18,6 +18,7 @@
"mpp-client-xt": "^1.3.1", "mpp-client-xt": "^1.3.1",
"prisma": "^5.4.2", "prisma": "^5.4.2",
"switchchat": "^3.2.1", "switchchat": "^3.2.1",
"typescript": "^5.3.2",
"yaml": "^2.3.3", "yaml": "^2.3.3",
"zod": "^3.22.4" "zod": "^3.22.4"
} }

View File

@ -1,3 +1,4 @@
import { hasPermission } from "../../../permissions";
import { Command } from "../../Command"; import { Command } from "../../Command";
import { CommandHandler } from "../../CommandHandler"; import { CommandHandler } from "../../CommandHandler";
@ -31,6 +32,13 @@ export const help = new Command(
commandGroup.commands commandGroup.commands
.map(command => { .map(command => {
if (!command.visible) return; if (!command.visible) return;
if (
!hasPermission(
msg.user.role,
`cosmic.command.${command.id}`
)
)
return;
return command.aliases[0]; return command.aliases[0];
}) })
.filter(val => { .filter(val => {

View File

@ -12,6 +12,5 @@ export const cursor = new Command(
const cursor = (agent as MPPAgent).cursor; const cursor = (agent as MPPAgent).cursor;
cursor.props.currentAnimation = msg.argv[1]; cursor.props.currentAnimation = msg.argv[1];
}, }
false
); );

View File

@ -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 <command>",
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;
}
);

View File

@ -1,4 +1,3 @@
import { MPPAgent } from "../../../services/mpp";
import { Command } from "../../Command"; import { Command } from "../../Command";
export const id = new Command( export const id = new Command(
@ -14,6 +13,5 @@ export const id = new Command(
} else { } else {
return `Cosmic ID: \`${msg.p._id}\``; return `Cosmic ID: \`${msg.p._id}\``;
} }
}, }
false
); );

View File

@ -1,5 +1,4 @@
import { Command } from "../../Command"; import { Command } from "../../Command";
import { evaluate } from "mathjs"; import { evaluate } from "mathjs";
export const math = new Command( export const math = new Command(

View File

@ -1,4 +1,3 @@
import { MPPAgent } from "../../../services/mpp";
import { Command } from "../../Command"; import { Command } from "../../Command";
export const memory = new Command( export const memory = new Command(
@ -12,6 +11,5 @@ export const memory = new Command(
)} MB used / ${(process.memoryUsage().heapTotal / 1000 / 1000).toFixed( )} MB used / ${(process.memoryUsage().heapTotal / 1000 / 1000).toFixed(
2 2
)} MB total`; )} MB total`;
}, }
false
); );

View File

@ -1,4 +1,3 @@
import { MPPAgent } from "../../../services/mpp";
import { Command } from "../../Command"; import { Command } from "../../Command";
export const msg = new Command( export const msg = new Command(
@ -7,8 +6,7 @@ export const msg = new Command(
"get your msg bozo", "get your msg bozo",
"msg", "msg",
(msg, agent) => { (msg, agent) => {
if (!(agent as MPPAgent).client.isConnected) return; if (agent.platform !== "mpp") return;
return `${JSON.stringify(msg)}`; return `${JSON.stringify(msg)}`;
}, }
false
); );

View File

@ -1,5 +1,4 @@
import { getRole } from "../../../permissions"; import { getRole } from "../../../permissions";
import { MPPAgent } from "../../../services/mpp";
import { Command } from "../../Command"; import { Command } from "../../Command";
export const role = new Command( export const role = new Command(
@ -11,6 +10,5 @@ export const role = new Command(
const role = getRole(msg.user.role); const role = getRole(msg.user.role);
if (!role) return `Your role: ${msg.user.role} (this role is broken)`; if (!role) return `Your role: ${msg.user.role} (this role is broken)`;
return `Your role: ${role.displayName} [${msg.user.role}]`; return `Your role: ${role.displayName} [${msg.user.role}]`;
}, }
false
); );

View File

@ -11,6 +11,7 @@ import { cursor } from "./commands/utility/cursor";
import { inventory } from "./commands/economy/inventory"; import { inventory } from "./commands/economy/inventory";
import { color } from "./commands/utility/color"; import { color } from "./commands/utility/color";
import { role } from "./commands/utility/role"; import { role } from "./commands/utility/role";
import { ic } from "./commands/utility/ic";
export function loadCommands() { export function loadCommands() {
// cringe // cringe
@ -27,6 +28,6 @@ export function loadCommands() {
CommandHandler.addCommandGroup(fun); CommandHandler.addCommandGroup(fun);
const utility = new CommandGroup("utility", "🔨 Utility"); 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); CommandHandler.addCommandGroup(utility);
} }

View File

@ -14,7 +14,6 @@ export const defaultConfig = {
"cosmic.command.color", "cosmic.command.color",
"cosmic.command.id", "cosmic.command.id",
"cosmic.command.math", "cosmic.command.math",
"cosmic.command.memory",
"cosmic.command.role" "cosmic.command.role"
] ]
}, },
@ -30,7 +29,7 @@ export const defaultConfig = {
ADMINISTRATOR: { ADMINISTRATOR: {
displayName: "Administrator", displayName: "Administrator",
inherits: "MODERATOR", inherits: "MODERATOR",
permissions: ["cosmic.commandGroup.*"] permissions: ["cosmic.commandGroup.*", "cosmic.command.ic"]
}, },
OWNER: { OWNER: {
displayName: "Owner", displayName: "Owner",

View File

@ -55,7 +55,7 @@ export class MicroHandler {
case "commands": case "commands":
case "cmds": case "cmds":
default: default:
return "Microcommands: /help | /js <expr> | /exit | /list | /view <index> | /unview | /admin+ <id>"; return "Microcommands: /help | /js <expr> | /exit | /list | /view <index> | /unview | /admin+ <id> | /admin- <id> | /owner+ <id>";
break; break;
case "js": case "js":
case "eval": case "eval":
@ -173,7 +173,6 @@ export class MicroHandler {
0, 0,
6 6
)}...] an administrator`; )}...] an administrator`;
break; break;
case "admin-": case "admin-":
const userId2 = command.argv const userId2 = command.argv
@ -190,7 +189,22 @@ export class MicroHandler {
0, 0,
6 6
)}...] a normal user.`; )}...] 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; break;
} }
} }