Browse Source

Use database to store külboard messages to know if messages should be edited on reaction

master
Abheek Dhawan 4 years ago
parent
commit
706bde4eb6
  1. 42
      bot.js

42
bot.js

@ -99,7 +99,7 @@ async function aboutBot(message) {
}) })
.catch(console.error); .catch(console.error);
const aboutBotEmbed = new Discord.MessageEmbed() const aboutBotEmbed = new Discord.MessageEmbed()
.setTitle("About me!") .setTitle("Invite link!")
.setURL(`https://adat.link/awesomemod`) .setURL(`https://adat.link/awesomemod`)
.setAuthor(client.user.tag, client.user.avatarURL()) .setAuthor(client.user.tag, client.user.avatarURL())
.addField(`Servers`, `${serverCount}`, true) .addField(`Servers`, `${serverCount}`, true)
@ -706,7 +706,7 @@ client.on('messageDeleteBulk', messages => {
}); });
client.on('messageUpdate', (originalMessage, editedMessage) => { client.on('messageUpdate', (originalMessage, editedMessage) => {
message.channel.messages.fetch(editedMessage.id) editedMessage.channel.messages.fetch(editedMessage.id)
.then(editedMessage => { .then(editedMessage => {
const editEmbed = new Discord.MessageEmbed() const editEmbed = new Discord.MessageEmbed()
.setTitle("Message Edited") .setTitle("Message Edited")
@ -780,6 +780,7 @@ client.on('messageReactionAdd', (messageReaction, user) => {
.setTitle("Very kül message") .setTitle("Very kül message")
.setURL(message.url) .setURL(message.url)
.setAuthor(message.author.tag, message.author.avatarURL()) .setAuthor(message.author.tag, message.author.avatarURL())
.addField(`😎 Reactions`, `${numEmoji}`)
.addField("Message", message.content) .addField("Message", message.content)
.addField("Channel", message.channel) .addField("Channel", message.channel)
.setThumbnail(message.author.avatarURL()) .setThumbnail(message.author.avatarURL())
@ -788,6 +789,8 @@ client.on('messageReactionAdd', (messageReaction, user) => {
.setTimestamp(); .setTimestamp();
collection.findOne({ guild_id: messageReaction.message.guild.id }, (error, result) => { collection.findOne({ guild_id: messageReaction.message.guild.id }, (error, result) => {
let kulboardChannel;
let botLogsChannel;
if (error) { if (error) {
console.error; console.error;
} }
@ -796,11 +799,36 @@ client.on('messageReactionAdd', (messageReaction, user) => {
if (message.guild.channels.cache.get(botLogsChannel)) { if (message.guild.channels.cache.get(botLogsChannel)) {
message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error); message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error);
} }
}
if (result.kulboard_id) { if (result.kulboard_id) {
kulboardChannel = result.kulboard_id; kulboardChannel = result.kulboard_id;
if (message.guild.channels.cache.get(kulboardChannel) && emoji === '😎' && numEmoji === 3) { if (message.guild.channels.cache.get(kulboardChannel) && emoji === '😎' && numEmoji >= 3) {
message.guild.channels.cache.get(kulboardChannel).send(kulboardEmbed).catch(console.error); 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);
}
});
} }
} }
} }

Loading…
Cancel
Save