mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
feat(bots/discord)!: add more attachment scan options
This commit is contained in:
@@ -26,7 +26,11 @@ export type Config = {
|
|||||||
messageScan?: {
|
messageScan?: {
|
||||||
scanBots?: boolean
|
scanBots?: boolean
|
||||||
scanOutsideGuilds?: boolean
|
scanOutsideGuilds?: boolean
|
||||||
allowedAttachmentMimeTypes: string[]
|
attachments?: {
|
||||||
|
scanAttachments?: boolean
|
||||||
|
allowedMimeTypes?: string[]
|
||||||
|
maxTextFileSize?: number
|
||||||
|
}
|
||||||
filter?: {
|
filter?: {
|
||||||
whitelist?: Filter
|
whitelist?: Filter
|
||||||
blacklist?: Filter
|
blacklist?: Filter
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ withContext(on, 'messageCreate', async (context, msg) => {
|
|||||||
embeds: response.embeds?.map(createMessageScanResponseEmbed),
|
embeds: response.embeds?.map(createMessageScanResponseEmbed),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (label)
|
if (label) {
|
||||||
db.insert(responses).values({
|
db.insert(responses).values({
|
||||||
replyId: reply.id,
|
replyId: reply.id,
|
||||||
channelId: reply.channel.id,
|
channelId: reply.channel.id,
|
||||||
@@ -49,7 +49,6 @@ withContext(on, 'messageCreate', async (context, msg) => {
|
|||||||
content: msg.content,
|
content: msg.content,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (label) {
|
|
||||||
for (const reaction of Object.values(MessageScanLabeledResponseReactions)) {
|
for (const reaction of Object.values(MessageScanLabeledResponseReactions)) {
|
||||||
await reply.react(reaction)
|
await reply.react(reaction)
|
||||||
}
|
}
|
||||||
@@ -60,11 +59,22 @@ withContext(on, 'messageCreate', async (context, msg) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.attachments.size > 0) {
|
if (msg.attachments.size > 0 && config.attachments?.scanAttachments) {
|
||||||
logger.debug(`Classifying message attachments for ${msg.id}`)
|
logger.debug(`Classifying message attachments for ${msg.id}`)
|
||||||
|
|
||||||
for (const attachment of msg.attachments.values()) {
|
for (const attachment of msg.attachments.values()) {
|
||||||
if (attachment.contentType && !config.allowedAttachmentMimeTypes.includes(attachment.contentType)) continue
|
if (
|
||||||
|
config.attachments.allowedMimeTypes &&
|
||||||
|
!config.attachments.allowedMimeTypes.includes(attachment.contentType!)
|
||||||
|
) {
|
||||||
|
logger.debug(`Disallowed MIME type for attachment: ${attachment.url}, ${attachment.contentType}`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attachment.contentType?.startsWith('text/') && attachment.size > (config.attachments.maxTextFileSize ?? 512 * 1000)) {
|
||||||
|
logger.debug(`Attachment ${attachment.url} is too large be to scanned, size is ${attachment.size}`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { text: content } = await api.client.parseImage(attachment.url)
|
const { text: content } = await api.client.parseImage(attachment.url)
|
||||||
|
|||||||
Reference in New Issue
Block a user