begin implementing fluxer bot

This commit is contained in:
2026-02-18 16:41:50 +01:00
parent 6053692bc1
commit 7678c1a722
13 changed files with 175 additions and 37 deletions

View File

@@ -21,6 +21,8 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
.env.test.local
.env.production.local
.env.local
.env.dev
.env.prod
# caches
.eslintcache

View File

@@ -1,12 +1,30 @@
{
"name": "@avocadi/bot-adapter-fluxer",
"module": "index.ts",
"type": "module",
"private": true,
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5"
}
"name": "@avocadi/bot-adapter-fluxer",
"type": "module",
"private": true,
"scripts": {
"build": "tsdown",
"dev:prod": "NODE_ENV=production tsdown --watch & node --watch ./dist/index.js",
"dev": "NODE_ENV=development tsdown --watch & node --watch ./dist/index.js"
},
"devDependencies": {
"@types/bun": "latest",
"tsdown": "catalog:"
},
"peerDependencies": {
"typescript": "^5"
},
"dependencies": {
"@avocadi/bot-core": "workspace:*",
"@discordjs/rest": "^2.6.0",
"@fluxerjs/core": "^1.1.7",
"cron": "^4.4.0",
"dotenv": "^17.3.1",
"dotenv-expand": "^12.0.3",
"zod": "catalog:"
},
"exports": {
".": "./dist/index.js",
"./package.json": "./package.json"
}
}

View 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
View 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;

View File

@@ -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,
},
};

View File

@@ -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();

View File

@@ -0,0 +1 @@
import "lib/client";

View 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;

View File

@@ -0,0 +1,3 @@
import { createLogger } from "@avocadi/bot-core/lib/logger";
export const logger = createLogger("FluxerAdapter");

View File

@@ -1,29 +1,30 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
"baseUrl": "src",
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}

View File

@@ -0,0 +1,9 @@
import { defineConfig } from "tsdown";
export default defineConfig({
entry: ["./src/index.ts"],
format: "esm",
dts: true,
exports: true,
fixedExtension: false,
});