const Discord = require('discord.js');
const client = new Discord.Client();
var author = " ";
var storedLink = " ";
var link;
var messageId;
var yes = false;
var linkNo = 0;
var now = new Date().getTime();
var sjl = new Date("2021-03-16").getTime();
var mat = new Date("2021-03-19").getTime();
var dokument = new Date("2021, 3, 5, 12:00").getTime();
// var martinovOdpocet = new Date("2020-12-25").getTime();
// var petrovOdpocet = new Date("2020, 12, 10, 12:00").getTime();
// var endOdpocet = new Date("2021-01-01").getTime();
var xiao = new Date("2021, 2, 3, 11:00").getTime();
var remainingSjl;
var remainingMat;
var remainingDok;
var left = 0;
var end = false;
var ping = 86000;
var countdownChannel;
var first = true;
var setNew = true;
var replyChannelId;
var mentionedChannelId;

client.once('ready', () => {
    console.log('Im online!');
});

client.on('message', message => {
    const args = message.content.split(' ');

    let msg = message.content.toLowerCase();

    if(message.content.includes(":USureBoutThat:")){
        message.channel.send("<:ugh:802988623271428117>");
    }

  if(message.content.includes('https://media.discordapp.net')) {
if(message.content.includes('webm') || message.content.includes('mov') ||
message.content.includes('mp4'))
{
let linkArr = message.content.split('https://media.discordapp.net');
message.channel.send('https://cdn.discordapp.com' +linkArr[1]) 
} 
} 
	
	
	
    var msgContent = message.content;

    var msgContentSplit = msgContent.split(" ");

    if(message.reference != null){

        if(msgContentSplit.length == 1 && message.mentions.channels.first() != undefined){

            var replyMessageId = message.reference.messageID;
            
            mentionedChannelId = msgContentSplit[0].substring(2, msgContentSplit[0].length - 1);
            replyChannelId = message.reference.channelID;
            
            var replyChannel = client.channels.cache.find(channel => channel.id === replyChannelId);

            replyChannel.messages.fetch(replyMessageId).then(msg => {
                var movedMessageContent;
                if(msg.attachments.first() != undefined){
                    var attachment = msg.attachments.first();
                    movedMessageContent = new Discord.MessageAttachment(attachment.url);
                }
                else{
                    movedMessageContent = msg.content;
                }
                client.channels.cache.get(mentionedChannelId).send(movedMessageContent).then(msgToEdit => {
                        msgToEdit.edit("Sent by <@" + msg.author + "> \nmooved <@" + message.author + ">\n" + msgToEdit.content);
                });
                msg.delete({timeout: 3000});
            });
            message.delete({timeout: 3000});
        }
    }

    if (msg.startsWith("henlo") && message.author.bot == false) {
        var emojis = ["🥰", "🐄", "🐮", "❤️", "👋", "🤠", "😊"];
        let randomNum = Math.floor(Math.random() * 7);
        message.channel.send("Henlooo " + message.author.username + "   " + emojis[randomNum]);
    }
    else if (msg.startsWith("how ye") && message.author.bot === false) {
        let randomNum = Math.floor(Math.random() * 5);
        var responses = ["Not bad, how yee?", "MOOdy", "A bit sad 😢", "Good, how yee?", "I'm fine, how yee?"];
        message.channel.send(responses[randomNum]);
    }
    else if (msg.startsWith("tylko jedno")) {
        message.channel.send("Koksu pięć gram odlecieć sam");
    }
    else if (msg.startsWith("time?") || msg.startsWith("left?")){
        countdowns(0);
    }

});

client.login(process.env.token);
