90 lines
1.8 KiB
Go
90 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
|
|
"github.com/joho/godotenv"
|
|
"github.com/mymmrac/telego"
|
|
th "github.com/mymmrac/telego/telegohandler"
|
|
tu "github.com/mymmrac/telego/telegoutil"
|
|
"github.com/robfig/cron/v3"
|
|
|
|
"fmt"
|
|
|
|
_ "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() {
|
|
if err := godotenv.Load(); err != nil {
|
|
panic(fmt.Sprintf("dotenv: %s", err))
|
|
}
|
|
|
|
conf, err := settings.LoadSettings("settings.toml")
|
|
|
|
//wg := &sync.WaitGroup{}
|
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
|
defer cancel()
|
|
|
|
bot, err := telego.NewBot(os.Getenv("TOKEN"),
|
|
telego.WithDefaultDebugLogger())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
c := cron.New()
|
|
c.AddFunc(fmt.Sprintf("TZ=%s %s",
|
|
conf.System.TimeZone,
|
|
conf.DailyScripture.Schedule), func() { fmt.Println("testing at 2pm") })
|
|
c.Start()
|
|
|
|
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)
|
|
go func(){
|
|
defer wg.Done()
|
|
for {
|
|
|
|
}
|
|
}()
|
|
|
|
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)*/
|
|
}
|
|
|
|
type Bot struct {
|
|
}
|