package dev.nincodedo.ninbot.components.fun.eightball;

import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.EmbedBuilder;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Component
@Log4j2
public class Magic8BallMessageBuilder {

    private Random random;
    private List<String> eightBallAnswers;

    public Magic8BallMessageBuilder() {
        this.random = new Random();
        this.eightBallAnswers = readMagic8BallList();
    }

    EmbedBuilder getMagic8BallEmbed(String username) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setTitle(String.format("%s shakes the Magic 8 Ball", username));
        embedBuilder.setThumbnail("https://i.imgur.com/80imnZ0.png");
        embedBuilder.appendDescription("The Magic 8 Ball says...\n\n");
        embedBuilder.appendDescription("_" + getMagic8BallAnswer() + "_");
        return embedBuilder;
    }

    private String getMagic8BallAnswer() {
        return eightBallAnswers.get(random.nextInt(eightBallAnswers.size()));
    }

    private List<String> readMagic8BallList() {
        List<String> answers = new ArrayList<>();
        try {
            answers = Files.readAllLines(new ClassPathResource("magic8BallAnswers.txt").getFile().toPath());
        } catch (IOException e) {
            log.error("Failed to read magic8BallAnswers.txt", e);
        }
        return answers;
    }
}

@@ -244,27 +244,92 @@
 java.io.
-IOException
+BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader
 ;%0Aimport
@@ -1387,118 +1387,291 @@
 try 
-%7B%0A            answers = Files.readAllLines(new ClassPathResource(%22magic8BallAnswers.txt%22).getFile().toPath());
+(BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getClassLoader()%0A                .getResourceAsStream(%22magic8BallAnswers.txt%22)))) %7B%0A            String line;%0A            while ((line = br.readLine()) != null) %7B%0A                answers.add(line);%0A            %7D
 %0A   

Fix 8ball too