mirror of
https://github.com/watn3y/steamsalty.git
synced 2025-05-12 23:31:36 +02:00
v0.3
Some checks failed
Build and Push to Docker Hub on changes to master branch / docker (push) Has been cancelled
Some checks failed
Build and Push to Docker Hub on changes to master branch / docker (push) Has been cancelled
- added start command - added info command
This commit is contained in:
parent
9c64a3e4b5
commit
453f03d832
5 changed files with 98 additions and 7 deletions
28
bot.go
28
bot.go
|
@ -1,10 +1,36 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"watn3y/steamsalty/botIO"
|
"watn3y/steamsalty/botIO"
|
||||||
|
"watn3y/steamsalty/commands"
|
||||||
"watn3y/steamsalty/steam"
|
"watn3y/steamsalty/steam"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bot() {
|
func bot() {
|
||||||
steam.StartWatchers(botIO.Authenticate())
|
updates, bot := botIO.Authenticate()
|
||||||
|
|
||||||
|
go steam.StartWatchers(bot)
|
||||||
|
|
||||||
|
for update := range updates {
|
||||||
|
log.Debug().Interface("update", update).Msg("Received update")
|
||||||
|
|
||||||
|
if update.Message == nil || update.Message.Text == "" {
|
||||||
|
log.Debug().Int("UpdateID", update.UpdateID).Msg("Unable to parse update")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if update.Message.Time().UTC().Unix() < time.Now().UTC().Unix() {
|
||||||
|
log.Debug().Int("UpdateID", update.UpdateID).Msg("Skipping old update")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info().Int64("ChatID", update.Message.Chat.ID).Int64("UserID", update.Message.From.ID).Str("Text", update.Message.Text).Msg("Recieved Message")
|
||||||
|
|
||||||
|
if update.Message.IsCommand() {
|
||||||
|
commands.Commands(update, bot)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"watn3y/steamsalty/config"
|
"watn3y/steamsalty/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Authenticate() *tgbotapi.BotAPI {
|
func Authenticate() (tgbotapi.UpdatesChannel, *tgbotapi.BotAPI) {
|
||||||
bot, err := tgbotapi.NewBotAPI(config.BotConfig.TelegramAPIToken)
|
bot, err := tgbotapi.NewBotAPI(config.BotConfig.TelegramAPIToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic().Err(err).Msg("Failed to authenticate")
|
log.Panic().Err(err).Msg("Failed to authenticate")
|
||||||
|
@ -14,7 +14,11 @@ func Authenticate() *tgbotapi.BotAPI {
|
||||||
|
|
||||||
bot.Debug = config.BotConfig.DebugMode
|
bot.Debug = config.BotConfig.DebugMode
|
||||||
|
|
||||||
|
updates := tgbotapi.NewUpdate(0)
|
||||||
|
updates.Timeout = 60
|
||||||
|
|
||||||
log.Info().Int64("ID", bot.Self.ID).Str("username", bot.Self.UserName).Msg("Successfully authenticated to Telegram API")
|
log.Info().Int64("ID", bot.Self.ID).Str("username", bot.Self.UserName).Msg("Successfully authenticated to Telegram API")
|
||||||
|
|
||||||
return bot
|
return bot.GetUpdatesChan(updates), bot
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
60
commands/commands.go
Normal file
60
commands/commands.go
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"watn3y/steamsalty/botIO"
|
||||||
|
"watn3y/steamsalty/config"
|
||||||
|
"watn3y/steamsalty/steam"
|
||||||
|
|
||||||
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Commands(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||||
|
|
||||||
|
cmd := strings.ToLower(update.Message.Command())
|
||||||
|
|
||||||
|
log.Debug().Str("cmd", cmd).Msg("Matching command")
|
||||||
|
|
||||||
|
switch cmd {
|
||||||
|
case "start":
|
||||||
|
start(update, bot)
|
||||||
|
case "info":
|
||||||
|
info(update, bot)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func start(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||||
|
message := tgbotapi.MessageConfig{
|
||||||
|
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||||
|
ParseMode: "html",
|
||||||
|
DisableWebPagePreview: false,
|
||||||
|
Text: "https://github.com/watn3y/steamsalty",
|
||||||
|
}
|
||||||
|
botIO.SendMessage(message, bot)
|
||||||
|
}
|
||||||
|
|
||||||
|
func info(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||||
|
if update.Message.Chat.ID != config.BotConfig.ChatID {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
textInfo := "<b>Watching profiles:</b> " + "\n"
|
||||||
|
|
||||||
|
for _, steamID := range config.BotConfig.Watchers {
|
||||||
|
profile := steam.GetPlayerDetails(steamID)
|
||||||
|
|
||||||
|
textInfo += fmt.Sprintf(`- <a href="%s">%s</a>`, profile.ProfileURL, profile.PersonaName) + "\n"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message := tgbotapi.MessageConfig{
|
||||||
|
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||||
|
ParseMode: "html",
|
||||||
|
DisableWebPagePreview: true,
|
||||||
|
Text: textInfo,
|
||||||
|
}
|
||||||
|
botIO.SendMessage(message, bot)
|
||||||
|
|
||||||
|
}
|
|
@ -1,12 +1,13 @@
|
||||||
package steam
|
package steam
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"watn3y/steamsalty/config"
|
||||||
|
|
||||||
"github.com/Philipp15b/go-steamapi"
|
"github.com/Philipp15b/go-steamapi"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"watn3y/steamsalty/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getPlayerDetails(steamID uint64) (summary steamapi.PlayerSummary) {
|
func GetPlayerDetails(steamID uint64) (summary steamapi.PlayerSummary) {
|
||||||
|
|
||||||
response, err := steamapi.GetPlayerSummaries([]uint64{steamID}, config.BotConfig.SteamAPIKey)
|
response, err := steamapi.GetPlayerSummaries([]uint64{steamID}, config.BotConfig.SteamAPIKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -46,14 +46,14 @@ func watcher(bot *tgbotapi.BotAPI, steamID uint64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(currentCommentsPage.CommentsHTML, steamContentCheckText) {
|
if strings.Contains(currentCommentsPage.CommentsHTML, steamContentCheckText) {
|
||||||
log.Info().Uint64("ProfileID", steamID).Msg("Found new comment(s) still being checked by Steam, retrying in "+ sleeptime.String())
|
log.Info().Uint64("ProfileID", steamID).Msg("Found new comment(s) still being checked by Steam, retrying in " + sleeptime.String())
|
||||||
time.Sleep(sleeptime)
|
time.Sleep(sleeptime)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Uint64("ProfileID", steamID).Msg("Found new comment(s)")
|
log.Info().Uint64("ProfileID", steamID).Msg("Found new comment(s)")
|
||||||
|
|
||||||
profileOwner := getPlayerDetails(steamID)
|
profileOwner := GetPlayerDetails(steamID)
|
||||||
|
|
||||||
for _, comment := range parseComments(currentCommentsPage) {
|
for _, comment := range parseComments(currentCommentsPage) {
|
||||||
log.Debug().Interface("Comment", comment).Msg("Processing Comment")
|
log.Debug().Interface("Comment", comment).Msg("Processing Comment")
|
||||||
|
|
Loading…
Reference in a new issue