mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-19 01:03:58 +00:00
feat: run bots in one process
This commit is contained in:
@@ -3,11 +3,11 @@ import { readFileSync, readdirSync } from 'node:fs';
|
|||||||
// Fix __dirname not being defined in ES modules. (https://stackoverflow.com/a/64383997)
|
// Fix __dirname not being defined in ES modules. (https://stackoverflow.com/a/64383997)
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { dirname, join } from 'node:path';
|
import { dirname, join } from 'node:path';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
import HelperClient from '../../client/index.js';
|
import HelperClient from '../../client/index.js';
|
||||||
|
|
||||||
|
export default async () => {
|
||||||
const config = JSON.parse(readFileSync('../config.json', 'utf-8'));
|
const config = JSON.parse(readFileSync('../config.json', 'utf-8'));
|
||||||
|
|
||||||
const helper = new HelperClient(config);
|
const helper = new HelperClient(config);
|
||||||
@@ -78,3 +78,5 @@ for (const file of helperEventFiles) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.login(config.discord.token);
|
client.login(config.discord.token);
|
||||||
|
|
||||||
|
}
|
||||||
10
bots/index.js
Normal file
10
bots/index.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { readdirSync } from 'node:fs';
|
||||||
|
|
||||||
|
const botFolders = readdirSync('./', { withFileTypes: true })
|
||||||
|
.filter(dirent => dirent.isDirectory())
|
||||||
|
.map(dirent => dirent.name);
|
||||||
|
|
||||||
|
for (const botFolder of botFolders) {
|
||||||
|
const botIndex = await import(`./${botFolder}/index.js`);
|
||||||
|
botIndex.default();
|
||||||
|
}
|
||||||
9
bots/package.json
Normal file
9
bots/package.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "bots",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"author": "Reis Can",
|
||||||
|
"license": "GPL-3.0-or-later"
|
||||||
|
}
|
||||||
@@ -9,7 +9,8 @@ import HelperClient from '../../client/index.js';
|
|||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
const config = JSON.parse(readFileSync('../config.json', 'utf-8'));
|
export default async () => {
|
||||||
|
const config = JSON.parse(readFileSync('./config.json', 'utf-8'));
|
||||||
|
|
||||||
const client = new Snoowrap(config.reddit);
|
const client = new Snoowrap(config.reddit);
|
||||||
const helper = new HelperClient(config);
|
const helper = new HelperClient(config);
|
||||||
@@ -99,3 +100,4 @@ for (const file of helperEventFiles) {
|
|||||||
helper.on(event.name, (...args) => event.execute(client, config, ...args));
|
helper.on(event.name, (...args) => event.execute(client, config, ...args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,8 @@ const __filename = fileURLToPath(import.meta.url);
|
|||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
import HelperClient from '../../client/index.js';
|
import HelperClient from '../../client/index.js';
|
||||||
|
|
||||||
const config = JSON.parse(readFileSync('../config.json', 'utf-8'));
|
export default async () => {
|
||||||
|
const config = JSON.parse(readFileSync('./config.json', 'utf-8'));
|
||||||
|
|
||||||
const helper = new HelperClient(config);
|
const helper = new HelperClient(config);
|
||||||
helper.connect();
|
helper.connect();
|
||||||
@@ -65,3 +66,4 @@ for (const file of helperEventFiles) {
|
|||||||
helper.on(event.name, (...args) => event.execute(bot, config, ...args));
|
helper.on(event.name, (...args) => event.execute(bot, config, ...args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user