<commit_before>#include "plugin.h"
#include "bot.h"
#include "events.h"
#include <algorithm>
#include <functional>
#include "admin.h"
#include <iostream>

void AdminPlugin::init(PluginHost *h)
{
	using namespace std::placeholders;
	Bot *b = (Bot*)h;
	b->add_handler("command/load", "admin", std::bind(&AdminPlugin::load, this, _1));
	b->add_handler("command/unload", "admin", std::bind(&AdminPlugin::unload, this, _1));
	b->add_handler("command/perm", "admin", std::bind(&AdminPlugin::permissions, this, _1));
	b->add_handler("command/perms", "admin", std::bind(&AdminPlugin::permissions, this, _1));
	b->add_handler("command/group", "admin", std::bind(&AdminPlugin::group, this, _1));
	b->add_handler("command/save", "admin", std::bind(&AdminPlugin::save, this, _1));
	b->add_handler("command/config", "admin", std::bind(&AdminPlugin::config, this, _1));
	bot = b;
}

void AdminPlugin::deinit(PluginHost *h)
{
	bot->remove_handler("command/load", "admin");
	bot->remove_handler("command/unload", "admin");
	bot->remove_handler("command/perm", "admin");
	bot->remove_handler("command/perms", "admin");
	bot->remove_handler("command/group", "admin");
	bot->remove_handler("command/save", "admin");
	bot->remove_handler("command/config", "admin");
}

std::string AdminPlugin::name()
{
	return "admin";
}

bool AdminPlugin::load(Event *e)
{
	IRCCommandEvent *ev = reinterpret_cast<IRCCommandEvent*>(e);
	Plugin *p = NULL;

	if((p = bot->load_plugin(ev->params[0])))
	{
		p->init(bot);
		bot->conn->send_privmsg(ev->target, "Loaded plugin " + ev->params[0]);
	}

	return true;
}

bool AdminPlugin::unload(Event *e)
{
	IRCCommandEvent *ev = reinterpret_cast<IRCCommandEvent*>(e);
	if(bot->unload_plugin(ev->params[0]))
	{
		bot->conn->send_privmsg(ev->target, "Unloaded plugin " + ev->params[0]);
	}

	return true;
}

bool AdminPlugin::save(Event *e)
{
	IRCCommandEvent *ev = reinterpret_cast<IRCCommandEvent*>(e);
	bot->config->save();<commit_msg>Load with no arguments - fixes crash<commit_after>#include "plugin.h"
#include "bot.h"
#include "events.h"
#include <algorithm>
#include <functional>
#include "admin.h"
#include <iostream>

void AdminPlugin::init(PluginHost *h)
{
	using namespace std::placeholders;
	Bot *b = (Bot*)h;
	b->add_handler("command/load", "admin", std::bind(&AdminPlugin::load, this, _1));
	b->add_handler("command/unload", "admin", std::bind(&AdminPlugin::unload, this, _1));
	b->add_handler("command/perm", "admin", std::bind(&AdminPlugin::permissions, this, _1));
	b->add_handler("command/perms", "admin", std::bind(&AdminPlugin::permissions, this, _1));
	b->add_handler("command/group", "admin", std::bind(&AdminPlugin::group, this, _1));
	b->add_handler("command/save", "admin", std::bind(&AdminPlugin::save, this, _1));
	b->add_handler("command/config", "admin", std::bind(&AdminPlugin::config, this, _1));
	bot = b;
}

void AdminPlugin::deinit(PluginHost *h)
{
	bot->remove_handler("command/load", "admin");
	bot->remove_handler("command/unload", "admin");
	bot->remove_handler("command/perm", "admin");
	bot->remove_handler("command/perms", "admin");
	bot->remove_handler("command/group", "admin");
	bot->remove_handler("command/save", "admin");
	bot->remove_handler("command/config", "admin");
}

std::string AdminPlugin::name()
{
	return "admin";
}

bool AdminPlugin::load(Event *e)
{
	IRCCommandEvent *ev = reinterpret_cast<IRCCommandEvent*>(e);
	Plugin *p = NULL;

	if (ev->params.size() == 0)
	{
		bot->conn->send_privmsg(ev->target, "Usage: load [plugin path]");
		return true;
	}

	if((p = bot->load_plugin(ev->params[0])))
	{
		p->init(bot);
		bot->conn->send_privmsg(ev->target, "Loaded plugin " + ev->params[0]);
	}

	return true;
}

bool AdminPlugin::unload(Event *e)
{
	IRCCommandEvent *ev = reinterpret_cast<IRCCommandEvent*>(e);
	if(bot->unload_plugin(ev->params[0]))
	{
		bot->conn->send_privmsg(ev->target, "Unloaded plugin " + ev->params[0]);
	}

	return true;
}

bool AdminPlugin::save(Event *e)
{
	IRCCommandEvent *ev = reinterpret_cast<IRCCommandEvent*>(e);
	bot->config->save();
{'fraction_non_alphanumeric': 0.21052631578947367, 'fraction_numerical': 0.0057100297914597815, 'mean_word_length': 6.931102362204724, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 77, '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': '5849206', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1452, 'n_words': 252}