Changing API library to telego.
This commit is contained in:
parent
0ed5159f33
commit
7234cb2668
6 changed files with 189 additions and 37 deletions
|
|
@ -4,18 +4,17 @@ import (
|
|||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-telegram/bot"
|
||||
"github.com/go-telegram/bot/models"
|
||||
"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"
|
||||
"git.destrealm.net/zancarius/justusbot/internal/settings"
|
||||
)
|
||||
|
||||
// Send any text message to the bot after the bot has been started
|
||||
|
|
@ -25,29 +24,52 @@ func main() {
|
|||
panic(fmt.Sprintf("dotenv: %s", err))
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
conf, err := settings.LoadSettings("settings.toml")
|
||||
|
||||
//wg := &sync.WaitGroup{}
|
||||
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
opts := []bot.Option{
|
||||
bot.WithDefaultHandler(handler),
|
||||
bot, err := telego.NewBot(os.Getenv("TOKEN"),
|
||||
telego.WithDefaultDebugLogger())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
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.AddFunc(fmt.Sprintf("TZ=%s %s",
|
||||
conf.System.TimeZone,
|
||||
conf.DailyScripture.Schedule), func() { fmt.Println("testing at 2pm") })
|
||||
c.Start()
|
||||
|
||||
wg.Add(1)
|
||||
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()
|
||||
b.Start(ctx)
|
||||
for {
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
wg.Add(1)
|
||||
|
|
@ -57,23 +79,12 @@ func main() {
|
|||
fmt.Println(b)
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
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)
|
||||
type Bot struct {
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue