From f3a3d853a8e56ccadf45882aaea49cfd4fde54a6 Mon Sep 17 00:00:00 2001 From: Miguel Machado Date: Fri, 12 Jan 2024 00:18:42 -0300 Subject: [PATCH] Delete scraper directory --- scraper/changeHuntPlayerCountTicker.go | 16 --------- scraper/changePlayersCount.go | 28 ---------------- scraper/huntScraper.go | 46 -------------------------- 3 files changed, 90 deletions(-) delete mode 100644 scraper/changeHuntPlayerCountTicker.go delete mode 100644 scraper/changePlayersCount.go delete mode 100644 scraper/huntScraper.go diff --git a/scraper/changeHuntPlayerCountTicker.go b/scraper/changeHuntPlayerCountTicker.go deleted file mode 100644 index f18e12f..0000000 --- a/scraper/changeHuntPlayerCountTicker.go +++ /dev/null @@ -1,16 +0,0 @@ -package scraper - -import ( - "time" - - "github.com/bwmarrin/discordgo" -) - -func UpdateHuntPlayerCountTicker(s *discordgo.Session, channelID string, intervalMinutes int) { - ticker := time.NewTicker(time.Duration(intervalMinutes) * time.Minute) - defer ticker.Stop() - - for range ticker.C { - ChangePlayersCount(s, channelID) - } -} diff --git a/scraper/changePlayersCount.go b/scraper/changePlayersCount.go deleted file mode 100644 index e048ad8..0000000 --- a/scraper/changePlayersCount.go +++ /dev/null @@ -1,28 +0,0 @@ -package scraper - -import ( - "fmt" - "time" - - "github.com/MiguelMachado-dev/disc-go-bot/utils" - "github.com/bwmarrin/discordgo" -) - -func ChangePlayersCount(s *discordgo.Session, channelID string) { - playersCh := make(chan string) - go hunt(playersCh) // Call the scraper in a goroutine (concurrently) - - var players string - select { - case players = <-playersCh: - // Successfully received players count from the scraper - case <-time.After(30 * time.Second): - // Timeout after 30 seconds if the scraper doesn't respond - log.Warnln("Scraper timed out") - } - - newName := fmt.Sprintf("Hunt p: %s", players) - - // Change the voice channel name - utils.ChangeVoiceChannelName(s, channelID, newName) -} diff --git a/scraper/huntScraper.go b/scraper/huntScraper.go deleted file mode 100644 index 33e5a8c..0000000 --- a/scraper/huntScraper.go +++ /dev/null @@ -1,46 +0,0 @@ -package scraper - -import ( - "regexp" - "time" - - "github.com/MiguelMachado-dev/disc-go-bot/config" - "github.com/gocolly/colly" -) - -type Stats struct { - Players string -} - -var log = config.NewLogger("huntScraper") - -func hunt(playersCh chan string) { - // Prints time that the scraper started - log.Infoln("Start scraping at", time.Now()) - - c := colly.NewCollector( - colly.AllowedDomains("steamcommunity.com"), - ) - - c.OnHTML(".apphub_HeaderBottom div.apphub_Stats", func(e *colly.HTMLElement) { - stats := Stats{} - stats.Players = e.ChildText(".apphub_NumInApp") - - // Use a regular expression to match numbers and commas - re := regexp.MustCompile(`[\d,]+`) - matches := re.FindString(stats.Players) - - // Send the players count through the channel - playersCh <- matches - }) - - c.OnResponse(func(r *colly.Response) { - log.Infoln("Status code:", r.StatusCode) - }) - - c.OnRequest(func(r *colly.Request) { - log.Infoln("Visiting:", r.URL) - }) - - c.Visit("https://steamcommunity.com/app/594650") -}