System.setProperty(SimpleLogger.LEVEL_IN_BRACKETS_KEY, "true");
System.setProperty(SimpleLogger.SHOW_LOG_NAME_KEY, "false");
System.out.println("Starting");
try {
startup = System.currentTimeMillis();
final Config config = new Config();
PermissionManager manager = new PermissionManager();
System.out.println("Loading and registering commands");
config.load();
manager.load();
Reflections reflections = new Reflections("com.zack6849.alphabot.commands");
Set<Class<? extends Command>> subTypes = reflections.getSubTypesOf(Command.class);
for (Class c : subTypes) {
Command cmd = CommandRegistry.getCommand(c.getSimpleName());
cmd.setManager(manager);
cmd.setConfig(config);
CommandRegistry.register(cmd);
}
//i have no idea what this is, but IDEA wouldn't shut the fuck up about changing it.
Configuration.Builder<PircBotX> builder = new Configuration.Builder<PircBotX>();
builder.setName(config.getBotNickname());
builder.setRealName(config.getBotUsername());
builder.setLogin(config.getBotIdent());
builder.setFinger(config.getCtcpFinger());
builder.setEncoding(Charset.isSupported("UTF-8") ? Charset.forName("UTF-8") : Charset.defaultCharset());
builder.setNickservPassword(config.getBotPassword());
builder.setVersion("Alphbot v2.0 BETA");
builder.setAutoNickChange(config.isAutoNickChange());
builder.setAutoReconnect(config.isAutoReconnectServer());
builder.setServer(config.getServerHostame(), Integer.parseInt(config.getServerPort()), config.getServerPassword());
builder.getListenerManager().addListener(new com.zack6849.alphabot.listeners.MessageEvent(config, manager));
builder.getListenerManager().addListener(new com.zack6849.alphabot.listeners.InviteEvent(config, manager));
for (String channel : config.getChannels()) {
builder.addAutoJoinChannel(channel);
}
PircBotX bot = new PircBotX(builder.buildConfiguration());
System.out.println("Starting bot...");
if (config.isEnableChatSocket()) {
new Thread(new ChatSocketListener(bot, config)).start();
}
bot.startBot();
System.out.println("Shutting down");
System.exit(0);