mirror of
https://github.com/watn3y/steamsalty.git
synced 2025-06-07 15:21:00 +02:00
v0.1
This commit is contained in:
parent
6aa64b6287
commit
3ec330e3a2
16 changed files with 408 additions and 1 deletions
20
botIO/authenticate.go
Normal file
20
botIO/authenticate.go
Normal 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
71
botIO/sending.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue