mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-23 19:21:04 +00:00
Add OCR, add configuration
This commit is contained in:
@@ -1,31 +1,50 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
// Fix __dirname not being defined in ES modules. (https://stackoverflow.com/a/64383997)
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname, join } from 'node:path';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
global.__dirname = dirname(__filename);
|
||||
|
||||
const configJSON = readFileSync('./config.json', 'utf-8');
|
||||
const config = JSON.parse(configJSON);
|
||||
global.config = config;
|
||||
console.log(config);
|
||||
import { createServer } from 'node:net';
|
||||
import { deserialize } from 'bson';
|
||||
import FastText from 'fasttext.js';
|
||||
import { runAI, trainAI } from './events/index.js';
|
||||
import { runAI, trainAI, runOCR } from './events/index.js';
|
||||
|
||||
const ft = new FastText({
|
||||
loadModel: './model/model.bin'
|
||||
});
|
||||
const ft = new FastText(global.config.fasttext);
|
||||
|
||||
ft.load();
|
||||
|
||||
// I'm sorry. This is probably the only solution.
|
||||
global.ft = ft;
|
||||
|
||||
const server = createServer(async (client) => {
|
||||
client.on('data', async (data) => {
|
||||
const eventData = deserialize(data);
|
||||
|
||||
switch(eventData.event) {
|
||||
case 'ai': {
|
||||
runAI(client, eventData, ft.predict);
|
||||
switch(eventData.op) {
|
||||
case 1: {
|
||||
runAI(client, eventData);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
case 'train_ai': {
|
||||
trainAI(ft.unload, ft.load);
|
||||
case 4: {
|
||||
trainAI();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
case 5: {
|
||||
runOCR(client, eventData);
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(process.env.PORT || 3000);
|
||||
server.listen(global.config.server.port || 3000);
|
||||
Reference in New Issue
Block a user