mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-23 11:11:04 +00:00
feat!: big feature changes
BREAKING CHANGES: - Heartbeating removed - `config.consoleLogLevel` -> `config.logLevel` NEW FEATURES: - Training messages - Sequence number system - WebSocket close codes used instead of disconnect packets FIXES: - Improved error handling - Some performance improvements - Made code more clean - Updated dependencies
This commit is contained in:
@@ -1,35 +1,41 @@
|
||||
import { ClientOperation, ServerOperation } from '@revanced/bot-shared'
|
||||
import { type ClientOperation, ServerOperation } from '@revanced/bot-shared'
|
||||
|
||||
import { inspect as inspectObject } from 'util'
|
||||
|
||||
import type { EventHandler } from './index'
|
||||
import type { EventHandler } from '.'
|
||||
|
||||
const parseTextEventHandler: EventHandler<ClientOperation.ParseText> = async (packet, { witClient, logger }) => {
|
||||
const parseTextEventHandler: EventHandler<ClientOperation.ParseText> = async (packet, { wit, logger }) => {
|
||||
const {
|
||||
client,
|
||||
d: { text, id },
|
||||
d: { text },
|
||||
} = packet
|
||||
|
||||
logger.debug(`Client ${client.id} requested to parse text:`, text)
|
||||
const nextSeq = client.currentSequence++
|
||||
const actualText = text.slice(0, 279)
|
||||
|
||||
logger.debug(`Client ${client.id} requested to parse text:`, actualText)
|
||||
|
||||
try {
|
||||
const { intents } = await witClient.message(text, {})
|
||||
const { intents } = await wit.message(actualText)
|
||||
const intentsWithoutIds = intents.map(({ id, ...rest }) => rest)
|
||||
|
||||
await client.send({
|
||||
op: ServerOperation.ParsedText,
|
||||
d: {
|
||||
id,
|
||||
labels: intentsWithoutIds,
|
||||
await client.send(
|
||||
{
|
||||
op: ServerOperation.ParsedText,
|
||||
d: {
|
||||
labels: intentsWithoutIds,
|
||||
},
|
||||
},
|
||||
})
|
||||
nextSeq,
|
||||
)
|
||||
} catch (e) {
|
||||
await client.send({
|
||||
op: ServerOperation.ParseTextFailed,
|
||||
d: {
|
||||
id,
|
||||
await client.send(
|
||||
{
|
||||
op: ServerOperation.ParseTextFailed,
|
||||
d: null,
|
||||
},
|
||||
})
|
||||
nextSeq,
|
||||
)
|
||||
|
||||
if (e instanceof Error) logger.error(e.stack ?? e.message)
|
||||
else logger.error(inspectObject(e))
|
||||
|
||||
Reference in New Issue
Block a user