Change command permissions and modify help to read permissions
This commit is contained in:
parent
bd98acab2a
commit
ce370aa97d
|
@ -7,7 +7,6 @@ NONE:
|
|||
- cosmic.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:
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -12,6 +12,5 @@ export const cursor = new Command(
|
|||
|
||||
const cursor = (agent as MPPAgent).cursor;
|
||||
cursor.props.currentAnimation = msg.argv[1];
|
||||
},
|
||||
false
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
);
|
|
@ -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
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Command } from "../../Command";
|
||||
|
||||
import { evaluate } from "mathjs";
|
||||
|
||||
export const math = new Command(
|
||||
|
|
|
@ -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
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -55,7 +55,7 @@ export class MicroHandler {
|
|||
case "commands":
|
||||
case "cmds":
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue