mirror of https://github.com/velour/catbase.git
history: record history in bot
This commit is contained in:
parent
fc0c6ccd46
commit
373929646c
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue