diff --git a/bot/bot.go b/bot/bot.go index a17e2ae..b43995f 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -15,6 +15,7 @@ import ( "github.com/go-chi/chi/v5/middleware" "github.com/jmoiron/sqlx" "github.com/rs/zerolog/log" + "github.com/velour/catbase/bot/history" "github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msglog" "github.com/velour/catbase/bot/user" @@ -63,6 +64,8 @@ type bot struct { quiet bool router *chi.Mux + + history *history.History } type EndPoint struct { @@ -82,6 +85,8 @@ func New(config *config.Config, connector Connector) Bot { msglog.RunNew(logIn, logOut) + historySz := config.GetInt("bot.historysz", 100) + users := []user.User{ { Name: config.Get("Nick", "bot"), @@ -103,6 +108,7 @@ func New(config *config.Config, connector Connector) Bot { filters: make(map[string]func(string) string), callbacks: make(CallbackMap), router: chi.NewRouter(), + history: history.New(historySz), } bot.migrateDB() diff --git a/bot/handlers.go b/bot/handlers.go index bec470b..5c69804 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -20,6 +20,13 @@ import ( func (b *bot) Receive(conn Connector, kind Kind, msg msg.Message, args ...interface{}) bool { // msg := b.buildMessage(client, inMsg) // do need to look up user and fix it + + if kind == Edit { + b.history.Edit(msg.ID, &msg) + } else { + b.history.Append(&msg) + } + if kind == Message && strings.HasPrefix(msg.Body, "help") && msg.Command { parts := strings.Fields(strings.ToLower(msg.Body)) b.checkHelp(conn, msg.Channel, parts) diff --git a/bot/interfaces.go b/bot/interfaces.go index 64381e2..5d54388 100644 --- a/bot/interfaces.go +++ b/bot/interfaces.go @@ -18,7 +18,7 @@ const ( // Message any standard chat Message - // Send a disappearing message to a user in chat + // Ephemeral sends a disappearing message to a user in chat Ephemeral // Reply something containing a message reference Reply @@ -28,7 +28,7 @@ const ( Reaction // Edit message ref'd new message to replace Edit - // Not sure what event is + // Event is unknown/generic Event // Help is used when the bot help system is triggered Help diff --git a/plugins/fact/factoid.go b/plugins/fact/factoid.go index e54b27a..c89af1a 100644 --- a/plugins/fact/factoid.go +++ b/plugins/fact/factoid.go @@ -30,7 +30,7 @@ import ( //go:embed *.html var embeddedFS embed.FS -// factoid stores info about our factoid for lookup and later interaction +// Factoid stores info about our factoid for lookup and later interaction type Factoid struct { ID sql.NullInt64 Fact string