feat: /xr command for currency exchange rates
This commit is contained in:
parent
3122a971bf
commit
730bda35fe
2 changed files with 185 additions and 0 deletions
24
main.go
24
main.go
|
|
@ -4,7 +4,9 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.gensokyo.cafe/kkyy/mycurrencynet"
|
||||
"go.uber.org/zap"
|
||||
tele "gopkg.in/telebot.v3"
|
||||
|
||||
|
|
@ -22,6 +24,25 @@ func initLogger() {
|
|||
logger = l.Sugar()
|
||||
}
|
||||
|
||||
var exchangeRates = mycurrencynet.New()
|
||||
|
||||
func initExchangeRates() {
|
||||
if err := exchangeRates.Update(); err != nil {
|
||||
logger.Panicw("Failed to update exchange rates", "err", err)
|
||||
}
|
||||
logger.Info("Exchange rates updated")
|
||||
|
||||
go exchangeRates.UpdateEvery(
|
||||
time.Hour,
|
||||
func(err error) {
|
||||
logger.Errorw("Failed to update exchange rates", "err", err)
|
||||
},
|
||||
func() {
|
||||
logger.Info("Exchange rates updated")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func runBot() {
|
||||
logger.Info("Bot initializing...")
|
||||
bot, err := initBot()
|
||||
|
|
@ -37,6 +58,7 @@ func runBot() {
|
|||
{Text: "traffic", Description: "Show traffic usage."},
|
||||
{Text: "dig", Description: "Diggy diggy dig."},
|
||||
{Text: "year_progress", Description: "Time doesn't wait."},
|
||||
{Text: "xr", Description: "Currency exchange rates"},
|
||||
}); err != nil {
|
||||
logger.Fatalw("Failed to announce commands", "err", err)
|
||||
}
|
||||
|
|
@ -45,6 +67,8 @@ func runBot() {
|
|||
botFinCh := utils.WaitFor(bot.Start)
|
||||
logger.Infow("Bot started", "username", bot.Me.Username)
|
||||
|
||||
go initExchangeRates()
|
||||
|
||||
// listen for shutdown signal
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue