package dev.nincodedo.ninbot.components.reaction;

import dev.nincodedo.ninbot.common.StatAwareListenerAdapter;
import dev.nincodedo.ninbot.components.config.component.ComponentService;
import dev.nincodedo.ninbot.components.config.component.ComponentType;
import dev.nincodedo.ninbot.components.stats.StatCategory;
import dev.nincodedo.ninbot.components.stats.StatManager;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
class ReactionListener extends StatAwareListenerAdapter {

    private List<ReactionResponse> reactionResponseList;
    private ComponentService componentService;
    private StatManager statManager;
    private String componentName;

    @Autowired
    public ReactionListener(List<ReactionResponse> reactionResponseList, ComponentService componentService,
            StatManager statManager) {
        super(statManager);
        this.reactionResponseList = reactionResponseList;
        this.componentService = componentService;
        this.statManager = statManager;
        this.componentName = "reaction-listener";
        componentService.registerComponent(componentName, ComponentType.LISTENER);
    }


    @Override
    public void onMessageReceived(MessageReceivedEvent event) {
        if (event.isFromGuild() && !event.getAuthor().isBot()
                && !componentService.isDisabled(componentName, event.getGuild().getId())) {
            respond(event);
        }
    }

    private void respond(MessageReceivedEvent event) {
        reactionResponseList.stream()
                .filter(reactionResponse -> reactionResponse.canRespond(event))
                .findFirst()
                .ifPresent(reactionResponse -> {
                    reactionResponse.react(event.getMessage(), event.getChannel());
                    statManager.addOneCount(reactionResponse.getResponse()
                            .toLowerCase(), StatCategory.REACTION, event.getGuild().getId());
                    countOneStat(componentName, event.getGuild().getId());
                });
    }
}

@@ -101,24 +101,80 @@
 nerAdapter;%0A
+import dev.nincodedo.ninbot.common.logging.UtilLogging;%0A
 import dev.n
@@ -235,16 +235,16 @@
 ervice;%0A
-
 import d
@@ -419,24 +419,58 @@
 tatManager;%0A
+import lombok.extern.slf4j.Slf4j;%0A
 import net.d
@@ -658,16 +658,23 @@
 .List;%0A%0A
+@Slf4j%0A
 @Compone
@@ -1638,23 +1638,295 @@
     
-respond(event);
+try %7B%0A                respond(event);%0A            %7D catch (Exception e) %7B%0A                log.error(%22Reaction listener error in server %7B%7D in channel %7B%7D%22,%0A                        UtilLogging.logGuildInfo(event.getGuild()), UtilLogging.logChannelInfo(event.getChannel()), e);%0A            %7D
 %0A   

Add logging for Reaction listener