justusbot/cmd/bot/main.go

90 lines
1.8 KiB
Go
Raw Normal View History

package main
import (
"context"
2026-09-10 15:44:40 -06:00
"os"
"os/signal"
2026-09-10 15:44:40 -06:00
"github.com/joho/godotenv"
2026-09-10 22:31:23 -06:00
"github.com/mymmrac/telego"
th "github.com/mymmrac/telego/telegohandler"
tu "github.com/mymmrac/telego/telegoutil"
2026-09-10 15:44:40 -06:00
"github.com/robfig/cron/v3"
"fmt"
2026-09-09 22:17:51 -06:00
2026-09-10 15:44:40 -06:00
_ "git.destrealm.net/zancarius/justusbot/internal/bible"
2026-09-10 22:31:23 -06:00
"git.destrealm.net/zancarius/justusbot/internal/settings"
)
// Send any text message to the bot after the bot has been started
func main() {
2026-09-10 15:44:40 -06:00
if err := godotenv.Load(); err != nil {
panic(fmt.Sprintf("dotenv: %s", err))
}
2026-09-10 22:31:23 -06:00
conf, err := settings.LoadSettings("settings.toml")
//wg := &sync.WaitGroup{}
2026-09-10 15:44:40 -06:00
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
2026-09-10 22:31:23 -06:00
bot, err := telego.NewBot(os.Getenv("TOKEN"),
telego.WithDefaultDebugLogger())
if err != nil {
panic(err)
}
2026-09-10 15:44:40 -06:00
c := cron.New()
2026-09-10 22:31:23 -06:00
c.AddFunc(fmt.Sprintf("TZ=%s %s",
conf.System.TimeZone,
conf.DailyScripture.Schedule), func() { fmt.Println("testing at 2pm") })
2026-09-10 15:44:40 -06:00
c.Start()
2026-09-10 22:31:23 -06:00
updates, _ := bot.UpdatesViaLongPolling(ctx, nil)
bh, _ := th.NewBotHandler(bot, updates)
defer func() {
_ = bh.Stop()
}()
bh.HandleMessage(func(ctx *th.Context, message telego.Message) error {
// Send a message with inline keyboard
_, _ = ctx.Bot().SendMessage(ctx, tu.Message(
tu.ID(message.Chat.ID),
fmt.Sprintf("Hello %s!", message.From.FirstName),
).WithReplyMarkup(tu.InlineKeyboard(
tu.InlineKeyboardRow(
tu.InlineKeyboardButton("Go!").WithCallbackData("go"),
)),
))
return nil
}, th.CommandEqual("start"))
bh.Start()
/*wg.Add(1)
2026-09-10 15:44:40 -06:00
go func(){
defer wg.Done()
2026-09-10 22:31:23 -06:00
for {
}
2026-09-10 15:44:40 -06:00
}()
wg.Add(1)
go func(){
defer wg.Done()
time.Sleep(1*time.Second)
fmt.Println(b)
}()
2026-09-10 22:31:23 -06:00
wg.Wait()*/
2026-09-10 15:44:40 -06:00
/*fmt.Println(bible.FindAlias("mat"))
2026-09-09 22:17:51 -06:00
s, err := settings.LoadSettings("settings.toml")
2026-09-10 15:44:40 -06:00
fmt.Println(s, err)*/
}
2026-09-10 22:31:23 -06:00
type Bot struct {
2026-09-10 15:44:40 -06:00
}