diff --git a/bun.lockb b/bun.lockb index 51508de..e0f28ce 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 2882d02..090c180 100644 --- a/package.json +++ b/package.json @@ -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" } } \ No newline at end of file diff --git a/src/services/ServiceAgent.ts b/src/services/ServiceAgent.ts new file mode 100644 index 0000000..6f226ad --- /dev/null +++ b/src/services/ServiceAgent.ts @@ -0,0 +1,10 @@ +import EventEmitter from "events"; + +export abstract class ServiceAgent extends EventEmitter { + constructor(public client: T) { + super(); + } + + public abstract start(): void; + public abstract stop(): void; +} diff --git a/src/services/index.ts b/src/services/index.ts index 80160ed..16a9375 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -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>(); + + public static loadServices() { + const testAgent = new MPPAgent("wss://mppclone.com", env.MPPNET_TOKEN); + testAgent.start(); + } } diff --git a/src/services/mpp/index.ts b/src/services/mpp/index.ts index e69de29..991a5e4 100644 --- a/src/services/mpp/index.ts +++ b/src/services/mpp/index.ts @@ -0,0 +1,19 @@ +import Client from "mpp-client-net"; +import { ServiceAgent } from "../ServiceAgent"; + +export class MPPAgent extends ServiceAgent { + 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(); + } +} diff --git a/src/util/env.ts b/src/util/env.ts new file mode 100644 index 0000000..b5615c2 --- /dev/null +++ b/src/util/env.ts @@ -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;