package io.github.likcoras.ssbot;

import io.github.likcoras.ssbot.backends.BttHandler;
import io.github.likcoras.ssbot.backends.MuHandler;
import io.github.likcoras.ssbot.backends.SilentLatestHandler;
import io.github.likcoras.ssbot.backends.XmlHandler;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.log4j.Logger;
import org.pircbotx.exception.IrcException;
import org.xml.sax.SAXException;

public class SSBot {
	
	private static final Logger LOG = Logger.getLogger(SSBot.class);
	
	public static void main(final String[] args) {
		
		LOG.info("Starting SSBot...");
		
		final ConfigParser cfg = new ConfigParser();
		
		try {
			
			cfg.parse();
			
		} catch (final IOException e) {
			
			LOG.fatal("Error while loading config:", e);
			
		}
		
		final BotManager bot = new BotManager(cfg);
		bot.registerHandler(new BttHandler(cfg));
		bot.registerHandler(new SilentLatestHandler(cfg));
		
		try {
			
			bot.registerHandler(new MuHandler(cfg));
			
		} catch (final ClassNotFoundException e) {
			
			LOG.warn("Error while loading MuHandler:", e);
			
		}
		
		final XmlHandler xml = new XmlHandler(cfg);
		
		try {
			
			xml.update();
			
		} catch (IOException | SAXException | ParserConfigurationException e) {
			
			LOG.warn("Error while loading XmlHandler:", e);
			
		}
		
		bot.registerHandler(xml);
		
		try {
			
			bot.start();
			
		} catch (IOException | IrcException e) {
			
			LOG.warn("Error while running IRC bot:", e);
			
		}
		
		LOG.info("Bot stopped, exiting.");
		System.exit(0);
		
	}
	
}

@@ -847,16 +847,327 @@
 r(cfg);%0A
+%09%09registerHandlers(bot, cfg);%0A%09%09%0A%09%09try %7B%0A%09%09%09%0A%09%09%09bot.start();%0A%09%09%09%0A%09%09%7D catch (IOException %7C IrcException e) %7B%0A%09%09%09%0A%09%09%09LOG.warn(%22Error while running IRC bot:%22, e);%0A%09%09%09%0A%09%09%7D%0A%09%09%0A%09%09LOG.info(%22Bot stopped, exiting.%22);%0A%09%09System.exit(0);%0A%09%09%0A%09%7D%0A%09%0A%09private static void registerHandlers(BotManager bot, ConfigParser cfg) %7B%0A%09%09%0A
 %09%09bot.re
@@ -1685,204 +1685,8 @@
 %0A%09%09%0A
-%09%09try %7B%0A%09%09%09%0A%09%09%09bot.start();%0A%09%09%09%0A%09%09%7D catch (IOException %7C IrcException e) %7B%0A%09%09%09%0A%09%09%09LOG.warn(%22Error while running IRC bot:%22, e);%0A%09%09%09%0A%09%09%7D%0A%09%09%0A%09%09LOG.info(%22Bot stopped, exiting.%22);%0A%09%09System.exit(0);%0A%09%09%0A
 %09%7D%0A%09

Improve readability