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