mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
chore: format and remove unneccessary code
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": ["prettier"],
|
||||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"sourceType": "module",
|
||||
"ecmaVersion": "latest"
|
||||
|
||||
@@ -39,4 +39,3 @@ bun bundle
|
||||
```
|
||||
|
||||
The files will be placed in the `dist` directory. **Configurations and `.env` files will NOT be copied automatically.**
|
||||
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
{
|
||||
"name": "@revanced/bot-websocket-api",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"description": "🧦 WebSocket API server for bots assisting ReVanced",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"bundle": "bun build src/index.ts --outdir=dist --target=node --minify --sourcemap=external",
|
||||
"dev": "bun run src/index.ts --watch",
|
||||
"build": "bun bundle",
|
||||
"watch": "bun dev"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/revanced/revanced-helper.git",
|
||||
"directory": "apis/websocket"
|
||||
},
|
||||
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"contributors": [
|
||||
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/revanced/revanced-helper/issues"
|
||||
},
|
||||
"homepage": "https://github.com/revanced/revanced-helper#readme",
|
||||
"dependencies": {
|
||||
"@fastify/websocket": "^8.2.0",
|
||||
"@revanced/bot-shared": "workspace:*",
|
||||
"@sapphire/async-queue": "^1.5.0",
|
||||
"chalk": "^5.3.0",
|
||||
"fastify": "^4.24.3",
|
||||
"node-wit": "^6.6.0",
|
||||
"tesseract.js": "^5.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node-wit": "^6.0.3",
|
||||
"@types/ws": "^8.5.10",
|
||||
"typed-emitter": "^2.1.0"
|
||||
}
|
||||
"name": "@revanced/bot-websocket-api",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"description": "🧦 WebSocket API server for bots assisting ReVanced",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"bundle": "bun build src/index.ts --outdir=dist --target=node --minify --sourcemap=external",
|
||||
"dev": "bun run src/index.ts --watch",
|
||||
"build": "bun bundle",
|
||||
"watch": "bun dev"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/revanced/revanced-helper.git",
|
||||
"directory": "apis/websocket"
|
||||
},
|
||||
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"contributors": [
|
||||
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/revanced/revanced-helper/issues"
|
||||
},
|
||||
"homepage": "https://github.com/revanced/revanced-helper#readme",
|
||||
"dependencies": {
|
||||
"@fastify/websocket": "^8.2.0",
|
||||
"@revanced/bot-shared": "workspace:*",
|
||||
"@sapphire/async-queue": "^1.5.0",
|
||||
"chalk": "^5.3.0",
|
||||
"fastify": "^4.24.3",
|
||||
"node-wit": "^6.6.0",
|
||||
"tesseract.js": "^5.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node-wit": "^6.0.3",
|
||||
"@types/ws": "^8.5.10",
|
||||
"typed-emitter": "^2.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ export default class Client {
|
||||
this.#emitter.emit('packet', packet)
|
||||
this.#emitter.emit(
|
||||
uncapitalize(ClientOperation[packet.op] as ClientEventName),
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error TypeScript doesn't know that the above line will negate the type enough
|
||||
packet
|
||||
)
|
||||
} catch (e) {
|
||||
@@ -181,7 +181,7 @@ export default class Client {
|
||||
this.once('heartbeat', () => clearTimeout(interval))
|
||||
// This should never happen but it did in my testing so I'm adding this just in case
|
||||
this.once('disconnect', () => clearTimeout(interval))
|
||||
// Technically we don't have to do this, but JUST IN CASE!
|
||||
// Technically we don't have to do this, but JUST IN CASE!
|
||||
} else this.#hbTimeout.refresh()
|
||||
}, this.heartbeatInterval)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ import type { Worker as TesseractWorker } from 'tesseract.js'
|
||||
export { default as parseTextEventHandler } from './parseText.js'
|
||||
export { default as parseImageEventHandler } from './parseImage.js'
|
||||
|
||||
export type EventHandler<POp extends ClientOperation> = (packet: ClientPacketObject<POp>, context: EventContext) => void | Promise<void>
|
||||
export type EventHandler<POp extends ClientOperation> = (
|
||||
packet: ClientPacketObject<POp>,
|
||||
context: EventContext
|
||||
) => void | Promise<void>
|
||||
export type EventContext = {
|
||||
witClient: Wit
|
||||
tesseractWorker: TesseractWorker
|
||||
|
||||
@@ -17,16 +17,17 @@ import {
|
||||
|
||||
import { getConfig, checkEnv, logger } from './utils/index.js'
|
||||
import { WebSocket } from 'ws'
|
||||
import { DisconnectReason, HumanizedDisconnectReason } from '@revanced/bot-shared'
|
||||
|
||||
// Load environment variables and config
|
||||
|
||||
(async () => {
|
||||
import {
|
||||
DisconnectReason,
|
||||
HumanizedDisconnectReason,
|
||||
} from '@revanced/bot-shared'
|
||||
|
||||
// Check environment variables and load config
|
||||
const environment = checkEnv(logger)
|
||||
const config = getConfig()
|
||||
|
||||
if (!config.debugLogsInProduction && environment === 'production') logger.debug = () => {}
|
||||
if (!config.debugLogsInProduction && environment === 'production')
|
||||
logger.debug = () => {}
|
||||
|
||||
// Workers and API clients
|
||||
|
||||
@@ -90,9 +91,14 @@ const server = fastify()
|
||||
parseImageEventHandler(packet, eventContext)
|
||||
)
|
||||
|
||||
if (environment === 'development' && !config.debugLogsInProduction) {
|
||||
logger.debug('Running development mode or debug logs in production is enabled, attaching debug events...')
|
||||
client.on('packet', ({ client: _, ...rawPacket }) =>
|
||||
if (
|
||||
environment === 'development' &&
|
||||
!config.debugLogsInProduction
|
||||
) {
|
||||
logger.debug(
|
||||
'Running development mode or debug logs in production is enabled, attaching debug events...'
|
||||
)
|
||||
client.on('packet', ({ client, ...rawPacket }) =>
|
||||
logger.debug(
|
||||
`Packet received from client ${client.id}:`,
|
||||
inspectObject(rawPacket)
|
||||
@@ -100,7 +106,10 @@ const server = fastify()
|
||||
)
|
||||
|
||||
client.on('heartbeat', () =>
|
||||
logger.debug('Heartbeat received from client', client.id)
|
||||
logger.debug(
|
||||
'Heartbeat received from client',
|
||||
client.id
|
||||
)
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -146,5 +155,3 @@ else
|
||||
'Server started at:',
|
||||
`${addressInfo.address}:${addressInfo.port}`
|
||||
)
|
||||
|
||||
})()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import type { Logger } from './logger.js'
|
||||
|
||||
export default function checkEnv(logger: Logger) {
|
||||
if (!process.env['NODE_ENV']) logger.warn('NODE_ENV not set, defaulting to `development`')
|
||||
if (!process.env['NODE_ENV'])
|
||||
logger.warn('NODE_ENV not set, defaulting to `development`')
|
||||
const environment = (process.env['NODE_ENV'] ??
|
||||
'development') as NodeEnvironment
|
||||
'development') as NodeEnvironment
|
||||
|
||||
if (!['development', 'production'].includes(environment)) {
|
||||
logger.error(
|
||||
@@ -16,7 +17,9 @@ export default function checkEnv(logger: Logger) {
|
||||
logger.info(`Running in ${environment} mode...`)
|
||||
|
||||
if (environment === 'production' && process.env['IS_USING_DOT_ENV']) {
|
||||
logger.warn('You seem to be using .env files, this is generally not a good idea in production...')
|
||||
logger.warn(
|
||||
'You seem to be using .env files, this is generally not a good idea in production...'
|
||||
)
|
||||
}
|
||||
|
||||
if (!process.env['WIT_AI_TOKEN']) {
|
||||
|
||||
@@ -2,28 +2,31 @@ import { existsSync } from 'node:fs'
|
||||
import { resolve as resolvePath } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
|
||||
const configPath = resolvePath(
|
||||
process.cwd(),
|
||||
'config.json'
|
||||
)
|
||||
const configPath = resolvePath(process.cwd(), 'config.json')
|
||||
|
||||
const userConfig: Partial<Config> = existsSync(configPath)
|
||||
? (await import(pathToFileURL(configPath).href, {
|
||||
assert: {
|
||||
type: 'json',
|
||||
},
|
||||
})).default
|
||||
? (
|
||||
await import(pathToFileURL(configPath).href, {
|
||||
assert: {
|
||||
type: 'json',
|
||||
},
|
||||
})
|
||||
).default
|
||||
: {}
|
||||
|
||||
type BaseTypeOf<T> = T extends (infer U)[]
|
||||
? U[]
|
||||
: T extends (...args: any[]) => infer U
|
||||
? (...args: any[]) => U
|
||||
: T extends object
|
||||
? { [K in keyof T]: T[K] }
|
||||
: T
|
||||
: T extends (...args: unknown[]) => infer U
|
||||
? (...args: unknown[]) => U
|
||||
: T extends object
|
||||
? { [K in keyof T]: T[K] }
|
||||
: T
|
||||
|
||||
export type Config = Omit<
|
||||
BaseTypeOf<typeof import('../../config.json')>,
|
||||
'$schema'
|
||||
>
|
||||
|
||||
export type Config = Omit<BaseTypeOf<typeof import('../../config.json')>, '$schema'> & {}
|
||||
export const defaultConfig: Config = {
|
||||
address: '127.0.0.1',
|
||||
port: 80,
|
||||
|
||||
@@ -3,14 +3,23 @@ import { Chalk } from 'chalk'
|
||||
const chalk = new Chalk()
|
||||
const logger = {
|
||||
debug: (...args) => console.debug(chalk.gray('DEBUG:', ...args)),
|
||||
info: (...args) => console.info(chalk.bgBlue.whiteBright(' INFO '), ...args),
|
||||
warn: (...args) => console.warn(chalk.bgYellow.blackBright.bold(' WARN '), chalk.yellowBright(...args)),
|
||||
error: (...args) => console.error(chalk.bgRed.whiteBright.bold(' ERROR '), chalk.redBright(...args)),
|
||||
info: (...args) =>
|
||||
console.info(chalk.bgBlue.whiteBright(' INFO '), ...args),
|
||||
warn: (...args) =>
|
||||
console.warn(
|
||||
chalk.bgYellow.blackBright.bold(' WARN '),
|
||||
chalk.yellowBright(...args)
|
||||
),
|
||||
error: (...args) =>
|
||||
console.error(
|
||||
chalk.bgRed.whiteBright.bold(' ERROR '),
|
||||
chalk.redBright(...args)
|
||||
),
|
||||
log: console.log,
|
||||
} satisfies Logger
|
||||
|
||||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'log'
|
||||
export type LogFunction = (...x: any[]) => void
|
||||
export type LogFunction = (...x: unknown[]) => void
|
||||
export type Logger = Record<LogLevel, LogFunction>
|
||||
|
||||
export default logger
|
||||
@@ -4,7 +4,7 @@
|
||||
"baseUrl": ".",
|
||||
"outDir": "dist",
|
||||
"module": "ESNext",
|
||||
"composite": false,
|
||||
"composite": false
|
||||
},
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"include": ["./*.json", "src/**/*.ts"]
|
||||
|
||||
110
package.json
110
package.json
@@ -1,57 +1,57 @@
|
||||
{
|
||||
"name": "revanced-helper",
|
||||
"version": "0.0.0",
|
||||
"description": "🤖 Bots assisting ReVanced on multiple platforms",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"apis/*",
|
||||
"bots/*",
|
||||
"packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "bun task build",
|
||||
"commitlint": "commitlint --edit",
|
||||
"format": "turbo run format",
|
||||
"format:check": "turbo run format:check",
|
||||
"lint": "turbo run lint",
|
||||
"lint:apply": "turbo run lint:apply",
|
||||
"watch": "bun task watch",
|
||||
"task": "turbo run",
|
||||
"t": "bun task",
|
||||
"prepare": "lefthook install"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/revanced/revanced-helper.git"
|
||||
},
|
||||
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"contributors": [
|
||||
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/revanced/revanced-helper/issues"
|
||||
},
|
||||
"homepage": "https://github.com/revanced/revanced-helper#readme",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^18.4.3",
|
||||
"@commitlint/config-conventional": "^18.4.3",
|
||||
"@tsconfig/strictest": "^2.0.2",
|
||||
"conventional-changelog-conventionalcommits": "^7.0.2",
|
||||
"eslint": "^8.54.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
"eslint-plugin-prettier": "^5.0.1",
|
||||
"lefthook": "^1.5.3",
|
||||
"prettier": "^3.1.0",
|
||||
"semantic-release": "^22.0.8",
|
||||
"turbo": "^1.10.16",
|
||||
"typescript": "^5.3.2"
|
||||
},
|
||||
"overrides": {
|
||||
"uuid": ">=9.0.0",
|
||||
"isomorphic-fetch": ">=3.0.0"
|
||||
}
|
||||
"name": "revanced-helper",
|
||||
"version": "0.0.0",
|
||||
"description": "🤖 Bots assisting ReVanced on multiple platforms",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"apis/*",
|
||||
"bots/*",
|
||||
"packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "bun task build",
|
||||
"commitlint": "commitlint --edit",
|
||||
"format": "turbo run format",
|
||||
"format:check": "turbo run format:check",
|
||||
"lint": "turbo run lint",
|
||||
"lint:apply": "turbo run lint:apply",
|
||||
"watch": "bun task watch",
|
||||
"task": "turbo run",
|
||||
"t": "bun task",
|
||||
"prepare": "lefthook install"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/revanced/revanced-helper.git"
|
||||
},
|
||||
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"contributors": [
|
||||
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/revanced/revanced-helper/issues"
|
||||
},
|
||||
"homepage": "https://github.com/revanced/revanced-helper#readme",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^18.4.3",
|
||||
"@commitlint/config-conventional": "^18.4.3",
|
||||
"@tsconfig/strictest": "^2.0.2",
|
||||
"conventional-changelog-conventionalcommits": "^7.0.2",
|
||||
"eslint": "^8.54.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
"eslint-plugin-prettier": "^5.0.1",
|
||||
"lefthook": "^1.5.3",
|
||||
"prettier": "^3.1.0",
|
||||
"semantic-release": "^22.0.8",
|
||||
"turbo": "^1.10.16",
|
||||
"typescript": "^5.3.2"
|
||||
},
|
||||
"overrides": {
|
||||
"uuid": ">=9.0.0",
|
||||
"isomorphic-fetch": ">=3.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
{
|
||||
"name": "@revanced/bot-api",
|
||||
"type": "module",
|
||||
"version": "0.1.0",
|
||||
"description": "🙌🏻 Programmatic API for bots assisting ReVanced to communicate to its API server",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "bun bundle && bun types",
|
||||
"watch": "conc --raw \"bun bundle:watch\" \"bun types:watch\"",
|
||||
"bundle": "bun build src/index.ts --outdir=dist --sourcemap=external --target=node --minify",
|
||||
"bundle:watch": "bun run bundle --watch",
|
||||
"types": "tsc --declaration --emitDeclarationOnly",
|
||||
"types:watch": "bun types --watch --preserveWatchOutput",
|
||||
"types:clean": "bun types --build --clean"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/revanced/revanced-helper.git",
|
||||
"directory": "packages/api"
|
||||
},
|
||||
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"contributors": [
|
||||
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/revanced/revanced-helper/issues"
|
||||
},
|
||||
"homepage": "https://github.com/revanced/revanced-helper#readme",
|
||||
"dependencies": {
|
||||
"@revanced/bot-shared": "workspace:*",
|
||||
"ws": "^8.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ws": "^8.5.10",
|
||||
"typed-emitter": "^2.1.0"
|
||||
}
|
||||
"name": "@revanced/bot-api",
|
||||
"type": "module",
|
||||
"version": "0.1.0",
|
||||
"description": "🙌🏻 Programmatic API for bots assisting ReVanced to communicate to its API server",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "bun bundle && bun types",
|
||||
"watch": "conc --raw \"bun bundle:watch\" \"bun types:watch\"",
|
||||
"bundle": "bun build src/index.ts --outdir=dist --sourcemap=external --target=node --minify",
|
||||
"bundle:watch": "bun run bundle --watch",
|
||||
"types": "tsc --declaration --emitDeclarationOnly",
|
||||
"types:watch": "bun types --watch --preserveWatchOutput",
|
||||
"types:clean": "bun types --build --clean"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/revanced/revanced-helper.git",
|
||||
"directory": "packages/api"
|
||||
},
|
||||
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"contributors": [
|
||||
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/revanced/revanced-helper/issues"
|
||||
},
|
||||
"homepage": "https://github.com/revanced/revanced-helper#readme",
|
||||
"dependencies": {
|
||||
"@revanced/bot-shared": "workspace:*",
|
||||
"ws": "^8.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ws": "^8.5.10",
|
||||
"typed-emitter": "^2.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,9 @@ export default class Client {
|
||||
rs(packet)
|
||||
}
|
||||
|
||||
const parseTextFailedListener = (packet: Packet<ServerOperation.ParseTextFailed>) => {
|
||||
const parseTextFailedListener = (
|
||||
packet: Packet<ServerOperation.ParseTextFailed>
|
||||
) => {
|
||||
if (packet.d.id !== currentId) return
|
||||
this.gateway.off('parseTextFailed', parseTextFailedListener)
|
||||
rj(packet)
|
||||
@@ -84,7 +86,9 @@ export default class Client {
|
||||
rs(packet)
|
||||
}
|
||||
|
||||
const parseImageFailedListener = (packet: Packet<ServerOperation.ParseImageFailed>) => {
|
||||
const parseImageFailedListener = (
|
||||
packet: Packet<ServerOperation.ParseImageFailed>
|
||||
) => {
|
||||
if (packet.d.id !== currentId) return
|
||||
this.gateway.off('parseImageFailed', parseImageFailedListener)
|
||||
rj(packet)
|
||||
|
||||
@@ -24,8 +24,7 @@ export default class ClientGateway {
|
||||
|
||||
#hbTimeout: NodeJS.Timeout = null!
|
||||
#socket: WebSocket = null!
|
||||
#emitter =
|
||||
new EventEmitter() as TypedEmitter<ClientGatewayEventHandlers>
|
||||
#emitter = new EventEmitter() as TypedEmitter<ClientGatewayEventHandlers>
|
||||
|
||||
constructor(options: ClientGatewayOptions) {
|
||||
this.url = options.url
|
||||
@@ -110,6 +109,7 @@ export default class ClientGateway {
|
||||
|
||||
switch (packet.op) {
|
||||
case ServerOperation.Hello:
|
||||
// eslint-disable-next-line no-case-declarations
|
||||
const data = Object.freeze(
|
||||
(packet as Packet<ServerOperation.Hello>).d
|
||||
)
|
||||
@@ -124,9 +124,11 @@ export default class ClientGateway {
|
||||
default:
|
||||
return this.#emitter.emit(
|
||||
uncapitalize(
|
||||
ServerOperation[packet.op] as ClientGatewayServerEventName
|
||||
ServerOperation[
|
||||
packet.op
|
||||
] as ClientGatewayServerEventName
|
||||
),
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error TypeScript doesn't know that the lines above negate the type enough
|
||||
packet
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"rootDir": "./src",
|
||||
"outDir": "dist",
|
||||
"module": "ESNext",
|
||||
"composite": true,
|
||||
"composite": true
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
2
packages/api/utility-types.d.ts
vendored
2
packages/api/utility-types.d.ts
vendored
@@ -1 +1 @@
|
||||
type RequiredProperty<T> = { [P in keyof T]: Required<NonNullable<T[P]>>; };
|
||||
type RequiredProperty<T> = { [P in keyof T]: Required<NonNullable<T[P]>> }
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
{
|
||||
"name": "@revanced/bot-shared",
|
||||
"type": "module",
|
||||
"version": "0.1.0",
|
||||
"description": "🙌🏻 Shared components for bots assisting ReVanced",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "bun bundle && bun types",
|
||||
"watch": "conc --raw \"bun bundle:watch\" \"bun types:watch\"",
|
||||
"bundle": "bun build src/index.ts --outdir=dist --sourcemap=external --target=node --minify",
|
||||
"bundle:watch": "bun run bundle --watch",
|
||||
"types": "tsc --declaration --emitDeclarationOnly",
|
||||
"types:watch": "bun types --watch --preserveWatchOutput",
|
||||
"types:clean": "bun types --build --clean"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/revanced/revanced-helper.git",
|
||||
"directory": "packages/shared"
|
||||
},
|
||||
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"contributors": [
|
||||
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/revanced/revanced-helper/issues"
|
||||
},
|
||||
"homepage": "https://github.com/revanced/revanced-helper#readme",
|
||||
"dependencies": {
|
||||
"bson": "^6.2.0",
|
||||
"valibot": "^0.21.0",
|
||||
"zod": "^3.22.4"
|
||||
}
|
||||
"name": "@revanced/bot-shared",
|
||||
"type": "module",
|
||||
"version": "0.1.0",
|
||||
"description": "🙌🏻 Shared components for bots assisting ReVanced",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "bun bundle && bun types",
|
||||
"watch": "conc --raw \"bun bundle:watch\" \"bun types:watch\"",
|
||||
"bundle": "bun build src/index.ts --outdir=dist --sourcemap=external --target=node --minify",
|
||||
"bundle:watch": "bun run bundle --watch",
|
||||
"types": "tsc --declaration --emitDeclarationOnly",
|
||||
"types:watch": "bun types --watch --preserveWatchOutput",
|
||||
"types:clean": "bun types --build --clean"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/revanced/revanced-helper.git",
|
||||
"directory": "packages/shared"
|
||||
},
|
||||
"author": "Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"contributors": [
|
||||
"Palm <palmpasuthorn@gmail.com> (https://github.com/PalmDevs)",
|
||||
"ReVanced <nosupport@revanced.app> (https://github.com/revanced)"
|
||||
],
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/revanced/revanced-helper/issues"
|
||||
},
|
||||
"homepage": "https://github.com/revanced/revanced-helper#readme",
|
||||
"dependencies": {
|
||||
"bson": "^6.2.0",
|
||||
"valibot": "^0.21.0",
|
||||
"zod": "^3.22.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ enum DisconnectReason {
|
||||
/**
|
||||
* The client had never connected to the server (**CLIENT-ONLY**)
|
||||
*/
|
||||
NeverConnected
|
||||
NeverConnected,
|
||||
}
|
||||
|
||||
export default DisconnectReason
|
||||
@@ -4,8 +4,9 @@ const HumanizedDisconnectReason = {
|
||||
[DisconnectReason.InvalidPacket]: 'has sent invalid packet',
|
||||
[DisconnectReason.Generic]: 'has been disconnected for unknown reasons',
|
||||
[DisconnectReason.TimedOut]: 'has timed out',
|
||||
[DisconnectReason.ServerError]: 'has been disconnected due to an internal server error',
|
||||
[DisconnectReason.NeverConnected]: 'had never connected to the server'
|
||||
[DisconnectReason.ServerError]:
|
||||
'has been disconnected due to an internal server error',
|
||||
[DisconnectReason.NeverConnected]: 'had never connected to the server',
|
||||
} as const satisfies Record<DisconnectReason, string>
|
||||
|
||||
export default HumanizedDisconnectReason
|
||||
@@ -50,8 +50,8 @@ export enum ServerOperation {
|
||||
/**
|
||||
* Server's disconnect message
|
||||
*/
|
||||
Disconnect = 20
|
||||
Disconnect = 20,
|
||||
}
|
||||
|
||||
export const Operation = { ...ClientOperation, ...ServerOperation } as const
|
||||
export type Operation = (ClientOperation | ServerOperation)
|
||||
export type Operation = ClientOperation | ServerOperation
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { Packet } from '../schemas/Packet.js'
|
||||
import { ClientOperation, Operation, ServerOperation } from '../constants/Operation.js'
|
||||
import {
|
||||
ClientOperation,
|
||||
Operation,
|
||||
ServerOperation,
|
||||
} from '../constants/Operation.js'
|
||||
|
||||
/**
|
||||
* Checks whether a packet is trying to do the given operation
|
||||
@@ -7,7 +11,10 @@ import { ClientOperation, Operation, ServerOperation } from '../constants/Operat
|
||||
* @param packet A packet
|
||||
* @returns Whether this packet is trying to do the operation given
|
||||
*/
|
||||
export function packetMatchesOperation<TOp extends Operation>(op: TOp, packet: Packet): packet is Packet<TOp> {
|
||||
export function packetMatchesOperation<TOp extends Operation>(
|
||||
op: TOp,
|
||||
packet: Packet
|
||||
): packet is Packet<TOp> {
|
||||
return packet.op === op
|
||||
}
|
||||
|
||||
@@ -16,7 +23,9 @@ export function packetMatchesOperation<TOp extends Operation>(op: TOp, packet: P
|
||||
* @param packet A packet
|
||||
* @returns Whether this packet is a client packet
|
||||
*/
|
||||
export function isClientPacket(packet: Packet): packet is Packet<ClientOperation> {
|
||||
export function isClientPacket(
|
||||
packet: Packet
|
||||
): packet is Packet<ClientOperation> {
|
||||
return packet.op in ClientOperation
|
||||
}
|
||||
|
||||
@@ -25,6 +34,8 @@ export function isClientPacket(packet: Packet): packet is Packet<ClientOperation
|
||||
* @param packet A packet
|
||||
* @returns Whether this packet is a server packet
|
||||
*/
|
||||
export function isServerPacket(packet: Packet): packet is Packet<ServerOperation> {
|
||||
export function isServerPacket(
|
||||
packet: Packet
|
||||
): packet is Packet<ServerOperation> {
|
||||
return packet.op in ServerOperation
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export function uncapitalize<T extends string>(str: T): Uncapitalize<T> {
|
||||
return str.charAt(0).toLowerCase() + str.slice(1) as Uncapitalize<T>
|
||||
return (str.charAt(0).toLowerCase() + str.slice(1)) as Uncapitalize<T>
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
"rootDir": "./src",
|
||||
"outDir": "dist",
|
||||
"module": "ESNext",
|
||||
"composite": true,
|
||||
"composite": true
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"extends": "./tsconfig.base.json"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
// `bun-types` will not be added until https://github.com/oven-sh/bun/issues/7247 is fixed
|
||||
"extends": ["@tsconfig/strictest", /* "bun-types" */],
|
||||
"extends": ["@tsconfig/strictest" /* "bun-types" */],
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext"],
|
||||
"module": "NodeNext",
|
||||
@@ -12,6 +12,6 @@
|
||||
"esModuleInterop": true,
|
||||
"declaration": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"isolatedModules": true,
|
||||
},
|
||||
"isolatedModules": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"declarationMap": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
@@ -10,6 +10,6 @@
|
||||
},
|
||||
{
|
||||
"path": "./packages/api"
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user