mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-18 00:33:59 +00:00
feat: initialize helper client
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
import { Client, Events, GatewayIntentBits } from 'discord.js';
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
|
import HelperClient from '../../client/index.js';
|
||||||
|
|
||||||
const configJSON = readFileSync('../config.json', 'utf-8');
|
const configJSON = readFileSync('../config.json', 'utf-8');
|
||||||
const config = JSON.parse(configJSON);
|
const config = JSON.parse(configJSON);
|
||||||
|
|
||||||
|
const helper = new HelperClient(config.server);
|
||||||
|
|
||||||
|
helper.connect();
|
||||||
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
||||||
|
|
||||||
client.on(Events.MessageCreate, async (msg) => {
|
client.on(Events.MessageCreate, async (msg) => {
|
||||||
@@ -14,4 +19,14 @@ client.on(Events.InteractionCreate, async (interaction) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The ReVanced Helper events.
|
||||||
|
|
||||||
|
helper.on('aiResponse', async (aiRes) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
helper.on('ocrResponse', async (aiRes) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
client.login(config.discord.token);
|
client.login(config.discord.token);
|
||||||
78
client/index.js
Normal file
78
client/index.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { createConnection } from 'node:net';
|
||||||
|
import { serialize, deserialize } from 'bson';
|
||||||
|
import EventEmitter from 'node:events';
|
||||||
|
|
||||||
|
class HelperClient extends EventEmitter {
|
||||||
|
constructor({ server }) {
|
||||||
|
super();
|
||||||
|
if (!server.port) throw new Error('You did not specify the server port.');
|
||||||
|
this.server = server;
|
||||||
|
};
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
this.client = createConnection(this.server.port, this.server.host ? this.server.host : 'localhost', () => {
|
||||||
|
this.emit('connect');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.client.on('data', (data) => {
|
||||||
|
const eventData = deserialize(data);
|
||||||
|
|
||||||
|
switch (eventData.op) {
|
||||||
|
case 2: {
|
||||||
|
// The 'aiResponse' event.
|
||||||
|
|
||||||
|
this.emit('aiResponse', eventData);
|
||||||
|
};
|
||||||
|
|
||||||
|
case 6: {
|
||||||
|
// The 'ocrResponse' event.
|
||||||
|
|
||||||
|
this.emit('ocrResponse', eventData);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
sendData(data) {
|
||||||
|
this.client.write(serialize(data));
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
scanText(text, id) {
|
||||||
|
this.sendData({
|
||||||
|
op: 1,
|
||||||
|
id,
|
||||||
|
text
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
scanImage(url, id) {
|
||||||
|
this.sendData({
|
||||||
|
op: 5,
|
||||||
|
id,
|
||||||
|
url
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
sendTrainData(text, label) {
|
||||||
|
this.sendData({
|
||||||
|
op: 5,
|
||||||
|
label,
|
||||||
|
text
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
trainAI() {
|
||||||
|
this.sendData({ op: 4 });
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default HelperClient;
|
||||||
117
client/package-lock.json
generated
Normal file
117
client/package-lock.json
generated
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
{
|
||||||
|
"name": "helper-client",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 2,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "helper-client",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
|
"dependencies": {
|
||||||
|
"bson": "^4.7.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/base64-js": {
|
||||||
|
"version": "1.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||||
|
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/bson": {
|
||||||
|
"version": "4.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/bson/-/bson-4.7.0.tgz",
|
||||||
|
"integrity": "sha512-VrlEE4vuiO1WTpfof4VmaVolCVYkYTgB9iWgYNOrVlnifpME/06fhFRmONgBhClD5pFC1t9ZWqFUQEQAzY43bA==",
|
||||||
|
"dependencies": {
|
||||||
|
"buffer": "^5.6.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/buffer": {
|
||||||
|
"version": "5.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"base64-js": "^1.3.1",
|
||||||
|
"ieee754": "^1.1.13"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ieee754": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"base64-js": {
|
||||||
|
"version": "1.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||||
|
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
|
||||||
|
},
|
||||||
|
"bson": {
|
||||||
|
"version": "4.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/bson/-/bson-4.7.0.tgz",
|
||||||
|
"integrity": "sha512-VrlEE4vuiO1WTpfof4VmaVolCVYkYTgB9iWgYNOrVlnifpME/06fhFRmONgBhClD5pFC1t9ZWqFUQEQAzY43bA==",
|
||||||
|
"requires": {
|
||||||
|
"buffer": "^5.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"buffer": {
|
||||||
|
"version": "5.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
|
"requires": {
|
||||||
|
"base64-js": "^1.3.1",
|
||||||
|
"ieee754": "^1.1.13"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ieee754": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
client/package.json
Normal file
15
client/package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "helper-client",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "The ReVanced Helper client.",
|
||||||
|
"main": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "Reis Can",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
|
"dependencies": {
|
||||||
|
"bson": "^4.7.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user