mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-12 06:06:21 +00:00
Compare commits
8 Commits
@revanced/
...
@revanced/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f3295cc0f | ||
|
|
4da6175cf5 | ||
|
|
d90ad5c955 | ||
|
|
65add4dfee | ||
|
|
2c2f6b76d4 | ||
|
|
49c29bebfb | ||
|
|
4e889d4991 | ||
|
|
6d463df586 |
@@ -1,3 +1,10 @@
|
|||||||
|
# @revanced/bot-websocket-api [1.0.0-dev.9](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.8...@revanced/bot-websocket-api@1.0.0-dev.9) (2024-08-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **apis/websocket:** return `true` for data on a `TrainedMessage` packet ([65add4d](https://github.com/revanced/revanced-helper/commit/65add4dfeed2fa067c2c8e2377f7d01d505ade54))
|
||||||
|
|
||||||
# @revanced/bot-websocket-api [1.0.0-dev.8](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.7...@revanced/bot-websocket-api@1.0.0-dev.8) (2024-07-31)
|
# @revanced/bot-websocket-api [1.0.0-dev.8](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.7...@revanced/bot-websocket-api@1.0.0-dev.8) (2024-07-31)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "@revanced/bot-websocket-api",
|
"name": "@revanced/bot-websocket-api",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.0-dev.8",
|
"version": "1.0.0-dev.9",
|
||||||
"description": "🧦 WebSocket API server for bots assisting ReVanced",
|
"description": "🧦 WebSocket API server for bots assisting ReVanced",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const trainMessageEventHandler: EventHandler<ClientOperation.TrainMessage> = asy
|
|||||||
client.send(
|
client.send(
|
||||||
{
|
{
|
||||||
op: ServerOperation.TrainedMessage,
|
op: ServerOperation.TrainedMessage,
|
||||||
d: null,
|
d: true,
|
||||||
},
|
},
|
||||||
nextSeq,
|
nextSeq,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +1,17 @@
|
|||||||
|
# @revanced/discord-bot [1.0.0-dev.19](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.18...@revanced/discord-bot@1.0.0-dev.19) (2024-08-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **bots/discord:** correct whitelist logic ([49c29be](https://github.com/revanced/revanced-helper/commit/49c29bebfbe348ae4e2cc1b3a83bfa41eb26ccd1))
|
||||||
|
|
||||||
|
# @revanced/discord-bot [1.0.0-dev.18](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.17...@revanced/discord-bot@1.0.0-dev.18) (2024-08-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **bots/discord:** set the `label` property correctly for message scans ([6d463df](https://github.com/revanced/revanced-helper/commit/6d463df586dee5dd8fe8d6cff1c5316f7809b32a))
|
||||||
|
|
||||||
# @revanced/discord-bot [1.0.0-dev.17](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.16...@revanced/discord-bot@1.0.0-dev.17) (2024-08-02)
|
# @revanced/discord-bot [1.0.0-dev.17](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.16...@revanced/discord-bot@1.0.0-dev.17) (2024-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "@revanced/discord-bot",
|
"name": "@revanced/discord-bot",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.0-dev.17",
|
"version": "1.0.0-dev.19",
|
||||||
"description": "🤖 Discord bot assisting ReVanced",
|
"description": "🤖 Discord bot assisting ReVanced",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ withContext(on, 'messageCreate', async (context, msg) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (label) {
|
if (label) {
|
||||||
db.insert(responses).values({
|
await db.insert(responses).values({
|
||||||
replyId: reply.id,
|
replyId: reply.id,
|
||||||
channelId: reply.channel.id,
|
channelId: reply.channel.id,
|
||||||
guildId: reply.guild!.id,
|
guildId: reply.guild!.id,
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ const PossibleReactions = Object.values(Reactions) as string[]
|
|||||||
|
|
||||||
withContext(on, 'messageReactionAdd', async (context, rct, user) => {
|
withContext(on, 'messageReactionAdd', async (context, rct, user) => {
|
||||||
if (user.bot) return
|
if (user.bot) return
|
||||||
|
await rct.users.remove(user.id)
|
||||||
|
|
||||||
const { database: db, logger, config } = context
|
const { database: db, logger, config } = context
|
||||||
const { messageScan: msConfig } = config
|
const { messageScan: msConfig } = config
|
||||||
|
|
||||||
@@ -35,10 +36,7 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => {
|
|||||||
|
|
||||||
if (!isAdmin(reactionMessage.member || reactionMessage.author)) {
|
if (!isAdmin(reactionMessage.member || reactionMessage.author)) {
|
||||||
// User is in guild, and config has member requirements
|
// User is in guild, and config has member requirements
|
||||||
if (
|
if (reactionMessage.inGuild() && msConfig.humanCorrections.allow) {
|
||||||
reactionMessage.inGuild() &&
|
|
||||||
(msConfig.humanCorrections.allow?.members || msConfig.humanCorrections.allow?.users)
|
|
||||||
) {
|
|
||||||
const {
|
const {
|
||||||
allow: { users: allowedUsers, members: allowedMembers },
|
allow: { users: allowedUsers, members: allowedMembers },
|
||||||
} = msConfig.humanCorrections
|
} = msConfig.humanCorrections
|
||||||
@@ -54,20 +52,19 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
} else if (allowedUsers) {
|
} else if (!allowedUsers?.includes(user.id)) return
|
||||||
if (!allowedUsers.includes(user.id)) return
|
} else
|
||||||
} else {
|
return void logger.warn(
|
||||||
return void logger.warn(
|
'No member or user requirements set for human corrections, all requests will be ignored',
|
||||||
'No member or user requirements set for human corrections, all requests will be ignored',
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
const response = await db.query.responses.findFirst({ where: eq(responses.replyId, rct.message.id) })
|
const response = await db.query.responses.findFirst({ where: eq(responses.replyId, rct.message.id) })
|
||||||
if (!response || response.correctedById) return
|
if (!response || response.correctedById) return
|
||||||
|
|
||||||
|
logger.debug(`User ${user.id} is trying to correct the response ${rct.message.id}`)
|
||||||
|
|
||||||
const handleCorrection = (label: string) =>
|
const handleCorrection = (label: string) =>
|
||||||
handleUserResponseCorrection(context, response, reactionMessage, label, user)
|
handleUserResponseCorrection(context, response, reactionMessage, label, user)
|
||||||
|
|
||||||
|
|||||||
@@ -79,17 +79,15 @@ export const getResponseFromText = async (
|
|||||||
return responseConfig
|
return responseConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
responseConfig.label = trigger!.label
|
|
||||||
|
|
||||||
if (matchedLabel.confidence >= trigger!.threshold) {
|
if (matchedLabel.confidence >= trigger!.threshold) {
|
||||||
logger.debug('Label confidence is enough')
|
logger.debug('Label confidence is enough')
|
||||||
responseConfig = response
|
responseConfig = { ...responseConfig, ...response, label: trigger!.label }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we still don't have a response config, we can match all regexes after the initial label trigger
|
// If we still don't have a response config, we can match all regexes after the initial label trigger
|
||||||
if (!responseConfig.triggers) {
|
if (!responseConfig.triggers && ocrMode) {
|
||||||
logger.debug('No match from NLP, doing after regexes')
|
logger.debug('No match from NLP, doing after regexes')
|
||||||
for (let i = 0; i < responses.length; i++) {
|
for (let i = 0; i < responses.length; i++) {
|
||||||
const {
|
const {
|
||||||
@@ -124,17 +122,19 @@ export const messageMatchesFilter = (message: Message, filter: NonNullable<Confi
|
|||||||
// If matches whitelist but also matches blacklist, will return false
|
// If matches whitelist but also matches blacklist, will return false
|
||||||
// If matches only whitelist, will return true
|
// If matches only whitelist, will return true
|
||||||
// If matches neither, will return true
|
// If matches neither, will return true
|
||||||
return whitelist
|
return (
|
||||||
? (whitelist.channels?.includes(message.channelId) ?? true) ||
|
(whitelist
|
||||||
(whitelist.roles?.some(role => memberRoles.has(role)) ?? true) ||
|
? whitelist.channels?.includes(message.channelId) ||
|
||||||
(whitelist.users?.includes(message.author.id) ?? true)
|
whitelist.roles?.some(role => memberRoles.has(role)) ||
|
||||||
: true &&
|
whitelist.users?.includes(message.author.id)
|
||||||
!(
|
: true) &&
|
||||||
blacklist &&
|
!(
|
||||||
(blacklist.channels?.includes(message.channelId) ||
|
blacklist &&
|
||||||
blacklist.roles?.some(role => memberRoles.has(role)) ||
|
(blacklist.channels?.includes(message.channelId) ||
|
||||||
blacklist.users?.includes(message.author.id))
|
blacklist.roles?.some(role => memberRoles.has(role)) ||
|
||||||
)
|
blacklist.users?.includes(message.author.id))
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handleUserResponseCorrection = async (
|
export const handleUserResponseCorrection = async (
|
||||||
|
|||||||
@@ -77,9 +77,13 @@ export class ClientWebSocketManager {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
rj(e)
|
rj(e)
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
|
||||||
this.connecting = false
|
|
||||||
})
|
})
|
||||||
|
.then(() => {
|
||||||
|
this.#socket.on('close', (code, reason) => this._handleDisconnect(code, reason.toString()))
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.connecting = false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
url,
|
|
||||||
type AnySchema,
|
type AnySchema,
|
||||||
type NullSchema,
|
type NullSchema,
|
||||||
type ObjectSchema,
|
type ObjectSchema,
|
||||||
type Output,
|
type Output,
|
||||||
|
type BooleanSchema,
|
||||||
array,
|
array,
|
||||||
enum_,
|
enum_,
|
||||||
null_,
|
null_,
|
||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
parse,
|
parse,
|
||||||
special,
|
special,
|
||||||
string,
|
string,
|
||||||
|
boolean,
|
||||||
|
url,
|
||||||
// merge
|
// merge
|
||||||
} from 'valibot'
|
} from 'valibot'
|
||||||
import DisconnectReason from '../constants/DisconnectReason'
|
import DisconnectReason from '../constants/DisconnectReason'
|
||||||
@@ -26,8 +28,7 @@ export const PacketSchema = special<Packet>(input => {
|
|||||||
'op' in input &&
|
'op' in input &&
|
||||||
typeof input.op === 'number' &&
|
typeof input.op === 'number' &&
|
||||||
input.op in Operation &&
|
input.op in Operation &&
|
||||||
'd' in input &&
|
'd' in input
|
||||||
typeof input.d === 'object'
|
|
||||||
) {
|
) {
|
||||||
if (input.op in ServerOperation && !('s' in input && typeof input.s === 'number')) return false
|
if (input.op in ServerOperation && !('s' in input && typeof input.s === 'number')) return false
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ export const PacketDataSchemas = {
|
|||||||
[ServerOperation.Disconnect]: object({
|
[ServerOperation.Disconnect]: object({
|
||||||
reason: enum_(DisconnectReason),
|
reason: enum_(DisconnectReason),
|
||||||
}),
|
}),
|
||||||
[ServerOperation.TrainedMessage]: null_(),
|
[ServerOperation.TrainedMessage]: boolean(),
|
||||||
[ServerOperation.TrainMessageFailed]: null_(),
|
[ServerOperation.TrainMessageFailed]: null_(),
|
||||||
|
|
||||||
[ClientOperation.ParseText]: object({
|
[ClientOperation.ParseText]: object({
|
||||||
@@ -78,7 +79,7 @@ export const PacketDataSchemas = {
|
|||||||
} as const satisfies Record<
|
} as const satisfies Record<
|
||||||
Operation,
|
Operation,
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: This is a schema, it's not possible to type it
|
// biome-ignore lint/suspicious/noExplicitAny: This is a schema, it's not possible to type it
|
||||||
ObjectSchema<any> | AnySchema | NullSchema
|
ObjectSchema<any> | AnySchema | NullSchema | BooleanSchema
|
||||||
>
|
>
|
||||||
|
|
||||||
export type Packet<TOp extends Operation = Operation> = TOp extends ServerOperation
|
export type Packet<TOp extends Operation = Operation> = TOp extends ServerOperation
|
||||||
|
|||||||
Reference in New Issue
Block a user