various improvements

This commit is contained in:
watn3y 2023-12-29 02:35:22 +01:00
parent d5272262da
commit 1a6953900c
14 changed files with 71 additions and 49 deletions

View file

@ -2,25 +2,24 @@ package botIO
import (
"watn3y/bloaterbot/config"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/rs/zerolog/log"
)
func Authenticate() (tgbotapi.UpdatesChannel, *tgbotapi.BotAPI) {
b, err := tgbotapi.NewBotAPI(config.BotConfig.APIToken)
bot, err := tgbotapi.NewBotAPI(config.BotConfig.APIToken)
if err != nil {
log.Panic().Err(err).Msg("Failed to authorize bot")
}
b.Debug = config.BotConfig.DebugMode
bot.Debug = config.BotConfig.DebugMode
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := tgbotapi.NewUpdate(0)
updates.Timeout = 60
log.Info().Int64("ID", b.Self.ID).Str("username", b.Self.UserName).Msg("Successfully authorized bot")
log.Info().Int64("ID", bot.Self.ID).Str("username", bot.Self.UserName).Msg("Successfully authorized bot")
return b.GetUpdatesChan(u), b
return bot.GetUpdatesChan(updates), bot
}

View file

@ -1,12 +1,18 @@
package botIO
import tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
import (
"github.com/rs/zerolog/log"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
func GetUserByID(userToGet tgbotapi.ChatConfigWithUser, bot *tgbotapi.BotAPI) (error bool, member tgbotapi.ChatMember) {
member, err := bot.GetChatMember(tgbotapi.GetChatMemberConfig{ChatConfigWithUser: userToGet})
if err != nil {
log.Error().Err(err).Msg("Unable to get info for user")
return true, member
}
log.Debug().Interface("member",member).Msg("Got Info for user")
return false, member
}