summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratyush Desai2024-10-10 16:56:19 +0200
committerPratyush Desai2024-10-10 16:56:19 +0200
commit91b0e21b7ac29d11d7c6774c92c99f4640a1a8d1 (patch)
tree2e6a75f85583b04a7a19c54fade8e5ddb7cc44e6
parente300f7137055a260c522fe546a75e528533cf812 (diff)
parentdfe7deff72ec77f798efe243c1c22bb63c523040 (diff)
downloadwatbot-91b0e21b7ac29d11d7c6774c92c99f4640a1a8d1.tar.gz
watbot-91b0e21b7ac29d11d7c6774c92c99f4640a1a8d1.tar.bz2
watbot-91b0e21b7ac29d11d7c6774c92c99f4640a1a8d1.zip
Merge pull request 'Configurable database path' (#26) from config into master
Reviewed-on: https://git.com.de/LibertaCasa/watbot/pulls/26
-rw-r--r--config.example.yaml1
-rw-r--r--main.go2
-rw-r--r--wat/bot.go3
-rw-r--r--wat/db.go4
4 files changed, 7 insertions, 3 deletions
diff --git a/config.example.yaml b/config.example.yaml
index 02dc9dd..bc766ca 100644
--- a/config.example.yaml
+++ b/config.example.yaml
@@ -1,4 +1,5 @@
watbot:
+ database: wat.db # wat.db (in the working directory) is the default
server:
host: irc.casa # mandatory, no default
port: 6697
diff --git a/main.go b/main.go
index fb71444..1d13154 100644
--- a/main.go
+++ b/main.go
@@ -20,6 +20,7 @@ type Config struct {
}
type watConfig struct {
+ Database string `default:"wat.db" yaml:"database"`
Nick string `yaml:"nick"`
Pass string `yaml:"pass"`
User string `yaml:"user"`
@@ -99,6 +100,7 @@ func main() {
Name: config.Name,
}
watConfig := wat.WatConfig{
+ DatabasePath: config.Database,
AutoJoinChannels: config.Channels.Join,
PermittedChannels: config.Channels.Permitted,
IgnoredHosts: config.Ignores.Hosts,
diff --git a/wat/bot.go b/wat/bot.go
index ffa6d8b..806906c 100644
--- a/wat/bot.go
+++ b/wat/bot.go
@@ -20,6 +20,7 @@ type WatBot struct {
}
type WatConfig struct {
+ DatabasePath string
BotHosts []string
BotGames BotGameConfig
AdminHosts []string
@@ -30,7 +31,7 @@ type WatConfig struct {
func NewWatBot(config *irc.ClientConfig, watConfig *WatConfig, serverConn *tls.Conn) *WatBot {
wat := WatBot{conn: serverConn, Nick: config.Nick, c: watConfig}
- wat.Db = NewWatDb()
+ wat.Db = NewWatDb(watConfig.DatabasePath)
wat.game = NewWatGame(&wat, wat.Db)
wat.integration = NewWatIntegration(&wat, wat.Db, &WatIntegrationConfig{BotHosts: watConfig.BotHosts, BotGames: watConfig.BotGames})
config.Handler = irc.HandlerFunc(wat.HandleIrcMsg)
diff --git a/wat/db.go b/wat/db.go
index 8971223..cd59892 100644
--- a/wat/db.go
+++ b/wat/db.go
@@ -52,10 +52,10 @@ type WatDb struct {
db *gorm.DB
}
-func NewWatDb() *WatDb {
+func NewWatDb(dbpath string) *WatDb {
w := WatDb{}
var err error
- w.db, err = gorm.Open(sqlite.Open("wat.db"), &gorm.Config{})
+ w.db, err = gorm.Open(sqlite.Open(dbpath), &gorm.Config{})
if err != nil {
panic(err)
}