refactor: move functions

This commit is contained in:
Yiyang Kang 2023-03-20 15:22:46 +08:00
parent 658a041ff8
commit 522d253410
5 changed files with 163 additions and 147 deletions

View file

@ -5,6 +5,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"git.gensokyo.cafe/kkyy/mycurrencynet"
"github.com/dustin/go-humanize"
@ -13,6 +14,25 @@ import (
tele "gopkg.in/telebot.v3"
)
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 handleExchangeRateCmd(c tele.Context) error {
msg := c.Message()
if msg == nil {