Add option to import macros/reminders from old install
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Hamcha 2022-03-27 00:53:11 +01:00
parent 7439793823
commit f6e8ce25b3
Signed by: hamcha
GPG Key ID: 1669C533B8CF6D89
1 changed files with 23 additions and 0 deletions

23
main.go
View File

@ -4,6 +4,7 @@ import (
"flag"
"log"
"net/url"
"os"
"strings"
"git.fromouter.space/crunchy-rocks/clessy-ng/modules"
@ -34,8 +35,11 @@ func checkErr(err error, message string, args ...interface{}) {
func main() {
disable := flag.String("disable", "", "Blacklist mods (separated by comma)")
enable := flag.String("enable", "", "Whitelist mods (separated by comma)")
macrofile := flag.String("import-macros", "", "If specified, path to JSON file containing macros to import to DB")
remindfile := flag.String("import-reminders", "", "If specified, path to JSON file containing reminders to import to DB")
flag.Parse()
// Make Telegram API client
api := tg.MakeAPIClient(utils.RequireEnv("CLESSY_TOKEN"))
name, err := api.GetMe()
checkErr(err, "could not retrieve bot info")
@ -45,6 +49,23 @@ func main() {
checkErr(err, "could not open database")
defer db.Close()
// Perform imports
if *macrofile != "" {
byt, err := os.ReadFile(*macrofile)
checkErr(err, "could not load macro file")
db.Set([]byte("mod/macros/data"), byt, &pebble.WriteOptions{Sync: true})
log.Println("Imported macros")
}
if *remindfile != "" {
byt, err := os.ReadFile(*macrofile)
checkErr(err, "could not load macro file")
db.Set([]byte("mod/macros/data"), byt, &pebble.WriteOptions{Sync: true})
log.Println("Imported reminders")
}
// Pick modules
toActivate := make(map[string]modules.Module)
if *disable != "" {
for _, modname := range strings.Split(*disable, ",") {
@ -60,6 +81,7 @@ func main() {
toActivate = mods
}
// Initialize modules
for modname, mod := range toActivate {
log.Printf("Initializing %s", modname)
err := mod.Initialize(modules.ModuleOptions{
@ -70,6 +92,7 @@ func main() {
checkErr(err, "Starting module %s failed with error", modname)
}
// Set webhook and handle calls
webhook := utils.RequireEnv("CLESSY_WEBHOOK")
uri, err := url.Parse(webhook)
checkErr(err, "Specified webhook is not a valid URL")