<commit_before>package plugins

import (
	"runtime"
	"time"

	"github.com/belak/irc"
	"github.com/belak/seabird/bot"
	"github.com/belak/seabird/mux"
)

func init() {
	bot.RegisterPlugin("ctcp", NewCTCPPlugin)
}

type CTCPPlugin struct{}

func NewCTCPPlugin(m *mux.CTCPMux) error {
	p := &CTCPPlugin{}

	m.Event("TIME", p.Time)
	m.Event("PING", p.Ping)
	m.Event("VERSION", p.Version)

	return nil
}

func (p *CTCPPlugin) Time(c *irc.Client, e *irc.Event) {
	t := time.Now().Format("Mon 2 Jan 2006 15:04:05 MST")
	c.CTCPReply(e, "TIME %s", t)
}

func (p *CTCPPlugin) Ping(c *irc.Client, e *irc.Event) {
	c.CTCPReply(e, "PING %s", e.Trailing())
}

func (p *CTCPPlugin) Version(c *irc.Client, e *irc.Event) {
	c.CTCPReply(e, "VERSION belak/seabird [%s %s %s]",
		runtime.GOOS, runtime.GOARCH, runtime.Version())
}<commit_msg>Add git hash to ctcp version if explicitly enabled<commit_after>package plugins

import (
	"bytes"
	"os/exec"
	"runtime"
	"time"

	"github.com/belak/irc"
	"github.com/belak/seabird/bot"
	"github.com/belak/seabird/mux"
)

func init() {
	bot.RegisterPlugin("ctcp", NewCTCPPlugin)
}

type CTCPPlugin struct {
	EnableGit bool
}

func NewCTCPPlugin(b *bot.Bot, m *mux.CTCPMux) error {
	p := &CTCPPlugin{}

	// NOTE: We ignore the error because ctcp config is optional
	b.Config("ctcp", p)

	m.Event("TIME", p.Time)
	m.Event("PING", p.Ping)
	m.Event("VERSION", p.Version)

	return nil
}

func (p *CTCPPlugin) Time(c *irc.Client, e *irc.Event) {
	t := time.Now().Format("Mon 2 Jan 2006 15:04:05 MST")
	c.CTCPReply(e, "TIME %s", t)
}

func (p *CTCPPlugin) Ping(c *irc.Client, e *irc.Event) {
	c.CTCPReply(e, "PING %s", e.Trailing())
}

func (p *CTCPPlugin) Version(c *irc.Client, e *irc.Event) {
	if p.EnableGit {
		out, err := exec.Command("git", "rev-parse", "--short", "HEAD").Output()
		if err != nil {
			c.CTCPReply(e, "VERSION Error running git: %s", err)
			return
		}

		c.CTCPReply(e, "VERSION belak/seabird [%s %s %s] %s",
			runtime.GOOS, runtime.GOARCH, runtime.Version(), string(bytes.TrimSpace(out)))
	} else {
		c.CTCPReply(e, "VERSION belak/seabird [%s %s %s]",
			runtime.GOOS, runtime.GOARCH, runtime.Version())
	}
}
{'fraction_non_alphanumeric': 0.1857541899441341, 'fraction_numerical': 0.010242085661080074, 'mean_word_length': 4.190821256038648, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3986942', 'n_tokens_mistral': 961, 'n_tokens_neox': 906, 'n_words': 205}