Partial agent setup

This commit is contained in:
Hri7566 2023-10-16 13:14:02 -04:00
parent 5fff41105e
commit 1cdfd3c82c
6 changed files with 55 additions and 11 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -9,8 +9,12 @@
"typescript": "^5.0.0"
},
"dependencies": {
"@t3-oss/env-core": "^0.7.1",
"dotenv": "^16.3.1",
"hyperimport": "^0.1.0",
"mpp-client-net": "^1.1.3",
"prisma": "^5.4.2"
"mpp-client-xt": "^1.3.1",
"prisma": "^5.4.2",
"zod": "^3.22.4"
}
}

View File

@ -0,0 +1,10 @@
import EventEmitter from "events";
export abstract class ServiceAgent<T> extends EventEmitter {
constructor(public client: T) {
super();
}
public abstract start(): void;
public abstract stop(): void;
}

View File

@ -1,14 +1,13 @@
import EventEmitter from "events";
export abstract class ServiceAgent extends EventEmitter {
constructor() {
super();
}
public abstract start(): void;
public abstract stop(): void;
}
import { MPPAgent } from "./mpp";
import env from "../util/env";
import { ServiceAgent } from "./ServiceAgent";
export class ServiceLoader {
public static loadServices() {}
public static agents = new Array<ServiceAgent<unknown>>();
public static loadServices() {
const testAgent = new MPPAgent("wss://mppclone.com", env.MPPNET_TOKEN);
testAgent.start();
}
}

View File

@ -0,0 +1,19 @@
import Client from "mpp-client-net";
import { ServiceAgent } from "../ServiceAgent";
export class MPPAgent extends ServiceAgent<Client> {
constructor(uri: string, token: string) {
const cl = new Client(uri, token);
super(cl);
}
public start() {
this.client.start();
// TODO get rid of this gay shit
this.client.setChannel("Simon Says");
}
public stop() {
this.client.stop();
}
}

12
src/util/env.ts Normal file
View File

@ -0,0 +1,12 @@
import z from "zod";
import { createEnv } from "@t3-oss/env-core";
export const env = createEnv({
isServer: true,
server: {
MPPNET_TOKEN: z.string()
},
runtimeEnv: process.env
});
export default env;