added proper logging to most of the code
This commit is contained in:
parent
65c6020e49
commit
7d4c9c5ab9
21 changed files with 218 additions and 283 deletions
|
@ -2,7 +2,7 @@ package botIO
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"watn3y/bloaterbotv3/config"
|
||||
)
|
||||
|
||||
|
@ -11,14 +11,15 @@ func Authenticate() (tgbotapi.UpdatesChannel, *tgbotapi.BotAPI) {
|
|||
b, err := tgbotapi.NewBotAPI(config.BotConfig.APIToken)
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to connect Bot to Telegram: %v\n", err)
|
||||
log.Panic().Err(err).Msg("Failed to authorize bot")
|
||||
}
|
||||
|
||||
b.Debug = config.BotConfig.DebugMode
|
||||
|
||||
u := tgbotapi.NewUpdate(0)
|
||||
u.Timeout = 60
|
||||
log.Printf("[bot] Authorized on account %s", b.Self.UserName)
|
||||
|
||||
log.Info().Int64("ID", b.Self.ID).Str("username", b.Self.UserName).Msg("Successfully authorized bot")
|
||||
|
||||
return b.GetUpdatesChan(u), b
|
||||
}
|
||||
|
|
|
@ -2,55 +2,70 @@ package botIO
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func SendMessage(message tgbotapi.MessageConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send message: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to send message")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Sent Message: %s", message.Text)
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Str("msg", result.Text).Msg("Sent message")
|
||||
log.Debug().Interface("msg", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func EditMessage(message tgbotapi.EditMessageTextConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send message: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to edit message")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Edited Message: %s", message.Text)
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Str("msg", result.Text).Msg("Edited message")
|
||||
log.Debug().Interface("msg", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func SendVideo(message tgbotapi.VideoConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send message: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to send video")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Sent Video: %s", message.File)
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Msg("Sent video")
|
||||
log.Debug().Interface("video", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func SendPhoto(message tgbotapi.PhotoConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send message: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to send photo")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Sent Photo: %s", message.File)
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Msg("Sent photo")
|
||||
log.Debug().Interface("photo", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func SendSticker(sticker tgbotapi.StickerConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(sticker)
|
||||
func SendSticker(message tgbotapi.StickerConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send Sticker: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to send sticker")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Sent Sticker")
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Msg("Sent sticker")
|
||||
log.Debug().Interface("sticker", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue