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

import java.util.List;

import org.bitbucket.eunjeon.seunjeon.Analyzer;
import org.bitbucket.eunjeon.seunjeon.LNode;
import org.bitbucket.eunjeon.seunjeon.Morpheme;

import net.dv8tion.jda.api.entities.Message;
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 TListener extends ListenerAdapter{
	List<SentimentalDictionary> dicList;
	
	public TListener(List<SentimentalDictionary> dicList) {
		this.dicList = dicList;
	}
	@Override
	public void onMessageReceived(MessageReceivedEvent event) {
		// TODO Auto-generated method stub
		User user = event.getAuthor();
		TextChannel tc = event.getTextChannel();
		Message msg = event.getMessage();
		if(user.isBot()) return;
//		// 형태소 분석
//		for (Eojeol eojeol : Analyzer.parseEojeolJava(msg.getContentRaw())) {
//			for (LNode node : eojeol.nodesJava()) {
//				Morpheme m = node.morpheme();
//				tc.sendMessage(m.surface() + " / 품사:" + m.feature().head()).queue();
//			}
//		}
		int count = 0;
		for (LNode node : Analyzer.parseJava(msg.getContentRaw())) {
			Morpheme m = node.morpheme();
			if(!m.feature().head().equalsIgnoreCase("jks")) {
				for(SentimentalDictionary dic : dicList) {
					if(dic.getWord_root().equalsIgnoreCase(m.surface())){
						count += Integer.parseInt(dic.getPolarity());
					}
				}
			}
		}	
		if(count > 0)
			tc.sendMessage(String.format("%s가 해피하네요", user.getName())).queue();
		else if(count < 0)
			tc.sendMessage(String.format("%s가 우울하네요", user.getName())).queue();
		
	}

}
