- Fixed SLEEPTIME not working (always 0)
- Refined logging
- Added metadata to /info command
- Bot now automatically sets own commands for autocompletion
This commit is contained in:
Noah 2024-12-22 07:13:19 +01:00
parent eb0482b8e0
commit 6be403fc58
14 changed files with 116 additions and 53 deletions

View file

@ -13,6 +13,6 @@ func GetPlayerDetails(steamID uint64) (summary steamapi.PlayerSummary) {
if err != nil {
log.Error().Err(err).Msg("Failed to get Player Summary")
}
log.Debug().Interface("Player", response[0]).Msg("Successfully got PlayerSummary from Steam API")
log.Debug().Interface("Player", response[0]).Msg("Got PlayerSummary from Steam API")
return response[0]
}

View file

@ -13,7 +13,7 @@ import (
"github.com/rs/zerolog/log"
)
func getComments(steamID uint64, start int, count int) (page CommentsPage) {
func GetComments(steamID uint64, start int, count int) (page CommentsPage) {
baseURL := "https://steamcommunity.com/comment/Profile/render/"
@ -47,7 +47,7 @@ func getComments(steamID uint64, start int, count int) (page CommentsPage) {
log.Error().Err(err).Msg("Failed to parse Comments as JSON")
}
log.Debug().Interface("CommentPage", page).Uint64("ProfileID", steamID).Msg("Successfully got Comment Page")
log.Trace().Interface("CommentPage", page).Uint64("ProfileID", steamID).Msg("Got Comment Page")
return page
}
@ -85,6 +85,6 @@ func parseComments(rawComments CommentsPage) (comments []Comment) {
})
slices.Reverse(comments)
log.Debug().Interface("Comments", comments).Msg("Successfully parsed Comment Page")
log.Trace().Interface("Comments", comments).Msg("Parsed Comment Page")
return comments
}

View file

@ -15,30 +15,30 @@ import (
"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)
watcher(bot, steamID, time.Duration(config.BotConfig.SleepInterval)*time.Second)
}(steamID)
}
wg.Wait()
}
func watcher(bot *tgbotapi.BotAPI, steamID uint64) {
func watcher(bot *tgbotapi.BotAPI, steamID uint64, sleeptime time.Duration) {
log.Info().Uint64("SteamID", steamID).Msg("Started Watcher")
var newestProcessedComment int64 = 0
for {
currentCommentsPage := getComments(steamID, 0, math.MaxInt32)
currentCommentsPage := GetComments(steamID, 0, math.MaxInt32)
if newestProcessedComment == 0 || newestProcessedComment == currentCommentsPage.TimeLastPost {
newestProcessedComment = currentCommentsPage.TimeLastPost
time.Sleep(sleeptime)