mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-29 14:11:02 +00:00
Add Server
This commit is contained in:
31
server/index.js
Normal file
31
server/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { createServer } from 'node:net';
|
||||
import { deserialize } from 'bson';
|
||||
import FastText from 'fasttext.js';
|
||||
import { runAI, trainAI } from './events/index.js';
|
||||
|
||||
const ft = new FastText({
|
||||
loadModel: './model/model.bin'
|
||||
});
|
||||
|
||||
ft.load();
|
||||
|
||||
const server = createServer(async (client) => {
|
||||
client.on('data', async (data) => {
|
||||
const eventData = deserialize(data);
|
||||
|
||||
switch(eventData.event) {
|
||||
case 'ai': {
|
||||
runAI(client, eventData, ft.predict);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'train_ai': {
|
||||
trainAI(ft.unload, ft.load);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(process.env.PORT || 3000);
|
||||
Reference in New Issue
Block a user