mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
feat(server): regex support for server-side
This commit is contained in:
@@ -23,10 +23,10 @@ And the server would return something like this:
|
||||
"response": [
|
||||
{
|
||||
"confidence": 0.99,
|
||||
"id": "String",
|
||||
"name": "revanced_download"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Training the AI
|
||||
|
||||
9
apps/server/src/config.example.json
Normal file
9
apps/server/src/config.example.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"regexSupport": false,
|
||||
"regexResponses": [
|
||||
{
|
||||
"label": "videobuffer",
|
||||
"regex": "insert regex here"
|
||||
}
|
||||
]
|
||||
}
|
||||
9
apps/server/src/config.json
Normal file
9
apps/server/src/config.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"regexSupport": false,
|
||||
"regexResponses": [
|
||||
{
|
||||
"label": "videobuffer",
|
||||
"regex": "insert regex here"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user