feat(server): regex support for server-side

This commit is contained in:
GramingFoxTeam
2023-07-14 19:59:03 +03:00
parent d505991330
commit 5228ac36e7
5 changed files with 42 additions and 4 deletions

View File

@@ -23,10 +23,10 @@ And the server would return something like this:
"response": [
{
"confidence": 0.99,
"id": "String",
"name": "revanced_download"
}
]
}
```
### Training the AI

View File

@@ -0,0 +1,9 @@
{
"regexSupport": false,
"regexResponses": [
{
"label": "videobuffer",
"regex": "insert regex here"
}
]
}

View File

@@ -0,0 +1,9 @@
{
"regexSupport": false,
"regexResponses": [
{
"label": "videobuffer",
"regex": "insert regex here"
}
]
}

View File

@@ -1,7 +1,26 @@
import { serialize } from 'bson';
export default async function runAI(client, data) {
const witAIReq = await fetch(
export default async function runAI(client, data, config) {
if (config.regexSupport) {
for (const reply of config.regexResponses) {
if (new RegExp(reply.regex).test(data.text)) {
client.write(
serialize({
op: 2,
id: data.id,
response: [
{
confidence: 1,
name: reply.label
}
]
})
);
return;
}
}
}
const witAIReq = await fetch(
`https://api.wit.ai/message?v=20230215&q=${encodeURI(data.text)}`,
{
headers: {

View File

@@ -1,6 +1,7 @@
import { createServer } from 'node:net';
import { deserialize } from 'bson';
import { runAI, runOCR, trainAI } from './events/index.js';
import Config from './config.json' assert { type: 'json' };
const server = createServer(async (client) => {
client.on('data', async (data) => {
@@ -10,7 +11,7 @@ const server = createServer(async (client) => {
switch (eventData.op) {
case 1: {
runAI(client, eventData);
runAI(client, eventData, Config);
break;
}