From 706bde4eb6feec0b7b4298035a77b3ba5a64a18a Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Sun, 4 Apr 2021 20:06:32 -0500 Subject: [PATCH] =?UTF-8?q?Use=20database=20to=20store=20k=C3=BClboard=20m?= =?UTF-8?q?essages=20to=20know=20if=20messages=20should=20be=20edited=20on?= =?UTF-8?q?=20reaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.js | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/bot.js b/bot.js index ce70602..bba2514 100644 --- a/bot.js +++ b/bot.js @@ -99,7 +99,7 @@ async function aboutBot(message) { }) .catch(console.error); const aboutBotEmbed = new Discord.MessageEmbed() - .setTitle("About me!") + .setTitle("Invite link!") .setURL(`https://adat.link/awesomemod`) .setAuthor(client.user.tag, client.user.avatarURL()) .addField(`Servers`, `${serverCount}`, true) @@ -706,7 +706,7 @@ client.on('messageDeleteBulk', messages => { }); client.on('messageUpdate', (originalMessage, editedMessage) => { - message.channel.messages.fetch(editedMessage.id) + editedMessage.channel.messages.fetch(editedMessage.id) .then(editedMessage => { const editEmbed = new Discord.MessageEmbed() .setTitle("Message Edited") @@ -780,6 +780,7 @@ client.on('messageReactionAdd', (messageReaction, user) => { .setTitle("Very kül message") .setURL(message.url) .setAuthor(message.author.tag, message.author.avatarURL()) + .addField(`😎 Reactions`, `${numEmoji}`) .addField("Message", message.content) .addField("Channel", message.channel) .setThumbnail(message.author.avatarURL()) @@ -788,6 +789,8 @@ client.on('messageReactionAdd', (messageReaction, user) => { .setTimestamp(); collection.findOne({ guild_id: messageReaction.message.guild.id }, (error, result) => { + let kulboardChannel; + let botLogsChannel; if (error) { console.error; } @@ -796,11 +799,36 @@ client.on('messageReactionAdd', (messageReaction, user) => { if (message.guild.channels.cache.get(botLogsChannel)) { message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error); } - - if (result.kulboard_id) { - kulboardChannel = result.kulboard_id; - if (message.guild.channels.cache.get(kulboardChannel) && emoji === '😎' && numEmoji === 3) { - message.guild.channels.cache.get(kulboardChannel).send(kulboardEmbed).catch(console.error); + } + if (result.kulboard_id) { + kulboardChannel = result.kulboard_id; + if (message.guild.channels.cache.get(kulboardChannel) && emoji === '😎' && numEmoji >= 3) { + if (!result.kulboard_messages) { + message.guild.channels.cache.get(kulboardChannel).send(kulboardEmbed) + .then(kulboardMessage => { + collection.updateOne({ guild_id: message.guild.id }, { $set: { "kulboard_messages": [{ "original_message": `${message.id}`, "kulboard_message": `${kulboardMessage.id}` }] } }); + }).catch(console.error) + } else { + collection.findOne( {"guild_id": `${message.guild.id}`}, { "projection": { "kulboard_messages": { "$elemMatch": { "original_message": `${message.id}` }}}}, (error, result) => { + if (error) { + console.error; + } + console.log(result) + if (!result.kulboard_messages) { + message.guild.channels.cache.get(kulboardChannel).send(kulboardEmbed) + .then(kulboardMessage => { + collection.updateOne({ guild_id: message.guild.id }, { $push: { "kulboard_messages": { "original_message": `${message.id}`, "kulboard_message": `${kulboardMessage.id}` } } }); + }).catch(console.error); + } else { + console.log(result) + console.log(result.kulboard_messages) + message.guild.channels.cache.get(kulboardChannel).messages.fetch(result.kulboard_messages[0].kulboard_message) + .then(kulboardMessage => { + console.log(kulboardMessage.author.tag) + kulboardMessage.edit(kulboardEmbed).catch(console.error); + }).catch(console.error); + } + }); } } }