Some checks failed
Build and Push Docker Images / docker (push) Failing after 44s
Signed-off-by: sunyz <i@sunyz.net>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"math/rand"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/realSunyz/lucky-tgbot/plugin/info"
|
|
"github.com/realSunyz/lucky-tgbot/plugin/reborn"
|
|
"github.com/realSunyz/lucky-tgbot/plugin/slash"
|
|
"github.com/realSunyz/lucky-tgbot/plugin/torf"
|
|
tele "gopkg.in/telebot.v3"
|
|
)
|
|
|
|
func main() {
|
|
pref := tele.Settings{
|
|
Token: os.Getenv("TOKEN"),
|
|
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
|
|
}
|
|
|
|
b, err := tele.NewBot(pref)
|
|
if err != nil {
|
|
log.Fatal("Error creating bot: ", err)
|
|
return
|
|
}
|
|
|
|
rebornData, err := reborn.InitRebornList("plugin/reborn/countries.json")
|
|
if err != nil {
|
|
log.Fatal("Error initializing rebornData: ", err)
|
|
}
|
|
|
|
source := rand.NewSource(time.Now().UnixNano())
|
|
r := rand.New(source)
|
|
|
|
b.Handle("/info", info.Execute)
|
|
|
|
b.Handle("/reborn", func(c tele.Context) error {
|
|
return reborn.Execute(c, r, rebornData)
|
|
})
|
|
|
|
b.Handle(tele.OnText, func(c tele.Context) error {
|
|
inputText := c.Text()
|
|
|
|
if strings.HasPrefix(inputText, "/") {
|
|
return slash.Execute(c)
|
|
} else {
|
|
return torf.Execute(c, r)
|
|
}
|
|
})
|
|
|
|
b.Start()
|
|
}
|