WIP push
This commit is contained in:
31
bolt.go
31
bolt.go
@@ -10,6 +10,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"code.jakeyoungdev.com/go/lite"
|
||||
dg "github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
@@ -22,19 +23,31 @@ const (
|
||||
dg.IntentMessageContent |
|
||||
dg.IntentsGuildMessages |
|
||||
dg.IntentGuildMessageReactions
|
||||
|
||||
DEFAULT_DB_NAME = "boltdb"
|
||||
DB_PATH = "/var/lib/bolt"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
//user, which user saved this
|
||||
//data, does this just go interface?
|
||||
//date saved?
|
||||
//expires?
|
||||
}
|
||||
|
||||
// basic bot structure containing discordgo connection as well as the command map
|
||||
type bolt struct {
|
||||
*dg.Session //holds discordgo internals
|
||||
commands map[string]Command //maps trigger phrase to command struct for fast lookup
|
||||
indicator string //the indicator used to detect whether a message is a command
|
||||
logLvl LogLevel //determines how much the bot logs
|
||||
db lite.Database
|
||||
}
|
||||
|
||||
type Bolt interface {
|
||||
Start() error
|
||||
AddCommands(cmd ...Command)
|
||||
Database(file string) error
|
||||
//filtered methods
|
||||
stop() error
|
||||
messageHandler(s *dg.Session, msg *dg.MessageCreate)
|
||||
@@ -97,8 +110,26 @@ func (b *bolt) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *bolt) Database(file string) error {
|
||||
if file == "" {
|
||||
file = DEFAULT_DB_NAME
|
||||
}
|
||||
|
||||
db, err := lite.New(lite.WithFile(file), lite.WithPath(DB_PATH))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.db = db
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// stops the bot
|
||||
func (b *bolt) stop() error {
|
||||
if b.db != nil {
|
||||
b.db.Close()
|
||||
}
|
||||
return b.Close()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user