<commit_before>/*
 * Choob.java
 *
 * Created on June 1, 2005, 2:22 AM
 */

/**
 *
 * @author	sadiq
 */

package uk.co.uwcs.choob;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.PircBot;

import uk.co.uwcs.choob.modules.Modules;
import uk.co.uwcs.choob.support.ChoobError;
import uk.co.uwcs.choob.support.ChoobProtectionDomain;
import uk.co.uwcs.choob.support.ConfigReader;
import uk.co.uwcs.choob.support.DbConnectionBroker;
import uk.co.uwcs.choob.support.IRCInterface;
import uk.co.uwcs.choob.support.Interval;
import uk.co.uwcs.choob.support.events.ChannelAction;
import uk.co.uwcs.choob.support.events.ChannelInfo;
import uk.co.uwcs.choob.support.events.ChannelInvite;
import uk.co.uwcs.choob.support.events.ChannelJoin;
import uk.co.uwcs.choob.support.events.ChannelKick;
import uk.co.uwcs.choob.support.events.ChannelMessage;
import uk.co.uwcs.choob.support.events.ChannelMode;
import uk.co.uwcs.choob.support.events.ChannelModes;
import uk.co.uwcs.choob.support.events.ChannelNotice;
import uk.co.uwcs.choob.support.events.ChannelParamMode;
import uk.co.uwcs.choob.support.events.ChannelPart;
import uk.co.uwcs.choob.support.events.ChannelTopic;
import uk.co.uwcs.choob.support.events.ChannelUserMode;
import uk.co.uwcs.choob.support.events.Event;
import uk.co.uwcs.choob.support.events.IRCEvent;
import uk.co.uwcs.choob.support.events.Message;
import uk.co.uwcs.choob.support.events.NickChange;
import uk.co.uwcs.choob.support.events.PluginLoaded;
import uk.co.uwcs.choob.support.events.PluginReLoaded;
import uk.co.uwcs.choob.support.events.PluginUnLoaded;
import uk.co.uwcs.choob.support.events.PrivateAction;
import uk.co.uwcs.choob.support.events.PrivateMessage;
import uk.co.uwcs.choob.support.events.PrivateNotice;
import uk.co.uwcs.choob.support.events.QuitEvent;
import uk.co.uwcs.choob.support.events.ServerResponse;
import uk.co.uwcs.choob.support.events.UnknownEvent;
import uk.co.uwcs.choob.support.events.UserModes;

/**
 * Core class of the Choob bot, main interaction with IRC.
 */
public final class Choob extends PircBot
{
	private DbConnectionBroker broker;
	private Modules modules;
	private IRCInterface irc;
	private String trigger;
	private List <Interval> intervalList;
	private ChoobWatcherThread watcher;

