Update id command, add basic permission stuff (no code yet), messing with mpp channel config
This commit is contained in:
parent
33b55647ad
commit
ec5064e493
|
@ -4,5 +4,7 @@ desiredUser:
|
||||||
agents:
|
agents:
|
||||||
wss://mppclone.com:
|
wss://mppclone.com:
|
||||||
- id: "✧𝓓𝓔𝓥 𝓡𝓸𝓸𝓶✧"
|
- id: "✧𝓓𝓔𝓥 𝓡𝓸𝓸𝓶✧"
|
||||||
|
# - id: "Anime/Touhou & Modern"
|
||||||
|
- id: "test/awkward"
|
||||||
# - id: "wizardposting"
|
# - id: "wizardposting"
|
||||||
# - id: Room163249719601
|
# - id: Room163249719601
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
user:
|
||||||
|
|
||||||
|
moderator:
|
||||||
|
|
||||||
|
admin:
|
|
@ -8,7 +8,9 @@ export const id = new Command(
|
||||||
"id",
|
"id",
|
||||||
(msg, agent) => {
|
(msg, agent) => {
|
||||||
if (!(agent as MPPAgent).client.isConnected) return;
|
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
|
false
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,46 @@
|
||||||
|
import { ConsoleAgent } from ".";
|
||||||
import { ServiceLoader } from "..";
|
import { ServiceLoader } from "..";
|
||||||
import { scopedEval } from "../..";
|
import { scopedEval } from "../..";
|
||||||
import { BaseCommandMessage } from "../../commands/CommandHandler";
|
import { BaseCommandMessage } from "../../commands/CommandHandler";
|
||||||
|
import { CosmicColor } from "../../util/CosmicColor";
|
||||||
import { ServiceAgent } from "../ServiceAgent";
|
import { ServiceAgent } from "../ServiceAgent";
|
||||||
import { MPPAgent } from "../mpp";
|
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 {
|
export class MicroHandler {
|
||||||
public static async handleMicroCommand(
|
public static async handleMicroCommand(
|
||||||
command: BaseCommandMessage,
|
command: BaseCommandMessage,
|
||||||
|
@ -16,10 +53,11 @@ export class MicroHandler {
|
||||||
case "commands":
|
case "commands":
|
||||||
case "cmds":
|
case "cmds":
|
||||||
default:
|
default:
|
||||||
return "Microcommands: /help | /js | /exit | /list | /view";
|
return "Microcommands: /help | /js <expr> | /exit | /list | /view <index> | /unview";
|
||||||
break;
|
break;
|
||||||
case "js":
|
case "js":
|
||||||
case "eval":
|
case "eval":
|
||||||
|
if (!command.argv[1]) return "Error: No arguments provided";
|
||||||
try {
|
try {
|
||||||
const out = scopedEval(command.argv.slice(1).join(" "));
|
const out = scopedEval(command.argv.slice(1).join(" "));
|
||||||
return `(${typeof out}) ${out}`;
|
return `(${typeof out}) ${out}`;
|
||||||
|
@ -54,7 +92,69 @@ export class MicroHandler {
|
||||||
if (agent.platform !== "console")
|
if (agent.platform !== "console")
|
||||||
return "This command is only for console agents.";
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,11 @@ export class ConsoleAgent extends ServiceAgent<readline.ReadLine> {
|
||||||
out = await CommandHandler.handleCommand(message, this);
|
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();
|
this.client.prompt();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Client from "mpp-client-net";
|
||||||
import { ServiceAgent } from "../ServiceAgent";
|
import { ServiceAgent } from "../ServiceAgent";
|
||||||
import { CommandHandler } from "../../commands/CommandHandler";
|
import { CommandHandler } from "../../commands/CommandHandler";
|
||||||
import { Cursor } from "./Cursor";
|
import { Cursor } from "./Cursor";
|
||||||
|
import { ChatMessage } from "../console/MicroHandler";
|
||||||
|
|
||||||
export class MPPAgent extends ServiceAgent<Client> {
|
export class MPPAgent extends ServiceAgent<Client> {
|
||||||
public cursor: Cursor;
|
public cursor: Cursor;
|
||||||
|
@ -38,6 +39,20 @@ export class MPPAgent extends ServiceAgent<Client> {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.client.on("a", async msg => {
|
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(" ");
|
let args = msg.a.split(" ");
|
||||||
|
|
||||||
const str = await CommandHandler.handleCommand(
|
const str = await CommandHandler.handleCommand(
|
||||||
|
@ -47,7 +62,7 @@ export class MPPAgent extends ServiceAgent<Client> {
|
||||||
argc: args.length,
|
argc: args.length,
|
||||||
argv: args,
|
argv: args,
|
||||||
p: {
|
p: {
|
||||||
_id: "MPP_" + this.client.uri + "_" + msg.p._id,
|
_id,
|
||||||
name: msg.p.name,
|
name: msg.p.name,
|
||||||
color: msg.p.color,
|
color: msg.p.color,
|
||||||
platformId: msg.p._id
|
platformId: msg.p._id
|
||||||
|
@ -70,15 +85,19 @@ export class MPPAgent extends ServiceAgent<Client> {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.client.sendArray([
|
this.emit("send chat", str);
|
||||||
{
|
|
||||||
m: "a",
|
|
||||||
message: `\u034f${str}`
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.on("send chat", text => {
|
||||||
|
this.client.sendArray([
|
||||||
|
{
|
||||||
|
m: "a",
|
||||||
|
message: `\u034f${text}`
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public fixUser() {
|
public fixUser() {
|
||||||
|
|
Loading…
Reference in New Issue