diff --git a/main.js b/main.js index 26c2102..eeb5ed2 100755 --- a/main.js +++ b/main.js @@ -40,10 +40,16 @@ function gotMessage(message){ let content = message.content.trim() - var msgContentSplit = content.split(/[ ]+/); + const msgContentSplit = content.split(/[ ]+/); - if(message.reference != null){ - move(message, msgContentSplit) + /** + * reference can't be null => must be a reply to message + * must contain only one argument + * that argument mentions channel + */ + if(message.reference != null && msgContentSplit.length == 1 + && message.mentions.channels.first() != undefined){ + move(message, msgContentSplit[0]) } let isBot = message.author.bot @@ -116,55 +122,59 @@ function mood(message){ message.reply(responses[randomNum]); } -function move(message, splits){ - var replyChannelId; - var mentionedChannelId; +function move(message, channelId){ + message.react('🐮') + + const replyChannel = message.channel; - if(splits.length == 1 && message.mentions.channels.first() != undefined){ + // const replyChannelId = message.reference.channelId; + // const replyChannel = client.channels.cache.get(replyChannelId); + + const msgToMooveId = message.reference.messageId; + + const mentionedChannelId = channelId.substring(2, channelId.length - 1) + - message.react('🐮') - - var replyMessageId = message.reference.messageID; - - mentionedChannelId = splits[0].substring(2, splits[0].length - 1); - replyChannelId = message.reference.channelID; - - var replyChannel = client.channels.cache.get(replyChannelId); - - // create embed - // add field for every attachment - // keď je tam emebed tak možnosť cez emotes či vymazať original post alebo nie - // zisti ako sa robia replies ako robia normálny usery - replyChannel.messages.fetch(replyMessageId).then(msg => { - let newMessage = [] + // create embed + // add field for every attachment + // keď je tam emebed tak možnosť cez emotes či vymazať original post alebo nie + replyChannel.messages.fetch(msgToMooveId).then(msg => { + + + if (msg.attachments.size > 0){ + // var exampleEmbed = new MessageEmbed() + // .setTitle('Some title') + // .setImage(allAttachments.next().value) + // .addField('Inline field title', 'Some value here', true); + // .addField("Original message: ", message.content) + let newMsgAttachments = [] let allAttachments = msg.attachments.values() + for (let i = 0; i < msg.attachments.size; i++){ let currAttachment = allAttachments.next().value - newMessage.push(new MessageAttachment(currAttachment.url)) + newMsgAttachments.push(new MessageAttachment(currAttachment.url)) } - if (newMessage.length > 0){ - client.channels.cache.get(mentionedChannelId).send(newMessage).then(msgToEdit => { - msgToEdit.edit(`Sent by ${msg.author}\nmooved ${message.author}\n`) - }) - msg.delete({timeout: 3000}); + client.channels.cache.get(mentionedChannelId).send({files: newMsgAttachments}).then(msgToEdit => { + msgToEdit.edit(`Sent by ${msg.author}\nmooved ${message.author}\n`) + }) + setTimeout(() => msg.delete(), 3000); + } + else { + if (msg.embeds.length > 0){ + message.channel.send("Can't really moove embeds yet, sowwy :c") } else { - if (msg.embeds.length > 0){ - message.channel.send("Can't really moove embeds, sowwy :c") - } - else { - let newMsg = new MessageEmbed() - .setColor(randomColor()) - .addField("MOO", `Sent by ${msg.author}\nmooved ${message.author}`) - .addField("Message:", msg.content) - client.channels.cache.get(mentionedChannelId).send(newMsg) - msg.delete({timeout: 3000}) - } + const embed = new MessageEmbed() + .setColor(randomColor()) + .addField("MOO", `Sent by ${msg.author}\nmooved ${message.author}`) + .addField("Message:", msg.content) + client.channels.cache.get(mentionedChannelId).send({embeds: [embed]}) + setTimeout(() => msg.delete(), 3000); } - }); - message.delete({timeout: 3000}); - } + } + }); + setTimeout(() => message.delete(), 3000); } function say(message){