Update id command, add basic permission stuff (no code yet), messing with mpp channel config

This commit is contained in:
Hri7566 2023-11-10 02:07:26 -05:00
parent 33b55647ad
commit ec5064e493
7 changed files with 143 additions and 11 deletions

View File

@ -4,5 +4,7 @@ desiredUser:
agents:
wss://mppclone.com:
- id: "✧𝓓𝓔𝓥 𝓡𝓸𝓸𝓶✧"
# - id: "Anime/Touhou & Modern"
- id: "test/awkward"
# - id: "wizardposting"
# - id: Room163249719601

5
config/permissions.yml Normal file
View File

@ -0,0 +1,5 @@
user:
moderator:
admin:

View File

@ -8,7 +8,9 @@ export const id = new Command(
"id",
(msg, agent) => {
if (!(agent as MPPAgent).client.isConnected) return;
return `ID: \`${(msg.originalMessage as any).p._id}\``;
return `ID: \`${(msg.originalMessage as any).p._id}\` Cosmic ID: \`${
msg.p._id
}\``;
},
false
);

View File

@ -1,9 +1,46 @@
import { ConsoleAgent } from ".";
import { ServiceLoader } from "..";
import { scopedEval } from "../..";
import { BaseCommandMessage } from "../../commands/CommandHandler";
import { CosmicColor } from "../../util/CosmicColor";
import { ServiceAgent } from "../ServiceAgent";
import { MPPAgent } from "../mpp";
export interface ChatMessage<T = unknown> {
m: "a";
a: string;
p: {
_id: string;
platformId: string;
name: string;
color: string;
};
originalMessage: T;
}
function onChildMessage(msg: ChatMessage) {
const consoleAgent = ServiceLoader.agents.find(
ag => ag.platform == "console"
) as ConsoleAgent | undefined;
if (!consoleAgent) return;
consoleAgent.logger.info(
`[${msg.p.platformId.substring(0, 6)}] ${msg.p.name}: ${msg.a}`
);
}
function onConsoleMessage(text: string) {
const consoleAgent = ServiceLoader.agents.find(
ag => ag.platform == "console"
) as ConsoleAgent | undefined;
if (!consoleAgent) return;
if (!consoleAgent.viewAgent) return;
consoleAgent.viewAgent.emit("send chat", `[Console] ${text}`);
}
export class MicroHandler {
public static async handleMicroCommand(
command: BaseCommandMessage,
@ -16,10 +53,11 @@ export class MicroHandler {
case "commands":
case "cmds":
default:
return "Microcommands: /help | /js | /exit | /list | /view";
return "Microcommands: /help | /js <expr> | /exit | /list | /view <index> | /unview";
break;
case "js":
case "eval":
if (!command.argv[1]) return "Error: No arguments provided";
try {
const out = scopedEval(command.argv.slice(1).join(" "));
return `(${typeof out}) ${out}`;
@ -54,7 +92,69 @@ export class MicroHandler {
if (agent.platform !== "console")
return "This command is only for console agents.";
return "WIP";
try {
let index = parseInt(command.argv[1]);
if (typeof index !== "number")
return "Please provide an index. (check /list)";
let walkie = agent as ConsoleAgent;
let talky = ServiceLoader.agents[index];
if (index == ServiceLoader.agents.indexOf(walkie))
return "Why would you want to chat with yourself?";
// Remove old listeners
if (walkie.viewAgent) {
walkie.viewAgent.off("chat", onChildMessage);
walkie.off("send chat", onConsoleMessage);
}
// Add new listeners
walkie.viewAgent = talky;
walkie.viewAgent.on("chat", onChildMessage);
walkie.on("send chat", onConsoleMessage);
return `Now veiwing agent ${index}`;
} catch (err) {
agent.logger.error(err);
}
break;
case "unview":
case "stopview":
case "stopviewing":
if (agent.platform !== "console")
return "This command is only for console agents.";
try {
let walkie = agent as ConsoleAgent;
// Remove old listeners
if (walkie.viewAgent) {
walkie.viewAgent.off("chat", onChildMessage);
walkie.off("send chat", onConsoleMessage);
}
delete walkie.viewAgent;
} catch (err) {
agent.logger.error(err);
}
break;
case "ppl":
if (agent.platform !== "console")
return "This command is only for console agents.";
let conAg = agent as ConsoleAgent;
if (!conAg.viewAgent) return "There is no agent being viewed.";
if (conAg.viewAgent.platform !== "mpp")
return "The view agent is not on MPP.";
const ppl = (conAg.viewAgent as MPPAgent).client.ppl;
return `MPP Users: ${Object.values(ppl).map(
p =>
`\n - ${p._id} (user) / ${p.id} (part): ${p.name} (${
p.color
}, ${new CosmicColor(p.color).getName()})`
)}`;
break;
}
}

View File

@ -73,7 +73,11 @@ export class ConsoleAgent extends ServiceAgent<readline.ReadLine> {
out = await CommandHandler.handleCommand(message, this);
}
if (out) this.logger.info(out);
if (out) {
this.logger.info(out);
} else {
this.emit("send chat", message.a);
}
this.client.prompt();
});
}

View File

@ -2,6 +2,7 @@ import Client from "mpp-client-net";
import { ServiceAgent } from "../ServiceAgent";
import { CommandHandler } from "../../commands/CommandHandler";
import { Cursor } from "./Cursor";
import { ChatMessage } from "../console/MicroHandler";
export class MPPAgent extends ServiceAgent<Client> {
public cursor: Cursor;
@ -38,6 +39,20 @@ export class MPPAgent extends ServiceAgent<Client> {
});
this.client.on("a", async msg => {
const _id = "MPP_" + this.client.uri + "_" + msg.p._id;
this.emit("chat", {
m: "a",
a: msg.a,
p: {
_id,
name: msg.p.name,
color: msg.p.color,
platformId: msg.p._id
},
originalMessage: msg
} as ChatMessage);
let args = msg.a.split(" ");
const str = await CommandHandler.handleCommand(
@ -47,7 +62,7 @@ export class MPPAgent extends ServiceAgent<Client> {
argc: args.length,
argv: args,
p: {
_id: "MPP_" + this.client.uri + "_" + msg.p._id,
_id,
name: msg.p.name,
color: msg.p.color,
platformId: msg.p._id
@ -70,15 +85,19 @@ export class MPPAgent extends ServiceAgent<Client> {
]);
}
} else {
this.client.sendArray([
{
m: "a",
message: `\u034f${str}`
}
]);
this.emit("send chat", str);
}
}
});
this.on("send chat", text => {
this.client.sendArray([
{
m: "a",
message: `\u034f${text}`
}
]);
});
}
public fixUser() {

0
src/util/permission.ts Normal file
View File