begin implementing fluxer bot
This commit is contained in:
6
adapters/fluxer/src/config/env/env.schema.ts
vendored
Normal file
6
adapters/fluxer/src/config/env/env.schema.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import z from "zod";
|
||||
|
||||
export const EnvSchema = z.object({
|
||||
FLUXER_APPLICATION_ID: z.string(),
|
||||
FLUXER_TOKEN: z.string(),
|
||||
});
|
||||
29
adapters/fluxer/src/config/env/index.ts
vendored
Normal file
29
adapters/fluxer/src/config/env/index.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import dotenv from "dotenv";
|
||||
import dotenvExpand from "dotenv-expand";
|
||||
import { EnvSchema } from "./env.schema";
|
||||
|
||||
const envFile =
|
||||
process.env.NODE_ENV === "production" ? ".env.prod" : ".env.dev";
|
||||
|
||||
const envPath = join(process.cwd(), envFile);
|
||||
|
||||
const rawEnv = Buffer.from(
|
||||
readFileSync(envPath, {
|
||||
encoding: "utf8",
|
||||
}),
|
||||
);
|
||||
|
||||
const envJson = { processEnv: dotenv.parse(rawEnv) };
|
||||
|
||||
const targetObj = {};
|
||||
|
||||
const expandedEnv = dotenvExpand.expand({
|
||||
processEnv: targetObj,
|
||||
parsed: envJson.processEnv,
|
||||
}) as { processEnv: Record<string, string> };
|
||||
|
||||
const env = EnvSchema.parse(expandedEnv.processEnv);
|
||||
|
||||
export default env;
|
||||
@@ -1,5 +1,6 @@
|
||||
import type z from "zod";
|
||||
import type { ConfigSchema } from "./config.schema";
|
||||
import env from "./env";
|
||||
|
||||
export const config: z.output<typeof ConfigSchema> = {
|
||||
channelMapping: {
|
||||
@@ -10,7 +11,7 @@ export const config: z.output<typeof ConfigSchema> = {
|
||||
help: "",
|
||||
introduction: "1473060169972367394",
|
||||
news: "",
|
||||
notification: "1473380467480031548",
|
||||
log: "1473380467480031548",
|
||||
"off-topic": "1473029758951358491",
|
||||
rules: "1473070476174811195",
|
||||
testing: "",
|
||||
@@ -37,7 +38,7 @@ export const config: z.output<typeof ConfigSchema> = {
|
||||
serverId: "1473029758951358488",
|
||||
version: 1,
|
||||
fluxer: {
|
||||
token: process.env.FLUXER_TOKEN || "",
|
||||
applicationId: process.env.FLUXER_APPLICATION_ID || "",
|
||||
token: env.FLUXER_TOKEN,
|
||||
applicationId: env.FLUXER_APPLICATION_ID,
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
import { config } from "config";
|
||||
import client from "lib/client";
|
||||
import { logger } from "lib/common-logger";
|
||||
|
||||
export class LogChannelService {
|
||||
private logChannelId = config.channelMapping.text.log;
|
||||
|
||||
async getLogChannel() {
|
||||
const logChannel = await client.channels.fetch(this.logChannelId);
|
||||
|
||||
if (logChannel.isSendable()) {
|
||||
return logChannel;
|
||||
} else {
|
||||
logger.fatal("Log channel not found or is not text-based.");
|
||||
throw new Error("Log channel not found or is not text-based");
|
||||
}
|
||||
}
|
||||
|
||||
async sendLogMessage(message: string) {
|
||||
const logChannel = await this.getLogChannel();
|
||||
|
||||
await logChannel.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
export const logChannelService = new LogChannelService();
|
||||
1
adapters/fluxer/src/index.ts
Normal file
1
adapters/fluxer/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
import "lib/client";
|
||||
11
adapters/fluxer/src/lib/client.ts
Normal file
11
adapters/fluxer/src/lib/client.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Client } from "@fluxerjs/core";
|
||||
import { config } from "config";
|
||||
import { logger } from "./common-logger";
|
||||
|
||||
const client = new Client({ intents: 0 });
|
||||
|
||||
await client.login(config.fluxer.token);
|
||||
|
||||
logger.info("fluxer client logged in successfully.");
|
||||
|
||||
export default client;
|
||||
3
adapters/fluxer/src/lib/common-logger.ts
Normal file
3
adapters/fluxer/src/lib/common-logger.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { createLogger } from "@avocadi/bot-core/lib/logger";
|
||||
|
||||
export const logger = createLogger("FluxerAdapter");
|
||||
Reference in New Issue
Block a user