package io.github.likcoras.asuka;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.pircbotx.User;

import com.google.common.collect.ImmutableSet;

import lombok.Cleanup;
import lombok.NonNull;

public class IgnoreManager {

	private Set<String> ignored;

	public IgnoreManager() {
		ignored = Collections.synchronizedSet(new HashSet<String>());
	}

	public void addIgnored(@NonNull User user) {
		addIgnored(user.getNick());
	}

	public void addIgnored(@NonNull String user) {
		ignored.add(user);
	}

	public void removeIgnored(@NonNull User user) {
		removeIgnored(user.getNick());
	}

	public void removeIgnored(@NonNull String user) {
		ignored.remove(user);
	}

	public boolean isIgnored(@NonNull User user) {
		return ignored.contains(user.getNick());
	}

	public Set<String> getIgnored() {
		return ImmutableSet.copyOf(ignored);
	}

	public void readFile(@NonNull Path ignoreFile) throws IOException {
		@Cleanup
		BufferedReader read = Files.newBufferedReader(ignoreFile);
		synchronized (ignored) {
			Files.lines(ignoreFile).forEach(ignored::add);
		}
	}

	public void writeFile(@NonNull Path ignoreFile) throws IOException {
		synchronized (ignored) {
			Files.write(ignoreFile, ignored);
		}
	}

}

@@ -1057,16 +1057,84 @@
 ption %7B%0A
+%09%09if (Files.notExists(ignoreFile))%0A%09%09%09Files.createFile(ignoreFile);%0A
 %09%09@Clean

Create file before reading