<commit_before>package extra

import (
	"fmt"
	"strings"
	"time"

	"github.com/go-xorm/xorm"

	seabird "github.com/belak/go-seabird"
	irc "github.com/go-irc/irc/v2"
)

func init() {
	seabird.RegisterPlugin("lastseen", newLastSeenPlugin)
}

type lastSeenPlugin struct {
	db *xorm.Engine
}

// LastSeen is the xorm model for the lastseen plugin
type LastSeen struct {
	ID      int64
	Channel string
	Nick    string
	Time    time.Time
}

func newLastSeenPlugin(m *seabird.BasicMux, cm *seabird.CommandMux, db *xorm.Engine) error {
	p := &lastSeenPlugin{db: db}

	err := p.db.Sync(LastSeen{})
	if err != nil {
		return err
	}

	cm.Event("active", p.activeCallback, &seabird.HelpInfo{
		Usage:       "<nick>",
		Description: "Reports the last time user was seen",
	})

	m.Event("PRIVMSG", p.msgCallback)

	return nil
}

func (p *lastSeenPlugin) activeCallback(b *seabird.Bot, m *irc.Message) {
	nick := m.Trailing()
	if nick == "" {
		b.MentionReply(m, "Nick required")
		return
	}

	channel := m.Params[0]

	b.MentionReply(m, "%s", p.getLastSeen(nick, channel))
}

func (p *lastSeenPlugin) getLastSeen(rawNick, rawChannel string) string {
	search := LastSeen{
		Channel: strings.ToLower(rawChannel),
		Nick:    strings.ToLower(rawNick),
	}

	_, err := p.db.Get(&search)
	if err != nil {
		return rawNick + " has not been seen in" + rawChannel
	}

	return rawNick + " was last active on " + formatDate(search.Time) + " at " + formatTime(search.Time)
}
<commit_msg>lastseen: fix not found check<commit_after>package extra

import (
	"fmt"
	"strings"
	"time"

	"github.com/go-xorm/xorm"

	seabird "github.com/belak/go-seabird"
	irc "github.com/go-irc/irc/v2"
)

func init() {
	seabird.RegisterPlugin("lastseen", newLastSeenPlugin)
}

type lastSeenPlugin struct {
	db *xorm.Engine
}

// LastSeen is the xorm model for the lastseen plugin
type LastSeen struct {
	ID      int64
	Channel string
	Nick    string
	Time    time.Time
}

func newLastSeenPlugin(m *seabird.BasicMux, cm *seabird.CommandMux, db *xorm.Engine) error {
	p := &lastSeenPlugin{db: db}

	err := p.db.Sync(LastSeen{})
	if err != nil {
		return err
	}

	cm.Event("active", p.activeCallback, &seabird.HelpInfo{
		Usage:       "<nick>",
		Description: "Reports the last time user was seen",
	})

	m.Event("PRIVMSG", p.msgCallback)

	return nil
}

func (p *lastSeenPlugin) activeCallback(b *seabird.Bot, m *irc.Message) {
	nick := m.Trailing()
	if nick == "" {
		b.MentionReply(m, "Nick required")
		return
	}

	channel := m.Params[0]

	b.MentionReply(m, "%s", p.getLastSeen(nick, channel))
}

func (p *lastSeenPlugin) getLastSeen(rawNick, rawChannel string) string {
	search := LastSeen{
		Channel: strings.ToLower(rawChannel),
		Nick:    strings.ToLower(rawNick),
	}

	found, err := p.db.Get(&search)
	if err != nil || !found {
		return rawNick + " has not been seen in" + rawChannel
	}

	return rawNick + " was last active on " + formatDate(search.Time) + " at " + formatTime(search.Time)
}

{'fraction_non_alphanumeric': 0.14111261872455902, 'fraction_numerical': 0.0027137042062415195, 'mean_word_length': 3.8423645320197046, 'pattern_counts': {'":': 0, '<': 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': '2455570', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1126, 'n_words': 268}