mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-30 22:51:01 +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:
43
apis/websocket/src/events/trainMessage.ts
Normal file
43
apis/websocket/src/events/trainMessage.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { type ClientOperation, ServerOperation } from '@revanced/bot-shared'
|
||||
|
||||
import { inspect as inspectObject } from 'util'
|
||||
|
||||
import type { EventHandler } from '.'
|
||||
|
||||
const trainMessageEventHandler: EventHandler<ClientOperation.TrainMessage> = async (packet, { wit, logger }) => {
|
||||
const {
|
||||
client,
|
||||
d: { text, label },
|
||||
} = packet
|
||||
|
||||
const nextSeq = client.currentSequence++
|
||||
const actualText = text.slice(0, 279)
|
||||
|
||||
logger.debug(`Client ${client.id} requested to train label ${label} with:`, actualText)
|
||||
|
||||
try {
|
||||
await wit.train(actualText, label)
|
||||
await client.send(
|
||||
{
|
||||
op: ServerOperation.TrainedMessage,
|
||||
d: null,
|
||||
},
|
||||
nextSeq,
|
||||
)
|
||||
|
||||
logger.debug(`Trained label ${label} with:`, actualText)
|
||||
} catch (e) {
|
||||
await client.send(
|
||||
{
|
||||
op: ServerOperation.TrainMessageFailed,
|
||||
d: null,
|
||||
},
|
||||
nextSeq,
|
||||
)
|
||||
|
||||
if (e instanceof Error) logger.error(e.stack ?? e.message)
|
||||
else logger.error(inspectObject(e))
|
||||
}
|
||||
}
|
||||
|
||||
export default trainMessageEventHandler
|
||||
Reference in New Issue
Block a user