	private ConfigReader conf;
	private int exitCode;
	private int messageLimit;
	/**
	 * Constructor for Choob, initialises vital variables.
	 */
	Choob() throws ChoobError
	{

		try
		{
			conf=new ConfigReader("bot.conf");
		}
		catch (final IOException e)
		{
			e.printStackTrace();
			System.out.println("\n\nError reading config file, exiting.");
			System.exit(2);
			return;
		}

		trigger = conf.getSettingFallback("botTrigger","~");

		messageLimit = Integer.valueOf(conf.getSettingFallback("messageLimit","0"));
		if (messageLimit < 0)
			messageLimit = 0;

		// Create a shiny synchronised (americans--) list
		intervalList = new ArrayList<Interval>();

		// Create a new database connection broker using the MySQL drivers
		PrintWriter logFile;
		try
		{
			logFile=new PrintWriter(new FileOutputStream("./tmp/db.log"));
		}
		catch (final IOException e)
		{
			e.printStackTrace();
			System.out.println("Cannot create db log, exiting.");
			System.exit(6);
			return;
		}
		try
		{
			broker = new DbConnectionBroker("com.mysql.jdbc.Driver", "jdbc:mysql://"
					+ conf.getSettingFallback("dbServer","localhost")
					+ "/" + conf.getSettingFallback("database","choob") + "?autoReconnect=true&"
					+ "autoReconnectForPools=true&initialTimeout=1&"
					+ "useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8",
						conf.getSettingFallback("dbUser","choob"), conf.getSettingFallback("dbPass",""), 10, 20, logFile, 60);
		}
		catch (final SQLException e)
		{<commit_msg>Create temp directory if it doesn't exist<commit_after>/*
 * Choob.java
 *
 * Created on June 1, 2005, 2:22 AM
 */

/**
 *
 * @author	sadiq
 */

package uk.co.uwcs.choob;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.PircBot;

import uk.co.uwcs.choob.modules.Modules;
import uk.co.uwcs.choob.support.ChoobError;
import uk.co.uwcs.choob.support.ChoobProtectionDomain;
import uk.co.uwcs.choob.support.ConfigReader;
import uk.co.uwcs.choob.support.DbConnectionBroker;
import uk.co.uwcs.choob.support.IRCInterface;
import uk.co.uwcs.choob.support.Interval;
import uk.co.uwcs.choob.support.events.ChannelAction;
import uk.co.uwcs.choob.support.events.ChannelInfo;
import uk.co.uwcs.choob.support.events.ChannelInvite;
import uk.co.uwcs.choob.support.events.ChannelJoin;
import uk.co.uwcs.choob.support.events.ChannelKick;
import uk.co.uwcs.choob.support.events.ChannelMessage;
import uk.co.uwcs.choob.support.events.ChannelMode;
import uk.co.uwcs.choob.support.events.ChannelModes;
import uk.co.uwcs.choob.support.events.ChannelNotice;
import uk.co.uwcs.choob.support.events.ChannelParamMode;
import uk.co.uwcs.choob.support.events.ChannelPart;
import uk.co.uwcs.choob.support.events.ChannelTopic;
import uk.co.uwcs.choob.support.events.ChannelUserMode;
import uk.co.uwcs.choob.support.events.Event;
import uk.co.uwcs.choob.support.events.IRCEvent;
import uk.co.uwcs.choob.support.events.Message;
import uk.co.uwcs.choob.support.events.NickChange;
import uk.co.uwcs.choob.support.events.PluginLoaded;
import uk.co.uwcs.choob.support.events.PluginReLoaded;
import uk.co.uwcs.choob.support.events.PluginUnLoaded;
import uk.co.uwcs.choob.support.events.PrivateAction;
import uk.co.uwcs.choob.support.events.PrivateMessage;
import uk.co.uwcs.choob.support.events.PrivateNotice;
import uk.co.uwcs.choob.support.events.QuitEvent;
import uk.co.uwcs.choob.support.events.ServerResponse;
import uk.co.uwcs.choob.support.events.UnknownEvent;
import uk.co.uwcs.choob.support.events.UserModes;

/**
 * Core class of the Choob bot, main interaction with IRC.
 */
public final class Choob extends PircBot
{
	private DbConnectionBroker broker;
	private Modules modules;
	private IRCInterface irc;
	private String trigger;
	private List <Interval> intervalList;
	private ChoobWatcherThread watcher;

	private ConfigReader conf;
	private int exitCode;
	private int messageLimit;
	/**
	 * Constructor for Choob, initialises vital variables.
	 */
	Choob() throws ChoobError
	{

		try
		{
			conf=new ConfigReader("bot.conf");
		}
		catch (final IOException e)
		{
			e.printStackTrace();
			System.out.println("\n\nError reading config file, exiting.");
			System.exit(2);
			return;
		}

		trigger = conf.getSettingFallback("botTrigger","~");

		messageLimit = Integer.valueOf(conf.getSettingFallback("messageLimit","0"));
		if (messageLimit < 0)
			messageLimit = 0;

		// Create a shiny synchronised (americans--) list
		intervalList = new ArrayList<Interval>();

		// Create a new database connection broker using the MySQL drivers
		PrintWriter logFile;
		try
		{
			final File logLocation = new File("./tmp/");
			logLocation.mkdirs();
			logFile=new PrintWriter(new FileOutputStream(logLocation.getPath() + "/db.log"));
		}
		catch (final IOException e)
		{
			e.printStackTrace();
			System.out.println("Cannot create db log, exiting.");
			System.exit(6);
			return;
		}
		try
		{
			broker = new DbConnectionBroker("com.mysql.jdbc.Driver", "jdbc:mysql://"
					+ conf.getSettingFallback("dbServer","localhost")
					+ "/" + conf.getSettingFallback("database","choob") + "?autoReconnect=true&"
					+ "autoReconnectForPools=true&initialTimeout=1&"
					+ "useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8",
						conf.getSettingFallback("dbUser","choob"), conf.getSettingFallback("dbPass",""), 10, 20, logFile, 60);
		}
		catch (final SQLException e)
		{
{'fraction_non_alphanumeric': 0.12979315350187492, 'fraction_numerical': 0.005322366033627676, 'mean_word_length': 4.769713886950454, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '3080592', 'n_tokens_mistral': 3017, 'n_tokens_neox': 2796, 'n_words': 493}