79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"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"
|
|
)
|
|
|
|
// 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))
|
|
}
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
|
defer cancel()
|
|
|
|
opts := []bot.Option{
|
|
bot.WithDefaultHandler(handler),
|
|
}
|
|
|
|
b, err := bot.New(os.Getenv("TOKEN"), opts...)
|
|
if nil != err {
|
|
fmt.Errorf("%v", err)
|
|
}
|
|
b.RegisterHandler(bot.HandlerTypeMessageText, "/start", bot.MatchTypeExact, startHandler)
|
|
|
|
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)*/
|
|
}
|
|
|
|
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,
|
|
Text: update.Message.Text,
|
|
})
|
|
}*/
|
|
}
|
|
|
|
func startHandler(ctx context.Context, b *bot.Bot, update *models.Update) {
|
|
fmt.Println("received start:", b, update)
|
|
}
|