2023-05-12 13:59:20 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-05-16 20:07:05 +02:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
2023-05-17 19:51:45 +02:00
|
|
|
"ewintr.nl/matrix-bots/bot"
|
2023-05-15 12:28:12 +02:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2023-05-12 13:59:20 +02:00
|
|
|
"golang.org/x/exp/slog"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-05-25 12:23:34 +02:00
|
|
|
|
2023-05-15 12:28:12 +02:00
|
|
|
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
|
|
|
|
2023-06-08 19:18:38 +02:00
|
|
|
botConfigs := []bot.Config{{
|
2023-06-08 19:10:32 +02:00
|
|
|
Homeserver: getParam("MATRIX_HOMESERVER", "http://localhost"),
|
|
|
|
UserID: getParam("MATRIX_USER_ID", "@bot:localhost"),
|
|
|
|
UserPassword: getParam("MATRIX_PASSWORD", "secret"),
|
|
|
|
UserAccessKey: getParam("MATRIX_ACCESS_KEY", "secret"),
|
|
|
|
UserDisplayName: getParam("MATRIX_DISPLAY_NAME", "Bot"),
|
|
|
|
DBPath: getParam("BOT_DB_PATH", "bot.db"),
|
|
|
|
Pickle: getParam("BOT_PICKLE", "scrambled"),
|
|
|
|
OpenAIKey: getParam("OPENAI_API_KEY", "no key"),
|
2023-06-08 19:18:38 +02:00
|
|
|
SystemPrompt: "You are a chatbot that helps people by responding to their questions with short messages.",
|
|
|
|
}}
|
|
|
|
|
|
|
|
for _, bc := range botConfigs {
|
|
|
|
b := bot.New(bc, logger)
|
|
|
|
if err := b.Init(); err != nil {
|
|
|
|
logger.Error(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
go b.Run()
|
2023-05-15 12:28:12 +02:00
|
|
|
}
|
2023-05-12 15:07:16 +02:00
|
|
|
|
|
|
|
done := make(chan os.Signal)
|
|
|
|
signal.Notify(done, os.Interrupt)
|
|
|
|
<-done
|
|
|
|
|
2023-05-16 20:07:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func getParam(name, def string) string {
|
|
|
|
val, ok := os.LookupEnv(name)
|
|
|
|
if !ok {
|
|
|
|
return def
|
2023-05-15 12:28:12 +02:00
|
|
|
}
|
2023-05-16 20:07:05 +02:00
|
|
|
return val
|
2023-05-12 13:59:20 +02:00
|
|
|
}
|