package me.lenajenichen.voicebot.listener;

import me.lenajenichen.voicebot.main.BotMain;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class CommandListener extends ListenerAdapter {

    @Override
    public void onMessageReceived(MessageReceivedEvent e) {
        String message = e.getMessage().getContentDisplay();

        if(e.isFromType(ChannelType.TEXT)) {
            TextChannel channel = e.getTextChannel();

            if(message.startsWith(".voice")) {
                String[] args = message.substring(1).split(" ");
                if(args.length > 0) {
                    if(!BotMain.INSTATNCE.getCmdMan().perform(args[1], e.getMember(), channel, e.getMessage())) {
                       channel.sendMessage(e.getMessage().getMember().getAsMention() + " folgende Commands existieren: \n`.voice unlock` um den Channel zu entsperren. \n`.voice lock` um deinen Channel zu sperren.").queue();
                    }
                }

            }
        }
    }

}
