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

27
main.go
View file

@ -4,18 +4,18 @@ import (
"os"
"os/signal"
"syscall"
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
tele "gopkg.in/telebot.v3"
"git.gensokyo.cafe/kkyy/mycurrencynet"
"git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/utils"
)
var logger *zap.SugaredLogger
var loglvl zap.AtomicLevel
var (
logger *zap.SugaredLogger
loglvl zap.AtomicLevel
)
func initLogger() {
logCfg := zap.NewProductionConfig()
@ -29,25 +29,6 @@ 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()