steamsalty/steam/profile.go
Noah Theus 453f03d832
Some checks failed
Build and Push to Docker Hub on changes to master branch / docker (push) Has been cancelled
v0.3
- added start command
- added info command
2024-12-21 08:28:28 +01:00

80 lines
2.5 KiB
Go

package steam
import (
"fmt"
"math"
"strings"
"sync"
"time"
"watn3y/steamsalty/botIO"
"watn3y/steamsalty/config"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/rs/zerolog/log"
)
var sleeptime time.Duration = time.Duration(config.BotConfig.SleepInterval) * time.Second
var steamContentCheckText string = "This comment is awaiting analysis by our automated content check system. It will be temporarily hidden until we verify that it does not contain harmful content (e.g. links to websites that attempt to steal information)."
func StartWatchers(bot *tgbotapi.BotAPI) {
var wg sync.WaitGroup
for _, steamID := range config.BotConfig.Watchers {
wg.Add(1)
go func(steamID uint64) {
defer wg.Done()
watcher(bot, steamID)
}(steamID)
}
wg.Wait()
}
func watcher(bot *tgbotapi.BotAPI, steamID uint64) {
log.Info().Uint64("SteamID", steamID).Msg("Started Watcher")
var newestProcessedComment int64 = 0
for {
currentCommentsPage := getComments(steamID, 0, math.MaxInt32)
if newestProcessedComment == 0 || newestProcessedComment == currentCommentsPage.TimeLastPost {
newestProcessedComment = currentCommentsPage.TimeLastPost
time.Sleep(sleeptime)
continue
}
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())
time.Sleep(sleeptime)
continue
}
log.Info().Uint64("ProfileID", steamID).Msg("Found new comment(s)")
profileOwner := GetPlayerDetails(steamID)
for _, comment := range parseComments(currentCommentsPage) {
log.Debug().Interface("Comment", comment).Msg("Processing Comment")
if comment.Timestamp <= newestProcessedComment {
log.Debug().Uint64("CommentID", comment.ID).Msg("Skipping Comment")
continue
}
msg := tgbotapi.MessageConfig{
BaseChat: tgbotapi.BaseChat{ChatID: config.BotConfig.ChatID},
ParseMode: "HTML",
DisableWebPagePreview: true,
Text: fmt.Sprintf(`<b><a href="%s">%s</a> just commented on <a href="%s">%s</a>'s profile:</b>`, comment.AuthorProfileURL, comment.Author, profileOwner.ProfileURL, profileOwner.PersonaName) + "\n" +
"<blockquote>" + comment.Text + "</blockquote>",
}
log.Info().Interface("Comment", comment).Msg("Notifying about new Comment")
botIO.SendMessage(msg, bot)
time.Sleep(time.Minute / 20)
}
newestProcessedComment = currentCommentsPage.TimeLastPost
time.Sleep(sleeptime)
}
}