<commit_before>#include <iostream>

#include <basedefs.h>
#include <pluginmanager.h>
//#include <core_api_cpp.h>
//#include <core_frontend.h>
#include <networkmanager_frontend.h>
#include <networkmanager_api_cpp.h>
#include <networkcache_userinterface.h>
#include <channelcache.h>
#include <unistd.h> // for Sleep
#include <string.h>
#include <sstream>
#include <log.h>
#include <fstream>

static pthread_mutex_t g_stateMutex;
static anp::uint32 g_state = 0;
using namespace anp;
using namespace firc;

class LogFileWriter: public ILogInterface
{
public:
	LogFileWriter(const std::string &filename):
	m_filename(filename)
	{
	}
	void present(const anp::dstring &message)
	{
		std::ofstream fout(m_filename.c_str(),
							std::ios_base::app | std::ios_base::out);
		if ( fout.is_open() )
		{
			fout << message << std::endl;
			fout.close();
		}
	}
private:
	std::string m_filename;
};

void irc_onPrivMsg(INetworkManagerFrontend &network,
					const anp::int8 *sender,
					const anp::int8 *receiver,
					const anp::int8 *message)
{
	std::cout << "main.cpp: Received a PRIVMSG!" << std::endl;


	if ( 0 == strcmp(message, "die") )
	{
		// Write state
		pthread_mutex_lock(&g_stateMutex);
		g_state = 1; // QUIT
		pthread_mutex_unlock(&g_stateMutex);
	}

	if ( receiver[0] == '#' )
	{
		const NetworkCacheUserInterface &cache = network.networkCache();
		ChannelCache channel;
		cache.getChannel(receiver, channel);
	
		std::stringstream ss;
		ss << "PRIVMSG " << channel.name() << " :The topic for "
			<< channel.name() << " is " << channel.topic() << ".\r\n";
		network.sendMessage(ss.str());
	}
}

int main(int argc, char *argv[])
{
	using namespace anp;
	using namespace anp::firc;
	
	const int8 *pluginNames[] = {
	//	"./libpluginTest1.so"
	};

	LogFileWriter logFileWriter("frontend_cpp.log");
	Log log;
	log.addLogInterface(&logFileWriter);
	log.addMessage("Log initialized.");
	
	pthread_mutex_init(&g_stateMutex, NULL);

	PluginManager pluginManager;
	
	for ( uint32 i=0; i<sizeof(pluginNames)/sizeof(pluginNames[0]);
			i++ )
	{
		pluginManager.loadPlugin(pluginNames[i]);
	}
	
	INetworkManagerFrontend *chatJunkies =
		networkmanager_create("irc.chatjunkies.org", "6667",
												&pluginManager);

	
	anp::uint32 state = 0;
	pluginManager.addCallbackOnPrivMsg(irc_onPrivMsg);

	sleep(9);
	chatJunkies->sendMessage("JOIN #my-secret-botdev\r\n");
	chatJunkies->sendMessage(
					"PRIVMSG #my-secret-botdev :Hello world!\r\n");
	sleep(20);
	<commit_msg>frontend_console_cpp accepts server and port args.<commit_after>#include <iostream>

#include <basedefs.h>
#include <pluginmanager.h>
//#include <core_api_cpp.h>
//#include <core_frontend.h>
#include <networkmanager_frontend.h>
#include <networkmanager_api_cpp.h>
#include <networkcache_userinterface.h>
#include <channelcache.h>
#include <unistd.h> // for Sleep
#include <string.h>
#include <sstream>
#include <log.h>
#include <fstream>

static pthread_mutex_t g_stateMutex;
static anp::uint32 g_state = 0;
using namespace anp;
using namespace firc;

class LogFileWriter: public ILogInterface
{
public:
	LogFileWriter(const std::string &filename):
	m_filename(filename)
	{
	}
	void present(const anp::dstring &message)
	{
		std::ofstream fout(m_filename.c_str(),
							std::ios_base::app | std::ios_base::out);
		if ( fout.is_open() )
		{
			fout << message << std::endl;
			fout.close();
		}
	}
private:
	std::string m_filename;
};

void irc_onPrivMsg(INetworkManagerFrontend &network,
					const anp::int8 *sender,
					const anp::int8 *receiver,
					const anp::int8 *message)
{
	std::cout << "main.cpp: Received a PRIVMSG!" << std::endl;


	if ( 0 == strcmp(message, "die") )
	{
		// Write state
		pthread_mutex_lock(&g_stateMutex);
		g_state = 1; // QUIT
		pthread_mutex_unlock(&g_stateMutex);
	}

	if ( receiver[0] == '#' )
	{
		const NetworkCacheUserInterface &cache = network.networkCache();
		ChannelCache channel;
		cache.getChannel(receiver, channel);
	
		std::stringstream ss;
		ss << "PRIVMSG " << channel.name() << " :The topic for "
			<< channel.name() << " is " << channel.topic() << ".\r\n";
		network.sendMessage(ss.str());
	}
}

int main(int argc, char *argv[])
{
	using namespace anp;
	using namespace anp::firc;
	
	std::string serverAddress = "irc.chatjunkies.org",
				serverPort = "6667";

	if ( argc >= 3 )
	{
		serverAddress = argv[1];
		serverPort = argv[2];
	}

	const int8 *pluginNames[] = {
	//	"./libpluginTest1.so"
	};

	LogFileWriter logFileWriter("frontend_cpp.log");
	Log log;
	log.addLogInterface(&logFileWriter);
	log.addMessage("Log initialized.");
	
	pthread_mutex_init(&g_stateMutex, NULL);

	PluginManager pluginManager;
	
	for ( uint32 i=0; i<sizeof(pluginNames)/sizeof(pluginNames[0]);
			i++ )
	{
		pluginManager.loadPlugin(pluginNames[i]);
	}
	
	INetworkManagerFrontend *chatJunkies =
		networkmanager_create(serverAddress.c_str(), serverPort.c_str(),
													&pluginManager);

	
	anp::uint32 state = 0;
	pluginManager.addCallbackOnPrivMsg(irc_onPrivMsg);

	sleep(9);
	chatJunkies->sendMessage("JOIN #my-secret-botdev\r\n");
	chatJunkies->sendMessage(
					"PRIVMSG #my-secret-botdev :Hello world!\r\n");
	sleep(20);
	
{'fraction_non_alphanumeric': 0.15440031152647976, 'fraction_numerical': 0.010319314641744548, 'mean_word_length': 4.663726571113561, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 36, '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': '4618238', 'n_tokens_mistral': 2062, 'n_tokens_neox': 1887, 'n_words': 359}