/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package FunctionLayer;
//https://github.com/Javacord/Javacord
//https://discordapp.com/developers/applications/
//https://docs.javacord.org/api/v/3.0.1/org/javacord/api/DiscordApi.html
//https://stackoverflow.com/questions/17654213/how-do-i-create-a-netbeans-style-jar-with-all-dependencies-in-a-lib-folder
//ps ax | grep EventNotfierDiscordBot-1.0
//kill $pid (number)
/*
screen -d -m -S nonRoot java -jar /home/sourcemodextensionstest/EventNotfierDiscordBot/EventNotfierDiscordBot-1.0.jar
screen -ls (number1)
screen -X -S (number1) quit
 */

import DataLayer.DataMapper;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.javacord.api.event.message.MessageCreateEvent;

/**
 *
 * @author install1
 */
public class Bottest {

    public static void main(String[] args) {
        // Insert your bot's token here
        String token = "NTI5MDIyODgwOTU3MDcxMzk5.Dwqy6w.sgbRejEzZOLdTqyqzDmktSTBDpM";
        DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
        api.addMessageCreateListener((MessageCreateEvent event) -> {
            DataMapper.instance.checkUpdateTime();
            if (event.getMessageContent().equalsIgnoreCase("!event")) {
                try {
                    event.getChannel().sendMessage("Event Information: ");
                    DataMapper.instance.initialization();
                    List<StringObject> EventContent = DataMapper.instance.getAllMapValues();
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < EventContent.size(); i++) {
                        sb.append(EventContent.get(i).getEventContent()).append("\n");
                    }
                    event.getChannel().sendMessage(sb.toString());
                } catch (SQLException | IOException | CustomError ex) {
                    Logger.getLogger(Bottest.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
}
