package kr.co.swh.lecture.opensource.project.youtube; 

import java.util.ArrayList;

import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class Server_talker extends ListenerAdapter{
	
	
	@Override
    public void onMessageReceived(MessageReceivedEvent event) {
		User user = event.getAuthor();
		TextChannel tc = event.getTextChannel();
		Message msg = event.getMessage();
		String a = null;
		
		if(user.isBot()) return;
		if(msg.getContentRaw().equalsIgnoreCase("hello"))
		tc.sendMessage("hello, "+ user.getAsMention()).queue();
//		System.out.println(msg.getContentRaw().substring(0,3));
		//;
		if (msg.getContentRaw().equals("이봐 징징이 거기 동전좀 주워주겠나?"))
        {
            MessageChannel channel = event.getChannel();
            long time = System.currentTimeMillis();
            channel.sendMessage("d민믜ㅏㅇ아라아") /* => RestAction<Message> */
                   .queue(response /* => Message */ -> {
                       response.editMessageFormat("싫어요 사장님 사장님이 주우세요: %d ms", System.currentTimeMillis() - time).queue();
                   });
        }
		if (msg.getContentRaw().equals("자네 해고 되고 싶나?"))
        {
            MessageChannel channel = event.getChannel();
            long time = System.currentTimeMillis();
            channel.sendMessage("홀롤롤로") /* => RestAction<Message> */
                   .queue(response /* => Message */ -> {
                       response.editMessageFormat("알겠어요 주울께요: %d ms", System.currentTimeMillis() - time).queue();
                   });
        }
		if (msg.getContentRaw().equals("이때를 노렸어!"))
        {
            MessageChannel channel = event.getChannel();
            long time = System.currentTimeMillis();
            channel.sendMessage("암") /* => RestAction<Message> */
                   .queue(response /* => Message */ -> {
                       response.editMessageFormat("사장님 지금 뭐하시는거에요?: %d ms", System.currentTimeMillis() - time).queue();
                   });
        }
		if (msg.getContentRaw().equals("어이 리사"))
        {
            MessageChannel channel = event.getChannel();
            long time = System.currentTimeMillis();
            channel.sendMessage("홀롤롤로") /* => RestAction<Message> */
                   .queue(response /* => Message */ -> {
                       response.editMessageFormat("그래 "+ user.getAsMention(), System.currentTimeMillis() - time).queue();
                   });
        }
		if (msg.getContentRaw().substring(0,3).equals("%p ")){
			
			String m = msg.getContentRaw().substring(3);
			Youtube y = new Youtube();
			ArrayList<String> arr = y.audio(m);
			
			
			
            MessageChannel channel = event.getChannel();
            long time = System.currentTimeMillis();
            
            for(String s : arr) {
            	channel.sendMessage("홀롤롤로") /* => RestAction<Message> */
            	.queue(response /* => Message */ -> {

            		response.editMessage(s).queue();

            	});
            }
            
            
		}
    
	}
}