<commit_before>package plugins

import (
	"encoding/json"
	"regexp"
	"strings"

	"../../seabird"
	"github.com/thoj/go-ircevent"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
)

func init() {
	seabird.RegisterPlugin("karma", NewKarmaPlugin)
}

type Karma struct {
	Name  string `bson:"name"`
	Score int    `bson:"score"`
}

type KarmaPlugin struct {
	Bot *seabird.Bot
	C   *mgo.Collection
}

var regex = regexp.MustCompile(`((?:\w+[\+-]?)*\w)(\+\+|--)(?:\s|$)`)

func NewKarmaPlugin(b *seabird.Bot, c json.RawMessage) {
	p := &KarmaPlugin{b, b.DB.C("karma")}
	b.RegisterFunction("karma", p.Karma)
	b.RegisterCallback("PRIVMSG", p.Msg)
}

func (p *KarmaPlugin) GetKarmaFor(name string) *Karma {
	name = strings.ToLower(name)
	k := &Karma{}
	err := p.C.Find(bson.M{"name": name}).One(k)
	if err != nil {
		return &Karma{Name: name}
	}

	return k
}

func (p *KarmaPlugin) Karma(e *irc.Event) {
	p.Bot.MentionReply(e, "%s's karma is %d", e.Message(), p.GetKarmaFor(e.Message()).Score)
}

func (p *KarmaPlugin) Msg(e *irc.Event) {
	matches := regex.FindAllStringSubmatch(e.Message(), -1)
	if len(matches) > 0 && !p.Bot.Auth.UserCan(p.Bot.GetUser(e.Nick), "karma.deny") {
		for _, v := range matches {
			if len(v) < 3 {
				continue
			}

			var diff int
			if v[2] == "++" {
				diff = 1
			} else {
				diff = -1
			}

			name := strings.ToLower(v[1])
			p.C.Upsert(bson.M{"name": name}, bson.M{"$inc": bson.M{"score": diff}})
			p.Bot.Reply(e, "%s's karma is now %d", v[1], p.GetKarmaFor(name).Score)
		}
	}
}
<commit_msg>old changes to karma<commit_after>package plugins

import (
	"encoding/json"
	"regexp"
	"strings"

	"../../seabird"
	"github.com/thoj/go-ircevent"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
)

func init() {
	seabird.RegisterPlugin("karma", NewKarmaPlugin)
}

type Karma struct {
	Name  string `bson:"name"`
	Score int    `bson:"score"`
}

type KarmaPlugin struct {
	Bot *seabird.Bot
	C   *mgo.Collection
}

var regex = regexp.MustCompile(`((?:\w+[\+-]?)*\w)(\+\+|--)(?:\s|$)`)

func NewKarmaPlugin(b *seabird.Bot, c json.RawMessage) {
	p := &KarmaPlugin{b, b.DB.C("karma")}
	b.RegisterFunction("karma", p.Karma)
	b.RegisterCallback("PRIVMSG", p.Msg)
}

func (p *KarmaPlugin) GetKarmaFor(name string) *Karma {
	name = strings.Trim(strings.ToLower(name))
	k := &Karma{}
	err := p.C.Find(bson.M{"name": name}).One(k)
	if err != nil {
		return &Karma{Name: name}
	}

	return k
}

func (p *KarmaPlugin) Karma(e *irc.Event) {
	p.Bot.MentionReply(e, "%s's karma is %d", e.Message(), p.GetKarmaFor(e.Message()).Score)
}

func (p *KarmaPlugin) Msg(e *irc.Event) {
	matches := regex.FindAllStringSubmatch(e.Message(), -1)
	if len(matches) > 0 && !p.Bot.Auth.UserCan(p.Bot.GetUser(e.Nick), "karma.deny") {
		for _, v := range matches {
			if len(v) < 3 {
				continue
			}

			var diff int
			if v[2] == "++" {
				diff = 1
			} else {
				diff = -1
			}

			name := strings.ToLower(v[1])
			p.C.Upsert(bson.M{"name": name}, bson.M{"$inc": bson.M{"score": diff}})
			p.Bot.Reply(e, "%s's karma is now %d", v[1], p.GetKarmaFor(name).Score)
		}
	}
}

{'fraction_non_alphanumeric': 0.21229964017010142, 'fraction_numerical': 0.006542361792607131, 'mean_word_length': 3.5847076461769114, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, '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': '4845533', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1340, 'n_words': 251}