feat: discord bot scanning messages

This commit is contained in:
GramingFoxTeam
2022-11-15 22:21:35 +03:00
parent bd2994388b
commit d1bd3b2b7e
4 changed files with 40 additions and 5 deletions

View File

@@ -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"
}
]
}

View File

@@ -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) => {

View File

@@ -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: {

View File

@@ -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: {