From 9e2bb347dbeadbf673a59028859e2df26ce1155a Mon Sep 17 00:00:00 2001 From: "Benjamin A. Shelton" Date: Thu, 10 Sep 2026 15:44:40 -0600 Subject: [PATCH] Testing a few things. --- cmd/bot/main.go | 54 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/cmd/bot/main.go b/cmd/bot/main.go index 24bd50e..2903929 100644 --- a/cmd/bot/main.go +++ b/cmd/bot/main.go @@ -2,22 +2,32 @@ package main import ( "context" - _ "os" - _ "os/signal" + "os" + "os/signal" + "sync" + "time" "github.com/go-telegram/bot" "github.com/go-telegram/bot/models" + "github.com/joho/godotenv" + "github.com/robfig/cron/v3" "fmt" - "git.destrealm.net/zancarius/justusbot/internal/bible" - "git.destrealm.net/zancarius/justusbot/internal/settings" + _ "git.destrealm.net/zancarius/justusbot/internal/bible" + _ "git.destrealm.net/zancarius/justusbot/internal/settings" ) // Send any text message to the bot after the bot has been started func main() { - /*ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + if err := godotenv.Load(); err != nil { + panic(fmt.Sprintf("dotenv: %s", err)) + } + + wg := &sync.WaitGroup{} + + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() opts := []bot.Option{ @@ -26,18 +36,36 @@ func main() { b, err := bot.New(os.Getenv("TOKEN"), opts...) if nil != err { - // panics for the sake of simplicity. - // you should handle this error properly in your code. - panic(err) + fmt.Errorf("%v", err) } + b.RegisterHandler(bot.HandlerTypeMessageText, "/start", bot.MatchTypeExact, startHandler) - b.Start(ctx)*/ - fmt.Println(bible.FindAlias("mat")) + c := cron.New() + c.AddFunc("TZ=America/Denver 7 14 * * *", func(){fmt.Println("testing at 2pm")}) + c.Start() + + wg.Add(1) + go func(){ + defer wg.Done() + b.Start(ctx) + }() + + wg.Add(1) + go func(){ + defer wg.Done() + time.Sleep(1*time.Second) + fmt.Println(b) + }() + + wg.Wait() + + /*fmt.Println(bible.FindAlias("mat")) s, err := settings.LoadSettings("settings.toml") - fmt.Println(s, err) + fmt.Println(s, err)*/ } func handler(ctx context.Context, b *bot.Bot, update *models.Update) { + fmt.Println(b.GetMe(ctx)) /*if update.Message != nil { b.SendMessage(ctx, &bot.SendMessageParams{ ChatID: update.Message.Chat.ID, @@ -45,3 +73,7 @@ func handler(ctx context.Context, b *bot.Bot, update *models.Update) { }) }*/ } + +func startHandler(ctx context.Context, b *bot.Bot, update *models.Update) { + fmt.Println("received start:", b, update) +}