<commit_before>#include "websocketpp_websocket.h"
#ifndef NONEXISTENT_WEBSOCKETPP

namespace SleepyDiscord {

	WebsocketppDiscordClient::WebsocketppDiscordClient(const std::string token, const char numOfThreads) :
		_thread(nullptr), maxNumOfThreads(numOfThreads)
	{
		init();
		start(token, numOfThreads);
	}

	WebsocketppDiscordClient::~WebsocketppDiscordClient() {
		if (_thread != nullptr && _thread->joinable()) _thread->join();
		else _thread.reset();
	}

	void WebsocketppDiscordClient::init() {
		// set up access channels to only log interesting things
		this_client.clear_access_channels(websocketpp::log::alevel::all);
		this_client.set_access_channels(websocketpp::log::alevel::connect);
		this_client.set_access_channels(websocketpp::log::alevel::disconnect);
		this_client.set_access_channels(websocketpp::log::alevel::app);

		this_client.set_tls_init_handler([this](websocketpp::connection_hdl) {
			return websocketpp::lib::make_shared<asio::ssl::context>(asio::ssl::context::tlsv1);
		});

		// Initialize the Asio transport policy
		this_client.init_asio();

		this_client.set_message_handler(std::bind(&WebsocketppDiscordClient::onMessage, this, websocketpp::lib::placeholders::_1, websocketpp::lib::placeholders::_2));
		
		this_client.set_close_handler(std::bind(&WebsocketppDiscordClient::onClose, this,
			websocketpp::lib::placeholders::_1));

		this_client.set_fail_handler(std::bind(&WebsocketppDiscordClient::onFail, this,
			websocketpp::lib::placeholders::_1));
	}

	bool WebsocketppDiscordClient::connect(const std::string & uri) {
		// Create a new connection to the given URI
		websocketpp::lib::error_code ec;
		// Note: there's might be a memory leak caused by get_connection
		_client::connection_ptr con = this_client.get_connection(uri, ec);

		if (ec) {
			onError(GENERAL_ERROR, "Connect initialization: " + ec.message());
			return false;
		}
		// Grab a handle for this connection so we can talk to it in a thread 
		// safe manor after the event loop starts.
		handle = con->get_handle();

		// Queue the connection. No DNS queries or network connections will be
		// made until the io_service event loop is run.
		this_client.connect(con);
		return true;
	}

	void WebsocketppDiscordClient::run() {
		do {
			this_client.run();
		} while (!isQuiting());
	}

	void handleTimers(const websocketpp::lib::error_code &ec, std::function<void()>& code) {
		if (ec == websocketpp::transport::error::operation_aborted) return;
		else code();
	}

	Timer WebsocketppDiscordClient::schedule(std::function<void()> code, const time_t milliseconds) {<commit_msg>Slight typo fix to comment<commit_after>#include "websocketpp_websocket.h"
#ifndef NONEXISTENT_WEBSOCKETPP

namespace SleepyDiscord {

	WebsocketppDiscordClient::WebsocketppDiscordClient(const std::string token, const char numOfThreads) :
		_thread(nullptr), maxNumOfThreads(numOfThreads)
	{
		init();
		start(token, numOfThreads);
	}

	WebsocketppDiscordClient::~WebsocketppDiscordClient() {
		if (_thread != nullptr && _thread->joinable()) _thread->join();
		else _thread.reset();
	}

	void WebsocketppDiscordClient::init() {
		// set up access channels to only log interesting things
		this_client.clear_access_channels(websocketpp::log::alevel::all);
		this_client.set_access_channels(websocketpp::log::alevel::connect);
		this_client.set_access_channels(websocketpp::log::alevel::disconnect);
		this_client.set_access_channels(websocketpp::log::alevel::app);

		this_client.set_tls_init_handler([this](websocketpp::connection_hdl) {
			return websocketpp::lib::make_shared<asio::ssl::context>(asio::ssl::context::tlsv1);
		});

		// Initialize the Asio transport policy
		this_client.init_asio();

		this_client.set_message_handler(std::bind(&WebsocketppDiscordClient::onMessage, this, websocketpp::lib::placeholders::_1, websocketpp::lib::placeholders::_2));
		
		this_client.set_close_handler(std::bind(&WebsocketppDiscordClient::onClose, this,
			websocketpp::lib::placeholders::_1));

		this_client.set_fail_handler(std::bind(&WebsocketppDiscordClient::onFail, this,
			websocketpp::lib::placeholders::_1));
	}

	bool WebsocketppDiscordClient::connect(const std::string & uri) {
		// Create a new connection to the given URI
		websocketpp::lib::error_code ec;
		// Note: there might be a memory leak caused by get_connection
		_client::connection_ptr con = this_client.get_connection(uri, ec);

		if (ec) {
			onError(GENERAL_ERROR, "Connect initialization: " + ec.message());
			return false;
		}
		// Grab a handle for this connection so we can talk to it in a thread 
		// safe manor after the event loop starts.
		handle = con->get_handle();

		// Queue the connection. No DNS queries or network connections will be
		// made until the io_service event loop is run.
		this_client.connect(con);
		return true;
	}

	void WebsocketppDiscordClient::run() {
		do {
			this_client.run();
		} while (!isQuiting());
	}

	void handleTimers(const websocketpp::lib::error_code &ec, std::function<void()>& code) {
		if (ec == websocketpp::transport::error::operation_aborted) return;
		else code();
	}

	Timer WebsocketppDiscordClient::schedule(std::function<void()> code, const time_t milliseconds) {
{'fraction_non_alphanumeric': 0.12805699980743307, 'fraction_numerical': 0.0019256691700365878, 'mean_word_length': 6.244072524407253, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '6706718', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1675, 'n_words': 334}