<commit_before>/**
 * Copyright (c) <NAME>, 2011-2012
 * See LICENSE for license.
 */

#include <QtCore/QList>
#include <QtCore/QDebug>
#include <QtCore/QCoreApplication>

#include "karmaplugin.h"

int main(int argc, char *argv[]) {
	if(argc < 2) {
		qWarning() << "Usage: dazeus-plugin-karma socketfile";
		return 1;
	}
	QString socketfile = argv[1];
	QCoreApplication app(argc, argv);
	KarmaPlugin kp(socketfile);
	return app.exec();
}

KarmaPlugin::KarmaPlugin(const QString &socketfile)
: QObject()
, d(new DaZeus())
{
	d->open(socketfile);
	d->subscribe("MESSAGE");
	connect(d,    SIGNAL(newEvent(DaZeus::Event*)),
	        this, SLOT(  newEvent(DaZeus::Event*)));
}

KarmaPlugin::~KarmaPlugin() {
	delete d;
}

int KarmaPlugin::modifyKarma(const QString &network, const QString &object, bool increase) {
	DaZeus::Scope s = DaZeus::Scope::Scope(network);
	QString qualifiedName = QLatin1String("perl.DazKarma.karma_") + object;
	int current = d->getProperty(qualifiedName, s).toInt();

	if(increase)
		++current;
	else	--current;

	if(current == 0) {
		d->unsetProperty(qualifiedName, s);
		// Also unset global property, in case one is left behind
		d->unsetProperty(qualifiedName, DaZeus::Scope::Scope());
	} else {
		d->setProperty(qualifiedName, QString::number(current), s);
	}

	return current;
}

void KarmaPlugin::newEvent(DaZeus::Event *e) {
	if(e->event != "MESSAGE") return;
	if(e->parameters.size() < 4) {
		qWarning() << "Incorrect parameter size for message received";
		return;
	}
	QString network = e->parameters[0];
	QString origin  = e->parameters[1];
	QString recv    = e->parameters[2];
	QString message = e->parameters[3];
	DaZeus::Scope s = DaZeus::Scope::Scope(network);
	// TODO: use getNick()
	if(!recv.startsWith('#')) {
		// reply to PM
		recv = origin;<commit_msg>Renamed MESSAGE event to PRIVMSG<commit_after>/**
 * Copyright (c) <NAME>, 2011-2012
 * See LICENSE for license.
 */

#include <QtCore/QList>
#include <QtCore/QDebug>
#include <QtCore/QCoreApplication>

#include "karmaplugin.h"

int main(int argc, char *argv[]) {
	if(argc < 2) {
		qWarning() << "Usage: dazeus-plugin-karma socketfile";
		return 1;
	}
	QString socketfile = argv[1];
	QCoreApplication app(argc, argv);
	KarmaPlugin kp(socketfile);
	return app.exec();
}

KarmaPlugin::KarmaPlugin(const QString &socketfile)
: QObject()
, d(new DaZeus())
{
	d->open(socketfile);
	d->subscribe("PRIVMSG");
	connect(d,    SIGNAL(newEvent(DaZeus::Event*)),
	        this, SLOT(  newEvent(DaZeus::Event*)));
}

KarmaPlugin::~KarmaPlugin() {
	delete d;
}

int KarmaPlugin::modifyKarma(const QString &network, const QString &object, bool increase) {
	DaZeus::Scope s = DaZeus::Scope::Scope(network);
	QString qualifiedName = QLatin1String("perl.DazKarma.karma_") + object;
	int current = d->getProperty(qualifiedName, s).toInt();

	if(increase)
		++current;
	else	--current;

	if(current == 0) {
		d->unsetProperty(qualifiedName, s);
		// Also unset global property, in case one is left behind
		d->unsetProperty(qualifiedName, DaZeus::Scope::Scope());
	} else {
		d->setProperty(qualifiedName, QString::number(current), s);
	}

	return current;
}

void KarmaPlugin::newEvent(DaZeus::Event *e) {
	if(e->event != "PRIVMSG") return;
	if(e->parameters.size() < 4) {
		qWarning() << "Incorrect parameter size for message received";
		return;
	}
	QString network = e->parameters[0];
	QString origin  = e->parameters[1];
	QString recv    = e->parameters[2];
	QString message = e->parameters[3];
	DaZeus::Scope s = DaZeus::Scope::Scope(network);
	// TODO: use getNick()
	if(!recv.startsWith('#')) {
		// reply to PM
		recv = origin;
{'fraction_non_alphanumeric': 0.16772765015222807, 'fraction_numerical': 0.00996401882092444, 'mean_word_length': 4.953871499176277, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 35, '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': '1596643', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1298, 'n_words': 287}