begin implementing fluxer bot
This commit is contained in:
2
adapters/fluxer/.gitignore
vendored
2
adapters/fluxer/.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
{
|
||||
"name": "@avocadi/bot-adapter-fluxer",
|
||||
"module": "index.ts",
|
||||
"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"
|
||||
"@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"
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -8,6 +8,7 @@
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
|
||||
"baseUrl": "src",
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
|
||||
9
adapters/fluxer/tsdown.config.ts
Normal file
9
adapters/fluxer/tsdown.config.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { defineConfig } from "tsdown";
|
||||
|
||||
export default defineConfig({
|
||||
entry: ["./src/index.ts"],
|
||||
format: "esm",
|
||||
dts: true,
|
||||
exports: true,
|
||||
fixedExtension: false,
|
||||
});
|
||||
28
bun.lock
28
bun.lock
@@ -1,8 +1,12 @@
|
||||
{
|
||||
"lockfileVersion": 1,
|
||||
"configVersion": 0,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"name": "avocadi-bot",
|
||||
"dependencies": {
|
||||
"@fluxerjs/core": "^1.1.7",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.4.2",
|
||||
},
|
||||
@@ -28,8 +32,18 @@
|
||||
},
|
||||
"adapters/fluxer": {
|
||||
"name": "@avocadi/bot-adapter-fluxer",
|
||||
"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:",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
"tsdown": "catalog:",
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5",
|
||||
@@ -170,6 +184,20 @@
|
||||
|
||||
"@esbuild/win32-x64": ["@esbuild/win32-x64@0.19.12", "", { "os": "win32", "cpu": "x64" }, "sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA=="],
|
||||
|
||||
"@fluxerjs/builders": ["@fluxerjs/builders@1.1.7", "", { "dependencies": { "@fluxerjs/types": "1.1.7", "@fluxerjs/util": "1.1.7" } }, "sha512-EoFfLwW8zFDSKGNuhN7TegMfZC7/3nOa8TIuWW84xK8oPmOkE3WQg4CZhjROIV31zsIimyYwIpCzDKpCfIvjGw=="],
|
||||
|
||||
"@fluxerjs/collection": ["@fluxerjs/collection@1.1.7", "", {}, "sha512-EC0Ndxql3nkTOoe0n7bS7Iil3DgCOc1O56j+f7l2bXPdaqq24oNlYWLxfVw2zQ/qJ9FTvBblyu9nT/KvThD0lQ=="],
|
||||
|
||||
"@fluxerjs/core": ["@fluxerjs/core@1.1.7", "", { "dependencies": { "@fluxerjs/builders": "1.1.7", "@fluxerjs/collection": "1.1.7", "@fluxerjs/rest": "1.1.7", "@fluxerjs/types": "1.1.7", "@fluxerjs/util": "1.1.7", "@fluxerjs/ws": "1.1.7" } }, "sha512-hFVY95F7+b081YHA9R2ecWOy5yz7i/pJVMp/7Oiz2PinVZAwGNKN7adLS6SQYiqO6cISXdXg01EK5cm7r+NJvg=="],
|
||||
|
||||
"@fluxerjs/rest": ["@fluxerjs/rest@1.1.7", "", { "dependencies": { "@fluxerjs/types": "1.1.7" } }, "sha512-UsmUjZWQUuZb+zLRimL2cg/Kborff1Ol/J+mxT6wfWqAVTcslVuyl2y/gHPDDLeKiNhpe09lh9eL58tE5bTDuw=="],
|
||||
|
||||
"@fluxerjs/types": ["@fluxerjs/types@1.1.7", "", {}, "sha512-uEn6ZBbv/SGRLgSHnymZ1DRU5+gG1UncwecxZBJ7B/ZbuhBSRnafIncHSwYs0ZXhlMZtCCpmOGElYPdr9Yc3HQ=="],
|
||||
|
||||
"@fluxerjs/util": ["@fluxerjs/util@1.1.7", "", { "dependencies": { "@fluxerjs/types": "1.1.7" } }, "sha512-Tn4PHetSvI4nYNU/x1/f15BqXmBQbguHq3ESuF+YXUoIo6T3axhGO2Ka+9jngSKHUCqv9/cs00AS6LBCOQfHhw=="],
|
||||
|
||||
"@fluxerjs/ws": ["@fluxerjs/ws@1.1.7", "", { "dependencies": { "@fluxerjs/types": "1.1.7", "ws": "^8.18.0" } }, "sha512-2WGlglxaPZmHQ0FW3OQpHL/ghMV7OI9vm+2FZ7ER0qqR+x3nrxbp7+2EXMtQMz2UpPH2+53/Hexa3+7Ze8dx4A=="],
|
||||
|
||||
"@jridgewell/gen-mapping": ["@jridgewell/gen-mapping@0.3.13", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA=="],
|
||||
|
||||
"@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.2", "", {}, "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw=="],
|
||||
|
||||
@@ -13,5 +13,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.4.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluxerjs/core": "^1.1.7"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user