MOOver.js/moove.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

const { EmbedBuilder } = require('discord.js');
const help = require('./helpFunctions');
const client = require('./main');
2023-02-25 12:42:21 +00:00
function moove(message) {
message.react('🐮');
2023-02-25 12:42:21 +00:00
const content = message.content.trim();
2023-02-25 12:42:21 +00:00
if (content.search(/<#[0-9]*>$/g) != 0) {
return;
}
const originalChannel = message.channel;
const msgToMooveId = message.reference.messageId;
const mentionedChannel = client.channels.cache.get(content.substring(2, content.length - 1));
if (mentionedChannel == undefined) {
return;
}
2023-02-25 12:42:21 +00:00
originalChannel.messages.fetch(msgToMooveId).then(msg => {
const sentBy = `Sent by ${msg.author}\nmooved ${message.author}\n`;
2023-02-25 12:42:21 +00:00
if (msg.embeds.length > 0 && msg.content == '' && msg.attachments.size == 0) {
mentionedChannel.send({ embeds: msg.embeds });
2023-02-25 12:42:21 +00:00
}
else if (msg.attachments.size > 0) {
const originalMsgAttachments = msg.attachments.values();
2023-02-25 12:42:21 +00:00
const attachmentsArr = [];
2023-02-25 12:42:21 +00:00
for (let i = 0; i < msg.attachments.size; i++) {
attachmentsArr.push(originalMsgAttachments.next().value);
2023-02-25 12:42:21 +00:00
}
let messStr = '';
2023-02-25 12:42:21 +00:00
if (msg.content != '') {
messStr = '\nMessage:\n' + msg.content;
2023-02-25 12:42:21 +00:00
}
mentionedChannel.send({ content: sentBy + messStr, files: attachmentsArr });
2023-02-25 12:42:21 +00:00
if (msg.embeds.length > 0) {
mentionedChannel.send({ embeds: msg.embeds });
2023-02-25 12:42:21 +00:00
}
}
else {
if (msg.content == '') {
// ? Empty, Has embeds
mentionedChannel.send({
content: sentBy + `Message:\n${msg.content}`,
});
2023-02-25 12:42:21 +00:00
}
else {
// ? Has content, No embeds
const embed = new EmbedBuilder()
2023-02-25 12:42:21 +00:00
.setColor(help.randomColor())
.addFields(
{ name: 'MOO', value: sentBy },
{ name: 'Message', value: msg.content },
);
mentionedChannel.send({ embeds: [embed] });
2023-02-25 12:42:21 +00:00
}
}
setTimeout(() => msg.delete(), 3000);
});
setTimeout(() => message.delete(), 3000);
2023-02-25 12:42:21 +00:00
}
module.exports = moove;