<commit_before>package heufybot.modules;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Iterator;

import heufybot.core.Channel;
import heufybot.core.HeufyBot;
import heufybot.core.User;
import heufybot.core.events.EventListenerAdapter;
import heufybot.core.events.types.*;
import heufybot.utils.StringUtils;
import heufybot.utils.enums.ModuleLoaderResponse;

public class ModuleInterface extends EventListenerAdapter
{
	private ArrayList<Module> modules;
	private HeufyBot bot;
	
	public ModuleInterface(HeufyBot bot)
	{
		this.modules = new ArrayList<Module>();
		this.bot = bot;
	}
	
	public SimpleEntry<ModuleLoaderResponse, String> loadModule(String moduleName)
	{
		try
		{
			for(Module module : modules)
			{
				String toLoad = "heufybot.modules." + moduleName;
				if(module.getClass().getName().toLowerCase().equals(toLoad.toLowerCase()))
				{
					return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.AlreadyLoaded, "");
				}
			}
			
			File[] folder = new File("modules").listFiles();
			for(int i = 0; i < folder.length; i++)
			{
				if(folder[i].getName().equalsIgnoreCase(moduleName + ".jar"))
				{
					String foundFileName = folder[i].getName();
					moduleName = foundFileName.substring(0, foundFileName.indexOf(".jar"));
					URL[] urls = { folder[i].toURI().toURL() };
					
					ClassLoader loader = URLClassLoader.newInstance(urls, getClass().getClassLoader());
					
					Class<?> moduleClass = Class.forName("heufybot.modules." + moduleName, true, loader);
					Module module = (Module) moduleClass.newInstance();
					
					modules.add(module);
					module.onLoad();
					
					return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.Success, moduleName);
				}
			}
			return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.DoesNotExist, "");
		} 
		catch (Exception e)
		{
			return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.DoesNotExist, "");
		}
	}
	
	public SimpleEntry<ModuleLoaderResponse, String> unloadModule(String moduleName)
	{
		for(Iterator<Module> iter = modules.iterator(); iter.hasNext();)
		{
  			Module module = iter.next();
  			if(module.getClass().getSimpleName().equalsIgnoreCase(moduleName))
  			{
  				module.onUnload();
  				iter.remove();
  				return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.Success, module.getClass().getSimpleName());
  			}
		}
		return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.DoesNotExist, "");
	}
	
	public void onMessage(MessageEvent event)
	{
		String message = event.getMessage();
		Module[] listCopy = new Module[modules.size()];
		listCopy = modules.toArray(listCopy);
		for (int l = 0; l < listCopy.length; l++)
		{
			Module module = listCopy[l];
			if(message.toLowerCase().matches(module.getTrigger()))
			{
				if(isAuthorized(module, event.getChannel(), event.getUser()) || bot.getConfig().getBotAdmins().contains(event.getUser().getNickname()))
				{
					module.processEvent(event.getChannel().getName(), message, event.getUser().getNickname(), StringUtils.parseStringtoList(message, " "));
				}
				else
				{
					bot.getIRC().cmdPRIVMSG(event.getChannel().getName(), "You are not authorized to use the " + module.getClass().getSimpleName() + " module!");
				}
			}
		}
	}
	<commit_msg>Format that a little bit better<commit_after>package heufybot.modules;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Iterator;

import heufybot.core.Channel;
import heufybot.core.HeufyBot;
import heufybot.core.User;
import heufybot.core.events.EventListenerAdapter;
import heufybot.core.events.types.*;
import heufybot.utils.StringUtils;
import heufybot.utils.enums.ModuleLoaderResponse;

public class ModuleInterface extends EventListenerAdapter
{
	private ArrayList<Module> modules;
	private HeufyBot bot;
	
	public ModuleInterface(HeufyBot bot)
	{
		this.modules = new ArrayList<Module>();
		this.bot = bot;
	}
	
	public SimpleEntry<ModuleLoaderResponse, String> loadModule(String moduleName)
	{
		try
		{
			for(Module module : modules)
			{
				String toLoad = "heufybot.modules." + moduleName;
				if(module.getClass().getName().toLowerCase().equals(toLoad.toLowerCase()))
				{
					return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.AlreadyLoaded, "");
				}
			}
			
			File[] folder = new File("modules").listFiles();
			for(int i = 0; i < folder.length; i++)
			{
				if(folder[i].getName().equalsIgnoreCase(moduleName + ".jar"))
				{
					String foundFileName = folder[i].getName();
					moduleName = foundFileName.substring(0, foundFileName.indexOf(".jar"));
					URL[] urls = { folder[i].toURI().toURL() };
					
					ClassLoader loader = URLClassLoader.newInstance(urls, getClass().getClassLoader());
					
					Class<?> moduleClass = Class.forName("heufybot.modules." + moduleName, true, loader);
					Module module = (Module) moduleClass.newInstance();
					
					modules.add(module);
					module.onLoad();
					
					return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.Success, moduleName);
				}
			}
			return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.DoesNotExist, "");
		} 
		catch (Exception e)
		{
			return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.DoesNotExist, "");
		}
	}
	
	public SimpleEntry<ModuleLoaderResponse, String> unloadModule(String moduleName)
	{
		for(Iterator<Module> iter = modules.iterator(); iter.hasNext();)
		{
  			Module module = iter.next();
  			if(module.getClass().getSimpleName().equalsIgnoreCase(moduleName))
  			{
  				module.onUnload();
  				iter.remove();
  				return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.Success, module.getClass().getSimpleName());
  			}
		}
		return new SimpleEntry<ModuleLoaderResponse, String>(ModuleLoaderResponse.DoesNotExist, "");
	}
	
	public void onMessage(MessageEvent event)
	{
		String message = event.getMessage();
		Module[] listCopy = new Module[modules.size()];
		listCopy = modules.toArray(listCopy);
		for (int l = 0; l < listCopy.length; l++)
		{
			Module module = listCopy[l];
			if(message.toLowerCase().matches(module.getTrigger()))
			{
				if(isAuthorized(module, event.getChannel(), event.getUser()) || bot.getConfig().getBotAdmins().contains(event.getUser().getNickname()))
				{
					module.processEvent(event.getChannel().getName(), message, event.getUser().getNickname(), StringUtils.parseStringtoList(message, " "));
				}
				else
				{
					bot.getIRC().cmdPRIVMSG(event.getChannel().getName(), "You are not authorized to use the \"" + module.getClass().getSimpleName() + "\" module!");
				}
			}
		}
	}
	
{'fraction_non_alphanumeric': 0.13710144927536233, 'fraction_numerical': 0.0008695652173913044, 'mean_word_length': 4.3829953198127924, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1202530', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2106, 'n_words': 375}