package io.github.likcoras.ssbot.auth;

import io.github.likcoras.ssbot.backends.AuthDataHandler;
import io.github.likcoras.ssbot.backends.DataHandler;

import org.pircbotx.Channel;
import org.pircbotx.User;
import org.pircbotx.UserLevel;

public class AuthHandler {
	
	CustomUserPrefixHandler customPrefix;
	
	public AuthHandler() {
		
		customPrefix = new CustomUserPrefixHandler();
		
	}
	
	public boolean checkAuth(final UserLevel required, final User user,
		final Channel chan) {
		
		final UserLevel level = customPrefix.getLevel(user, chan);
		
		if (level != null && required.compareTo(level) <= 0)
			return true;
		
		return false;
		
	}
	
	public boolean checkAuth(final DataHandler handler, final String msg,
		final User user, final Channel chan) {
		
		if (!(handler instanceof AuthDataHandler))
			return true;
		
		final UserLevel required =
			((AuthDataHandler) handler).getAuthLevel(msg);
		
		if (required == null)
			return true;
		
		return checkAuth(required, user, chan);
		
	}
	
}

@@ -263,16 +263,24 @@
 er %7B%0A%09%0A%09
+private 
 CustomUs
@@ -538,26 +538,26 @@
 etLevel(
-user, chan
+chan, user
 );%0A%09%09%0A%09%09
@@ -1006,10 +1006,89 @@
 %09%09%0A%09%7D%0A%09%0A
+%09CustomUserPrefixHandler getCustomPrefix() %7B%0A%09%09%0A%09%09return customPrefix;%0A%09%09%0A%09%7D%0A%09%0A
 %7D%0A

Access to CustomUserPrefixHandler reduced