From 45562030ce704d544191d2d79b23fde70ab03117 Mon Sep 17 00:00:00 2001 From: Dana Merrick Date: Sat, 3 Apr 2021 22:13:33 -0400 Subject: [PATCH 1/3] Replacing math/rand with crypto/rand --- cmd/tripbot/tripbot.go | 2 +- cmd/vlc-server/vlc-server.go | 2 +- pkg/chatbot/commands.go | 6 +++--- pkg/onscreens-server/left-rotator.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/tripbot/tripbot.go b/cmd/tripbot/tripbot.go index fccb96d1..3f3e7a72 100644 --- a/cmd/tripbot/tripbot.go +++ b/cmd/tripbot/tripbot.go @@ -1,9 +1,9 @@ package main import ( + "crypto/rand" "fmt" "log" - "math/rand" "os" "os/signal" "syscall" diff --git a/cmd/vlc-server/vlc-server.go b/cmd/vlc-server/vlc-server.go index 86c2174e..c00089ed 100644 --- a/cmd/vlc-server/vlc-server.go +++ b/cmd/vlc-server/vlc-server.go @@ -1,8 +1,8 @@ package main import ( + "crypto/rand" "log" - "math/rand" "os" "os/signal" "syscall" diff --git a/pkg/chatbot/commands.go b/pkg/chatbot/commands.go index ca32c31f..e32e1f1a 100644 --- a/pkg/chatbot/commands.go +++ b/pkg/chatbot/commands.go @@ -1,10 +1,10 @@ package chatbot import ( + "crypto/rand" "fmt" "log" "math" - "math/rand" "os" "os/exec" "path/filepath" @@ -57,8 +57,8 @@ func helloCmd(user *users.User, params []string) { // say a random greeting back, with random punctuation greetings := []string{"Hello", "Hey", "Hi"} punctuation := []string{"!", ".", ".", "."} - msg := greetings[rand.Intn(len(greetings))] - msg += punctuation[rand.Intn(len(punctuation))] + msg := greetings[rand.Int(len(greetings))] + msg += punctuation[rand.Int(len(punctuation))] // give a little help message if the user is new if user.CurrentMiles() < 2.0 { diff --git a/pkg/onscreens-server/left-rotator.go b/pkg/onscreens-server/left-rotator.go index 32e504cc..0b8a474c 100644 --- a/pkg/onscreens-server/left-rotator.go +++ b/pkg/onscreens-server/left-rotator.go @@ -1,8 +1,8 @@ package onscreensServer import ( + "crypto/rand" "log" - "math/rand" "path/filepath" "time" @@ -48,7 +48,7 @@ func leftRotatorContent() string { var output string // show a special, very rare message - if rand.Intn(10000) == 0 { + if rand.Int(10000) == 0 { return "You found the rare message! Make a clip for a prize!" } From ab78944da74b553fed424d91b01dffc01861cbd8 Mon Sep 17 00:00:00 2001 From: Dana Merrick Date: Sat, 3 Apr 2021 22:14:52 -0400 Subject: [PATCH 2/3] Adding more --- pkg/chatbot/chatbot.go | 2 +- pkg/onscreens-server/right-rotator.go | 2 +- pkg/vlc-server/playback.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/chatbot/chatbot.go b/pkg/chatbot/chatbot.go index 01a1d311..f5dcd311 100644 --- a/pkg/chatbot/chatbot.go +++ b/pkg/chatbot/chatbot.go @@ -1,9 +1,9 @@ package chatbot import ( + "crypto/rand" "fmt" "log" - "math/rand" "time" mylog "github.com/adanalife/tripbot/pkg/chatbot/log" diff --git a/pkg/onscreens-server/right-rotator.go b/pkg/onscreens-server/right-rotator.go index 310b166f..5acf30bd 100644 --- a/pkg/onscreens-server/right-rotator.go +++ b/pkg/onscreens-server/right-rotator.go @@ -1,8 +1,8 @@ package onscreensServer import ( + "crypto/rand" "log" - "math/rand" "path/filepath" "time" diff --git a/pkg/vlc-server/playback.go b/pkg/vlc-server/playback.go index ff63efec..59a52c2c 100644 --- a/pkg/vlc-server/playback.go +++ b/pkg/vlc-server/playback.go @@ -1,8 +1,8 @@ package vlcServer import ( + "crypto/rand" "errors" - "math/rand" "path/filepath" terrors "github.com/adanalife/tripbot/pkg/errors" From 69111a00e5f9b07a595c8c21bdd707e772874c68 Mon Sep 17 00:00:00 2001 From: Dana Merrick Date: Sat, 3 Apr 2021 22:17:22 -0400 Subject: [PATCH 3/3] More updates --- cmd/tripbot/tripbot.go | 8 -------- cmd/vlc-server/vlc-server.go | 4 ---- pkg/chatbot/chatbot.go | 2 +- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/cmd/tripbot/tripbot.go b/cmd/tripbot/tripbot.go index 3f3e7a72..5cbdc7d9 100644 --- a/cmd/tripbot/tripbot.go +++ b/cmd/tripbot/tripbot.go @@ -1,7 +1,6 @@ package main import ( - "crypto/rand" "fmt" "log" "os" @@ -30,7 +29,6 @@ var client *twitch.Client // main performs the various steps to get the bot running func main() { - createRandomSeed() listenForShutdown() initializeErrorLogger() startHttpServer() @@ -44,12 +42,6 @@ func main() { connectToTwitch() } -// createRandomSeed ensures that random numbers will be random -func createRandomSeed() { - // create a brand new random seed - rand.Seed(time.Now().UnixNano()) -} - // listenForShutdown creates a background job that listens for a graceful shutdown request func listenForShutdown() { helpers.WritePidFile(c.Conf.TripbotPidFile) diff --git a/cmd/vlc-server/vlc-server.go b/cmd/vlc-server/vlc-server.go index c00089ed..1a73b10e 100644 --- a/cmd/vlc-server/vlc-server.go +++ b/cmd/vlc-server/vlc-server.go @@ -1,7 +1,6 @@ package main import ( - "crypto/rand" "log" "os" "os/signal" @@ -24,9 +23,6 @@ func main() { log.Fatal("This doesn't yet work on darwin") } - // create a brand new random seed - rand.Seed(time.Now().UnixNano()) - // write the current pid to a pidfile helpers.WritePidFile(c.Conf.VLCPidFile) diff --git a/pkg/chatbot/chatbot.go b/pkg/chatbot/chatbot.go index f5dcd311..814ac42c 100644 --- a/pkg/chatbot/chatbot.go +++ b/pkg/chatbot/chatbot.go @@ -25,7 +25,7 @@ var Uptime time.Time // used to determine which help message to display // randomized so it starts with a new one every restart -var helpIndex = rand.Intn(len(c.HelpMessages)) +var helpIndex = rand.Int(len(c.HelpMessages)) const followerMsg = "Follow the stream to run unlimited commands :)" const subscriberMsg = "You must be a subscriber to run that command :)"