Compare commits

...

8 commits

Author SHA1 Message Date
c6c7480493
Merge pull request #1 from watn3y/v1.2
Some checks failed
Build and Push to Docker Hub on push to any branch / docker (push) Has been cancelled
V1.2
2025-08-31 04:15:13 +02:00
17ca2cff1b
docs: README changes 2025-08-31 04:12:04 +02:00
38db97bdcf
refactor: Standardized logging to be more uniform 2025-08-31 03:51:36 +02:00
99a81a201b
feat: Parse environment variables from .env file 2025-08-31 03:49:57 +02:00
e654f8449c
bump golang.org/x/net to v0.43.0 for security fixes
- Upgraded golang.org/x/net from v0.33.0 to v0.43.0
- Addresses: CVE-2025-22870 and CVE-2025-22872
- No functional changes or breaking updates
2025-08-08 01:19:10 +02:00
0e278d87ec
Don't log every received message 2024-12-22 08:21:02 +01:00
20b5287675
gitignore vscode config 2024-12-22 08:20:51 +01:00
60fd4b963c
add build script 2024-12-22 07:41:48 +01:00
15 changed files with 134 additions and 60 deletions

3
.gitignore vendored
View file

@ -26,3 +26,6 @@ go.work.sum
# Build ouput
build/
# vscode config
.vscode/

View file

@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.23.4-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.24.6-alpine AS builder
WORKDIR /steamsalty

View file

