package io.github.likcoras.asuka;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.pircbotx.User;
import lombok.Cleanup;

public class IgnoreManager {
	
	private Set<String> ignored;
	private Path ignoreFile;
	
	public IgnoreManager() {
		ignored = Collections.synchronizedSet(new HashSet<String>());
		ignoreFile = Paths.get("ignore.txt");
	}
	
	public void addIgnored(User user) {
		addIgnored(BotUtil.getId(user));
	}
	
	public void addIgnored(String user) {
		ignored.add(user);
	}
	
	public void removeIgnored(User user) {
		removeIgnored(BotUtil.getId(user));
	}
	
	public void removeIgnored(String user) {
		ignored.remove(user);
	}
	
	public boolean isIgnored(User user) {
		return ignored.contains(BotUtil.getId(user));
	}
	
	public void writeFile() throws IOException {
		@Cleanup
		BufferedWriter write = Files.newBufferedWriter(ignoreFile);
		synchronized(ignored) {
			for (String user : ignored)
				write.write(user + "\n");
		}
		write.flush();
	}
	
}

@@ -28,16 +28,47 @@
 asuka;%0A%0A
+import java.io.BufferedReader;%0A
 import j
@@ -86,24 +86,24 @@
 eredWriter;%0A
-
 import java.
@@ -177,36 +177,8 @@
 th;%0A
-import java.nio.file.Paths;%0A
 impo
@@ -366,34 +366,8 @@
 ed;%0A
-%09private Path ignoreFile;%0A
 %09%0A%09p
@@ -458,48 +458,8 @@
 ));%0A
-%09%09ignoreFile = Paths.get(%22ignore.txt%22);%0A
 %09%7D%0A%09
@@ -839,32 +839,283 @@
 Id(user));%0A%09%7D%0A%09%0A
+%09public void readFile(Path ignoreFile) throws IOException %7B%0A%09%09@Cleanup%0A%09%09BufferedReader read = Files.newBufferedReader(ignoreFile);%0A%09%09synchronized (ignored) %7B%0A%09%09%09String line;%0A%09%09%09while ((line = read.readLine()) != null)%0A%09%09%09%09ignored.add(line);%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09public void wri
@@ -1121,16 +1121,31 @@
 iteFile(
+Path ignoreFile
 ) throws
@@ -1224,32 +1224,32 @@
 er(ignoreFile);%0A
-
 %09%09synchronized(i
@@ -1246,16 +1246,17 @@
 hronized
+ 
 (ignored

Allow reading and writing from a specified Path