diff --git a/bots/config.example.json b/bots/config.example.json index 5c280b9..26d9847 100644 --- a/bots/config.example.json +++ b/bots/config.example.json @@ -1,5 +1,18 @@ { "discord": { "token": "YOUR-BOT-TOKEN-HERE" - } + }, + + "server": { + "port": 3000, + "host": "192.168.1.6" + }, + + "responses": [ + { + "label": "DOWNLOAD", + "threshold": 0.85, + "text": "you wanted peevanced" + } + ] } \ No newline at end of file diff --git a/bots/discord/index.js b/bots/discord/index.js index d87dd63..c804493 100644 --- a/bots/discord/index.js +++ b/bots/discord/index.js @@ -9,10 +9,10 @@ const helper = new HelperClient(config); helper.connect(); -const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] }); +const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }); client.on(Events.MessageCreate, async (msg) => { - + helper.scanText(msg.content, `${msg.channelId}/${msg.id}`); }); client.on(Events.InteractionCreate, async (interaction) => { @@ -22,7 +22,29 @@ client.on(Events.InteractionCreate, async (interaction) => { // The ReVanced Helper events. helper.on('aiResponse', async (aiRes) => { + const response = config.responses.find(res => res.label === aiRes.predictions[0].label); + if (!response) return; + if (Number(aiRes.predictions[0].score) >= response.threshold) { + const ids = aiRes.id.split('/'); + let channel = client.channels.cache.get(ids[0]); + + if (!channel) { + await client.channels.fetch(ids[0]); + channel = client.channels.cache.get(ids[0]); + } + + let message = channel.messages.cache.get(ids[1]); + + if (!message) { + await channel.messages.fetch(ids[1]); + message = channel.messages.cache.get(ids[1]); + } + + message.reply(response.text); + + return; + } }); helper.on('ocrResponse', async (aiRes) => { diff --git a/client/index.js b/client/index.js index 09e4cc0..578a823 100644 --- a/client/index.js +++ b/client/index.js @@ -15,7 +15,7 @@ class HelperClient extends EventEmitter { }); this.client.on('data', (data) => { - const eventData = deserialize(data); + const eventData = deserialize(data, { allowObjectSmallerThanBufferSize: true }); switch (eventData.op) { case 2: { diff --git a/server/index.js b/server/index.js index f1d352b..a8d938d 100644 --- a/server/index.js +++ b/server/index.js @@ -23,7 +23,7 @@ global.ft = ft; const server = createServer(async (client) => { client.on('data', async (data) => { - const eventData = deserialize(data); + const eventData = deserialize(data, { allowObjectSmallerThanBufferSize: true }); switch(eventData.op) { case 1: {