diff --git a/bot/handlers.go b/bot/handlers.go index 69e39dd..a8ebc9b 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -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 { t := reflect.TypeOf(plugin).String() - for _, spec := range b.callbacks[t][evt] { + req := func(spec HandlerSpec) bool { if spec.Regex.MatchString(message.Body) { req := Request{ Conn: conn, @@ -81,6 +81,17 @@ func (b *bot) runCallback(conn Connector, plugin Plugin, evt Kind, message msg.M 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 } diff --git a/bot/interfaces.go b/bot/interfaces.go index 5409ef5..159d201 100644 --- a/bot/interfaces.go +++ b/bot/interfaces.go @@ -19,6 +19,8 @@ import ( const ( _ = iota + // Any will be picked up by the matcher as generic + Any // Message any standard chat Message // Ephemeral sends a disappearing message to a user in chat diff --git a/plugins/gpt/chatgpt.go b/plugins/gpt/chatgpt.go index b1bf551..10ba308 100644 --- a/plugins/gpt/chatgpt.go +++ b/plugins/gpt/chatgpt.go @@ -3,8 +3,9 @@ package gpt import ( "context" "fmt" + + "github.com/andrewstuart/openai" ) -import "github.com/andrewstuart/openai" var session openai.ChatSession var client *openai.Client diff --git a/plugins/last/last.go b/plugins/last/last.go index 6d91705..7c71646 100644 --- a/plugins/last/last.go +++ b/plugins/last/last.go @@ -73,7 +73,7 @@ func (p *LastPlugin) register() { Handler: p.whoKilledChannel, }, { - Kind: bot.Message, IsCmd: false, + Kind: bot.Any, IsCmd: false, Regex: regexp.MustCompile(`.*`), HelpText: "Last does secret stuff you don't need to know about.", Handler: p.recordLast, @@ -192,7 +192,20 @@ func (p *LastPlugin) sayLast(c bot.Connector, chFrom, chTo string, force bool) { } 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", "") p.b.Send(c, bot.Message, chTo, msg, bot.MessageReference{ MessageID: l.MessageID,