This commit is contained in:
Noah 2024-12-20 02:09:07 +01:00
parent 6aa64b6287
commit 3ec330e3a2
16 changed files with 408 additions and 1 deletions

20
botIO/authenticate.go Normal file
View file

@ -0,0 +1,20 @@
package botIO
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/rs/zerolog/log"
"watn3y/steamsalty/config"
)
func Authenticate() *tgbotapi.BotAPI {
bot, err := tgbotapi.NewBotAPI(config.BotConfig.TelegramAPIToken)
if err != nil {
log.Panic().Err(err).Msg("Failed to authenticate")
}
bot.Debug = config.BotConfig.DebugMode
log.Info().Int64("ID", bot.Self.ID).Str("username", bot.Self.UserName).Msg("Successfully authenticated to Telegram API")
return bot
}

71
botIO/sending.go Normal file
View file

@ -0,0 +1,71 @@
package botIO
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"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.Error().Err(err).Msg("Failed to send message")
return
}
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.Error().Err(err).Msg("Failed to edit message")
return
}
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.Error().Err(err).Msg("Failed to send video")
return
}
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.Error().Err(err).Msg("Failed to send photo")
return
}
log.Info().Int64("chat", result.Chat.ID).Msg("Sent photo")
log.Debug().Interface("photo", result).Msg("")
return result
}
func SendSticker(message tgbotapi.StickerConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
result, err := bot.Send(message)
if err != nil {
log.Error().Err(err).Msg("Failed to send sticker")
return
}
log.Info().Int64("chat", result.Chat.ID).Msg("Sent sticker")
log.Debug().Interface("sticker", result).Msg("")
return result
}