last: record more messages and figure the time out

This commit is contained in:
Chris Sexton 2024-03-26 14:13:59 -04:00
parent 654cf6ced0
commit a187ea363c
4 changed files with 31 additions and 4 deletions

View File

@ -68,7 +68,7 @@ func ParseValues(r *regexp.Regexp, body string) RegexValues {
func (b *bot) runCallback(conn Connector, plugin Plugin, evt Kind, message msg.Message, args ...any) bool { func (b *bot) runCallback(conn Connector, plugin Plugin, evt Kind, message msg.Message, args ...any) bool {
t := reflect.TypeOf(plugin).String() t := reflect.TypeOf(plugin).String()
for _, spec := range b.callbacks[t][evt] { req := func(spec HandlerSpec) bool {
if spec.Regex.MatchString(message.Body) { if spec.Regex.MatchString(message.Body) {
req := Request{ req := Request{
Conn: conn, Conn: conn,
@ -81,6 +81,17 @@ func (b *bot) runCallback(conn Connector, plugin Plugin, evt Kind, message msg.M
return true return true
} }
} }
return false
}
for _, spec := range b.callbacks[t][Any] {
if req(spec) {
return true
}
}
for _, spec := range b.callbacks[t][evt] {
if req(spec) {
return true
}
} }
return false return false
} }

View File

@ -19,6 +19,8 @@ import (
const ( const (
_ = iota _ = iota
// Any will be picked up by the matcher as generic
Any
// Message any standard chat // Message any standard chat
Message Message
// Ephemeral sends a disappearing message to a user in chat // Ephemeral sends a disappearing message to a user in chat

View File

@ -3,8 +3,9 @@ package gpt
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/andrewstuart/openai"
) )
import "github.com/andrewstuart/openai"
var session openai.ChatSession var session openai.ChatSession
var client *openai.Client var client *openai.Client

View File

@ -73,7 +73,7 @@ func (p *LastPlugin) register() {
Handler: p.whoKilledChannel, Handler: p.whoKilledChannel,
}, },
{ {
Kind: bot.Message, IsCmd: false, Kind: bot.Any, IsCmd: false,
Regex: regexp.MustCompile(`.*`), Regex: regexp.MustCompile(`.*`),
HelpText: "Last does secret stuff you don't need to know about.", HelpText: "Last does secret stuff you don't need to know about.",
Handler: p.recordLast, Handler: p.recordLast,
@ -192,7 +192,20 @@ func (p *LastPlugin) sayLast(c bot.Connector, chFrom, chTo string, force bool) {
} }
return return
} }
msg := fmt.Sprintf(`%s killed the channel last night`, l.Nick) timeOfDay := "last night"
hour := time.Unix(l.Time, 0).Hour()
if hour < 18 {
timeOfDay = "in the afternoon"
}
if hour < 12 {
timeOfDay = "in the morning"
}
log.Debug().
Str("timeOfDay", timeOfDay).
Int("hour", hour).
Int64("l.Time", l.Time).
Msgf("killed")
msg := fmt.Sprintf(`%s killed the channel %s`, l.Nick, timeOfDay)
guildID := p.c.Get("discord.guildid", "") guildID := p.c.Get("discord.guildid", "")
p.b.Send(c, bot.Message, chTo, msg, bot.MessageReference{ p.b.Send(c, bot.Message, chTo, msg, bot.MessageReference{
MessageID: l.MessageID, MessageID: l.MessageID,