Remove console.log statements, replace some with logger.info, color command, decent modifications to console commands

This commit is contained in:
Hri7566 2023-11-09 06:15:27 -05:00
parent cb4c84f932
commit 33b55647ad
10 changed files with 1182 additions and 12 deletions

View File

@ -3,5 +3,6 @@ desiredUser:
color: "#1d0054"
agents:
wss://mppclone.com:
# - id: "✧𝓓𝓔𝓥 𝓡𝓸𝓸𝓶✧"
- id: "wizardposting"
- id: "✧𝓓𝓔𝓥 𝓡𝓸𝓸𝓶✧"
# - id: "wizardposting"
# - id: Room163249719601

View File

@ -1,4 +1,4 @@
enableMPP: false
enableMPP: true
enableDiscord: false
enableConsole: true
enableSwitchChat: false

View File

@ -0,0 +1,51 @@
import { MPPAgent } from "../../../services/mpp";
import { CosmicColor } from "../../../util/CosmicColor";
import { Command } from "../../Command";
export const color = new Command(
"color",
["color"],
"colors, bozo",
"color [<r> <g> <b> | <hex>]",
(msg, agent) => {
if (msg.argv[3]) {
// test for rgb
try {
let rstr = msg.argv[1];
let gstr = msg.argv[2];
let bstr = msg.argv[3];
let r = parseInt(rstr);
let g = parseInt(gstr);
let b = parseInt(bstr);
if (r > 255 || g > 255 || b > 255) throw "too large";
if (r < 0 || g < 0 || b < 0) throw "too small";
let c = new CosmicColor(r, g, b);
let outc = `${c.getName().replace("A", "a")} [${c.toHexa()}]`;
return `The RGB color ${r}, ${g}, ${b} is ${outc}`;
} catch (e) {
return `The color '${msg.argv[1]}, ${msg.argv[2]}, ${msg.argv[3]}' is not a valid RGB color. Reason: ${e}`;
}
} else if (msg.argv[1]) {
if (msg.argv[1].match(/#[0-9a-f]{6}/gi) !== null) {
// definitely a hex string
let c = new CosmicColor(msg.argv[1]);
let outc = `${c.getName().replace("A", "a")} [${c.toHexa()}]`;
return `The hex color '${msg.argv[1]}' is ${outc}`;
} else {
return `I don't think '${msg.argv[1]}' is a hex color.`;
}
} else {
if (msg.p.color) {
let c = new CosmicColor(msg.p.color);
let outc = `${c.getName().replace("A", "a")} [${c.toHexa()}]`;
return `${msg.p.name}, your color is ${outc}`;
} else {
return `You... have no color property or something? I guess just look at the command usage and manually choose a color so this doesn't happen.`;
}
}
},
false
);

View File

@ -8,6 +8,7 @@ import { math } from "./commands/utility/math";
import { memory } from "./commands/utility/memory";
import { cursor } from "./commands/utility/cursor";
import { inventory } from "./commands/economy/inventory";
import { color } from "./commands/utility/color";
export function loadCommands() {
const general = new CommandGroup("general", "⭐ General");
@ -19,6 +20,6 @@ export function loadCommands() {
CommandHandler.addCommandGroup(economy);
const utility = new CommandGroup("utility", "🔨 Utility");
utility.addCommands([math, memory, id, msg, cursor]);
utility.addCommands([math, memory, id, msg, cursor, color]);
CommandHandler.addCommandGroup(utility);
}

View File

@ -1,8 +1,12 @@
import EventEmitter from "events";
import { Logger } from "../util/Logger";
export abstract class ServiceAgent<T> extends EventEmitter {
public logger: Logger;
constructor(public platform: string, public client: T) {
super();
this.logger = new Logger(platform);
this.bindEventListeners();
}
@ -10,6 +14,6 @@ export abstract class ServiceAgent<T> extends EventEmitter {
public abstract stop(): void;
protected bindEventListeners() {
this.on("log", txt => console.log(txt));
this.on("log", txt => this.logger.info(txt));
}
}

View File

@ -1,8 +1,14 @@
import { ServiceLoader } from "..";
import { scopedEval } from "../..";
import { BaseCommandMessage } from "../../commands/CommandHandler";
import { ServiceAgent } from "../ServiceAgent";
import { MPPAgent } from "../mpp";
export class MicroHandler {
public static async handleMicroCommand(command: BaseCommandMessage) {
public static async handleMicroCommand(
command: BaseCommandMessage,
agent: ServiceAgent<unknown>
) {
let microcommand = command.argv[0].substring(1);
switch (microcommand) {
@ -10,7 +16,7 @@ export class MicroHandler {
case "commands":
case "cmds":
default:
return "Microcommands: /help | /js | /exit";
return "Microcommands: /help | /js | /exit | /list | /view";
break;
case "js":
case "eval":
@ -25,6 +31,31 @@ export class MicroHandler {
case "stop":
process.exit();
break;
case "list":
if (agent.platform !== "console")
return "This command is only for console agents.";
for (let i in ServiceLoader.agents) {
const agent2 = ServiceLoader.agents[i];
if (agent2.platform == "mpp") {
agent.emit(
"log",
`${i} - ${agent2.platform} - ${
(agent2 as MPPAgent).desiredChannel
}`
);
} else {
agent.emit("log", `${i} - ${agent2.platform}`);
}
}
break;
case "view":
case "connect":
if (agent.platform !== "console")
return "This command is only for console agents.";
return "WIP";
break;
}
}
}

View File

@ -19,6 +19,7 @@ export class ConsoleAgent extends ServiceAgent<readline.ReadLine> {
};
public logger = new Logger("Console");
public viewAgent: ServiceAgent<unknown> | undefined;
constructor() {
const cl = readline.createInterface({
@ -67,7 +68,7 @@ export class ConsoleAgent extends ServiceAgent<readline.ReadLine> {
let out;
if (text.startsWith("/")) {
out = await MicroHandler.handleMicroCommand(message);
out = await MicroHandler.handleMicroCommand(message, this);
} else {
out = await CommandHandler.handleCommand(message, this);
}

View File

@ -290,7 +290,6 @@ export class Cursor {
this.props.position.y <= 0
) {
this.props.velocity.y = -this.props.velocity.y;
console.log(this.props.velocity, "setting!!!");
}
this.props.ot = Date.now();

View File

@ -14,7 +14,6 @@ export class MPPAgent extends ServiceAgent<Client> {
) {
const cl = new Client(uri, token);
super("mpp", cl);
this.emit("log", desiredChannel);
this.cursor = new Cursor(this);
}
@ -30,7 +29,6 @@ export class MPPAgent extends ServiceAgent<Client> {
super.bindEventListeners();
this.client.on("hi", msg => {
this.emit("log", msg.u);
this.client.setChannel(this.desiredChannel);
this.fixUser();
});
@ -40,7 +38,6 @@ export class MPPAgent extends ServiceAgent<Client> {
});
this.client.on("a", async msg => {
console.log(`${msg.p.name}: ${msg.a}`);
let args = msg.a.split(" ");
const str = await CommandHandler.handleCommand(

1085
src/util/CosmicColor.ts Normal file

File diff suppressed because it is too large Load Diff