@ -1,9 +1,10 @@
# SteamSalty
SteamSalty notifies you on telegram about new comments on any steam profile.
## Running with Docker Compose
Docker image: https://hub.docker.com/r/watn3y/steamsalty
Docker image: <https://hub.docker.com/r/watn3y/steamsalty>
Example compose file:
@ -26,15 +27,18 @@ services:
## Running on Linux
Grab a release from the [releases page](https://github.com/watn3y/steamsalty/releases). Make sure to set your **environment variables** accordingly.
Grab a release from the [releases page](https://github.com/watn3y/steamsalty/releases). Make sure to set your [environment variables](#environment-variables) accordingly.
## Environment Variables
| Variable | Description | Default |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------ |
| `STEAMSALTY_LOGLEVEL` | LogLevel as described [here](https://pkg.go.dev/github.com/rs/zerolog@v1.33.0#readme-simple-leveled-logging-example) | 1 (Info) |
| `STEAMSALTY_TELEGRAMAPITOKEN` | Telegram Bot Token, get from @BotFather | None, **required** |
| `STEAMSALTY_STEAMAPIKEY` | Steam API Key, get from https://steamcommunity.com/dev/apikey | None, **required** |
| `STEAMSALTY_CHATID` | Chat to notify about new Comments | None, **required** |
| `STEAMSALTY_WATCHERS` | SteamIDs (in SteamID64 format) to check for new Profile Comments | None, **required** |
| `STEAMSALTY_SLEEPINTERVAL` | Amount of time to wait between requests to Steam in seconds | 60 |
> [!NOTE]
> For development purposes, SteamSalty supports loading environment variables from a .env file placed in the project root directory.
| Variable | Description | Default | Required |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------| ------------------ | -------------- |
| `STEAMSALTY_LOGLEVEL` | LogLevel as described [in the zerolog documentation](https://pkg.go.dev/github.com/rs/zerolog@v1.34.0#readme-simple-leveled-logging-example) | 1 (Info) | ❌ |
| `STEAMSALTY_TELEGRAMAPITOKEN` | Telegram BotToken, get it from [@BotFather on Telegram](https://t.me/BotFather) | None | ✅ |
| `STEAMSALTY_STEAMAPIKEY` | Steam API Key, get it from [steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey) | None | ✅ |
| `STEAMSALTY_CHATID` | Chat to notify about new comments | None | ✅ |
| `STEAMSALTY_WATCHERS` | SteamIDs (in SteamID64 format) to check for new profile comments | None | ✅ |
| `STEAMSALTY_SLEEPINTERVAL` | Amount of time to wait between requests to Steam in seconds | 60 | ❌ |

7
bot.go
View file

@ -18,10 +18,10 @@ func bot() {
go steam.StartWatchers(bot)
for update := range updates {
log.Debug().Interface("update", update).Msg("Received update")
log.Debug().Interface("update", update).Msg("Update received")
if update.Message == nil || update.Message.Text == "" {
log.Debug().Int("UpdateID", update.UpdateID).Msg("Unable to parse update")
log.Debug().Int("UpdateID", update.UpdateID).Msg("Failed to parse update")
continue
}
if update.Message.Time().UTC().Unix() < time.Now().UTC().Unix() {
@ -29,9 +29,8 @@ func bot() {
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() {
log.Info().Int64("ChatID", update.Message.Chat.ID).Int64("UserID", update.Message.From.ID).Str("Text", update.Message.Text).Msg("Command received")
commands.Commands(update, bot)
}
}

View file

@ -9,7 +9,7 @@ import (
func Authenticate() (tgbotapi.UpdatesChannel, *tgbotapi.BotAPI) {
bot, err := tgbotapi.NewBotAPI(config.BotConfig.TelegramAPIToken)
if err != nil {
log.Panic().Err(err).Msg("Failed to authenticate")
log.Panic().Err(err).Msg("Failed to authenticate to Telegram")
}
bot.Debug = false
@ -20,7 +20,7 @@ func Authenticate() (tgbotapi.UpdatesChannel, *tgbotapi.BotAPI) {
updates := tgbotapi.NewUpdate(0)
updates.Timeout = 60
log.Info().Int64("ID", bot.Self.ID).Str("username", bot.Self.UserName).Msg("Authenticated to Telegram API")
log.Info().Int64("ID", bot.Self.ID).Str("username", bot.Self.UserName).Msg("Authenticated to Telegram successfully")
return bot.GetUpdatesChan(updates), bot

View file

@ -12,7 +12,7 @@ func SendMessage(message tgbotapi.MessageConfig, bot *tgbotapi.BotAPI) (result t
return
}
log.Info().Int64("chat", result.Chat.ID).Str("msg", result.Text).Msg("Sent message")
log.Info().Int64("chat", result.Chat.ID).Str("msg", result.Text).Msg("Sent message successfully")
log.Debug().Interface("msg", result).Msg("")
return result
@ -25,7 +25,7 @@ func EditMessage(message tgbotapi.EditMessageTextConfig, bot *tgbotapi.BotAPI) (
return
}
log.Info().Int64("chat", result.Chat.ID).Str("msg", result.Text).Msg("Edited message")
log.Info().Int64("chat", result.Chat.ID).Str("msg", result.Text).Msg("Edited message successfully")
log.Debug().Interface("msg", result).Msg("")
return result
@ -38,7 +38,7 @@ func SendVideo(message tgbotapi.VideoConfig, bot *tgbotapi.BotAPI) (result tgbot
return
}
log.Info().Int64("chat", result.Chat.ID).Msg("Sent video")
log.Info().Int64("chat", result.Chat.ID).Msg("Sent video successfully")
log.Debug().Interface("video", result).Msg("")
return result
@ -51,7 +51,7 @@ func SendPhoto(message tgbotapi.PhotoConfig, bot *tgbotapi.BotAPI) (result tgbot
return
}
log.Info().Int64("chat", result.Chat.ID).Msg("Sent photo")
log.Info().Int64("chat", result.Chat.ID).Msg("Sent photo successfully")
log.Debug().Interface("photo", result).Msg("")
return result
@ -64,7 +64,7 @@ func SendSticker(message tgbotapi.StickerConfig, bot *tgbotapi.BotAPI) (result t
return
}
log.Info().Int64("chat", result.Chat.ID).Msg("Sent sticker")
log.Info().Int64("chat", result.Chat.ID).Msg("Sent sticker successfully")
log.Debug().Interface("sticker", result).Msg("")
return result

54
build.sh Normal file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env bash
# Get the current directory name as the project name
PROJECT_NAME=$(basename "$PWD")
# Change to the Go project directory (current directory)
cd "$PWD" || exit
# List of target architectures
architectures=(
"linux/amd64"
"linux/386"
"linux/arm64"
"linux/arm/v7"
"linux/riscv64"
"windows/amd64"
"darwin/amd64"
"darwin/arm64"
)
# Create a build directory if it doesn't exist
mkdir -p build
# Loop over architectures and build for each one
for arch in "${architectures[@]}"; do
os=$(echo $arch | cut -d '/' -f 1)
arch_type=$(echo $arch | cut -d '/' -f 2)
# Set the output file name using the project name, os, and arch
output_file="build/$PROJECT_NAME-$os-$arch_type"
# Build the app for the specific architecture
GOARCH=$arch_type GOOS=$os go build -o "$output_file"
# Provide feedback to the user
if [ $? -eq 0 ]; then
echo "Successfully built for $arch: $output_file"
# Create a tar.gz archive for the individual build
tar -czf "$output_file.tar.gz" -C build $(basename "$output_file")
if [ $? -eq 0 ]; then
echo "Successfully created archive: $output_file.tar.gz"
# Delete the executable after archiving
rm "$output_file"
echo "Deleted executable: $output_file"
else
echo "Failed to create archive for $output_file"
fi
else
echo "Failed to build for $arch"
fi
done

View file

@ -22,11 +22,11 @@ func SetBotCommands(bot *tgbotapi.BotAPI) {
result, err := bot.Request(commands)
if err != nil {
log.Error().Err(err).Msg("Failed to set own commands")
log.Error().Err(err).Msg("Failed to publish commands to Telegram")
return
}
log.Debug().Interface("commands", result).Msg("Set own commands")
log.Debug().Interface("commands", result).Msg("Published commands to Telegram successfully")
}
func Commands(update tgbotapi.Update, bot *tgbotapi.BotAPI) {

View file

@ -5,18 +5,26 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/joho/godotenv"
envconfig "github.com/sethvargo/go-envconfig"
)
var BotConfig config
func LoadConfig() {
if err := godotenv.Load(); err != nil {
log.Info().Err(err).Msg("Failed to load .env file, using the system environment")
} else {
log.Info().Err(err).Msg(".env file loaded successfully")
}
if err := envconfig.Process(context.Background(), &BotConfig); err != nil {
log.Panic().Err(err).Msg("Error parsing config from env variables")
log.Panic().Err(err).Msg("Failed to parse config from env variables")
}
zerolog.SetGlobalLevel(zerolog.Level(BotConfig.LogLevel))
log.Info().Msg("Loaded config")
log.Info().Msg("Config loaded successfully")
log.Debug().Interface("config", BotConfig).Msg("")
}

15
go.mod
View file

@ -1,19 +1,20 @@
module watn3y/steamsalty
go 1.23.4
go 1.24.6
require (
github.com/Philipp15b/go-steamapi v0.0.0-20210114153316-ec4fdd23b4c1
github.com/PuerkitoBio/goquery v1.10.0
github.com/PuerkitoBio/goquery v1.10.3
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/rs/zerolog v1.33.0
github.com/sethvargo/go-envconfig v1.1.0
github.com/rs/zerolog v1.34.0
github.com/sethvargo/go-envconfig v1.3.0
)
require (
github.com/andybalholm/cascadia v1.3.3 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sys v0.35.0 // indirect
)

25
go.sum
View file

@ -1,7 +1,7 @@
github.com/Philipp15b/go-steamapi v0.0.0-20210114153316-ec4fdd23b4c1 h1:PD13eMe9XAgPQ0SYWyirqwyOJG90TlEWApCw8A699l0=
github.com/Philipp15b/go-steamapi v0.0.0-20210114153316-ec4fdd23b4c1/go.mod h1:eQR7Xf64m2ALDAQE7Nr9ylFZhav1izvF3zzysKPhb0I=
github.com/PuerkitoBio/goquery v1.10.0 h1:6fiXdLuUvYs2OJSvNRqlNPoBm6YABE226xrbavY5Wv4=
github.com/PuerkitoBio/goquery v1.10.0/go.mod h1:TjZZl68Q3eGHNBA8CWaxAN7rOU1EbDz3CWuolcO5Yu4=
github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo=
github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
@ -10,18 +10,21 @@ github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sethvargo/go-envconfig v1.1.0 h1:cWZiJxeTm7AlCvzGXrEXaSTCNgip5oJepekh/BOQuog=
github.com/sethvargo/go-envconfig v1.1.0/go.mod h1:JLd0KFWQYzyENqnEPWWZ49i4vzZo/6nRidxI8YvGiHw=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/sethvargo/go-envconfig v1.3.0 h1:gJs+Fuv8+f05omTpwWIu6KmuseFAXKrIaOZSh8RMt0U=
github.com/sethvargo/go-envconfig v1.3.0/go.mod h1:JLd0KFWQYzyENqnEPWWZ49i4vzZo/6nRidxI8YvGiHw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
@ -42,8 +45,9 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -63,8 +67,9 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

View file

@ -38,6 +38,6 @@ func configureLogger() {
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.DateTime}
log.Logger = zerolog.New(output).With().Timestamp().Caller().Logger()
log.Info().Msg("Started Logger")
log.Info().Msg("Logger started successfully")
}

View file

@ -11,8 +11,8 @@ func GetPlayerDetails(steamID uint64) (summary steamapi.PlayerSummary) {
response, err := steamapi.GetPlayerSummaries([]uint64{steamID}, config.BotConfig.SteamAPIKey)
if err != nil {
log.Error().Err(err).Msg("Failed to get Player Summary")
log.Error().Err(err).Msg("Failed to retrive player summary")
}
log.Debug().Interface("Player", response[0]).Msg("Got PlayerSummary from Steam API")
log.Debug().Interface("Player", response[0]).Msg("Retrived player summary from SteamAPI successfully")
return response[0]
}

View file

@ -19,7 +19,7 @@ func GetComments(steamID uint64, start int, count int) (page CommentsPage) {
url, err := url.Parse(baseURL + strconv.FormatUint(steamID, 10))
if err != nil {
log.Error().Err(err).Msg("Unable to Parse SteamID into URL")
log.Error().Err(err).Msg("Failed to parse SteamID into URL")
return
}
@ -30,7 +30,7 @@ func GetComments(steamID uint64, start int, count int) (page CommentsPage) {
resp, err := http.Get(url.String())
if err != nil || resp.StatusCode != http.StatusOK {
log.Error().Err(err).Int("Response Code", resp.StatusCode).Msg("Failed to get Comments")
log.Error().Err(err).Int("Response Code", resp.StatusCode).Msg("Failed to retrieve comments")
}
defer resp.Body.Close()
@ -38,16 +38,16 @@ func GetComments(steamID uint64, start int, count int) (page CommentsPage) {
// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Error().Err(err).Msg("Failed to parse Comments")
log.Error().Err(err).Msg("Failed to parse comments")
log.Trace().Interface("Body", resp.Body)
}
err = json.Unmarshal(body, &page)
if err != nil {
log.Error().Err(err).Msg("Failed to parse Comments as JSON")
log.Error().Err(err).Msg("Failed to parse comments as JSON")
}
log.Trace().Interface("CommentPage", page).Uint64("ProfileID", steamID).Msg("Got Comment Page")
log.Trace().Interface("CommentPage", page).Uint64("ProfileID", steamID).Msg("Retrieved Comment Page successfully")
return page
}
@ -56,7 +56,7 @@ func parseComments(rawComments CommentsPage) (comments []Comment) {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(rawComments.CommentsHTML))
if err != nil {
log.Error().Err(err).Msg("Error while parsing CommentsHTML")
log.Error().Err(err).Msg("Failed to parse CommentsHTML")
return
}
doc.Find(".commentthread_comment.responsive_body_text").Each(func(i int, s *goquery.Selection) {
@ -64,14 +64,14 @@ func parseComments(rawComments CommentsPage) (comments []Comment) {
parsedID, err := strconv.ParseUint(strings.TrimPrefix(s.AttrOr("id", ""), "comment_"), 10, 64)
if err != nil {
log.Error().Err(err).Msg("Error while parsing Comment ID")
log.Error().Err(err).Msg("Failed to parse Comment ID")
return
}
c.ID = parsedID
c.Timestamp, err = strconv.ParseInt(s.Find(".commentthread_comment_timestamp").AttrOr("data-timestamp", ""), 10, 64)
if err != nil {
log.Error().Err(err).Msg("Error while parsing Comment Timestamp")
log.Error().Err(err).Msg("Failed to parse Comment Timestamp")
return
}
@ -85,6 +85,6 @@ func parseComments(rawComments CommentsPage) (comments []Comment) {
})
slices.Reverse(comments)
log.Trace().Interface("Comments", comments).Msg("Parsed Comment Page")
log.Trace().Interface("Comments", comments).Msg("Parsed comment page successfully")
return comments
}

View file

@ -33,7 +33,7 @@ func StartWatchers(bot *tgbotapi.BotAPI) {
}
func watcher(bot *tgbotapi.BotAPI, steamID uint64, sleeptime time.Duration) {
log.Info().Uint64("SteamID", steamID).Msg("Started Watcher")
log.Info().Uint64("SteamID", steamID).Msg("Starting Watcher")
var newestProcessedComment int64 = 0
@ -56,9 +56,9 @@ func watcher(bot *tgbotapi.BotAPI, steamID uint64, sleeptime time.Duration) {
profileOwner := GetPlayerDetails(steamID)
for _, comment := range parseComments(currentCommentsPage) {
log.Debug().Interface("Comment", comment).Msg("Processing Comment")
log.Debug().Interface("Comment", comment).Msg("Processing comment")
if comment.Timestamp <= newestProcessedComment {
log.Debug().Uint64("CommentID", comment.ID).Msg("Skipping Comment")
log.Debug().Uint64("CommentID", comment.ID).Msg("Skipping comment")
continue
}
@ -69,7 +69,7 @@ func watcher(bot *tgbotapi.BotAPI, steamID uint64, sleeptime time.Duration) {
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")
log.Info().Interface("Comment", comment).Msg("Notifying about new comment")
botIO.SendMessage(msg, bot)
time.Sleep(time.Minute / 20)
}