From e15122cfe971d0ae5d61e12b22bec021f9677339 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Mon, 23 Jul 2018 13:00:19 -0400 Subject: [PATCH] bot: refactor all rand seeds into main.go --- bot/handlers.go | 2 -- main.go | 4 ++++ plugins/admin/admin.go | 3 --- plugins/dice/dice.go | 4 ---- plugins/emojifyme/emojifyme.go | 3 --- plugins/picker/picker.go | 7 ------- plugins/reaction/reaction.go | 3 --- plugins/talker/talker.go | 2 -- plugins/your/your.go | 2 -- 9 files changed, 4 insertions(+), 26 deletions(-) diff --git a/bot/handlers.go b/bot/handlers.go index 16eccd8..cd01bb0 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -137,8 +137,6 @@ func (b *bot) LastMessage(channel string) (msg.Message, error) { // Take an input string and mutate it based on $vars in the string func (b *bot) Filter(message msg.Message, input string) string { - rand.Seed(time.Now().Unix()) - if strings.Contains(input, "$NICK") { nick := strings.ToUpper(message.User.Name) input = strings.Replace(input, "$NICK", nick, -1) diff --git a/main.go b/main.go index da07f0b..a71b78b 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ package main import ( "flag" "log" + "math/rand" + "time" "github.com/velour/catbase/bot" "github.com/velour/catbase/config" @@ -37,6 +39,8 @@ import ( ) func main() { + rand.Seed(time.Now().Unix()) + var cfile = flag.String("config", "config.lua", "Config file to load. (Defaults to config.lua)") flag.Parse() // parses the logging flags. diff --git a/plugins/admin/admin.go b/plugins/admin/admin.go index 1113bdd..ae624b2 100644 --- a/plugins/admin/admin.go +++ b/plugins/admin/admin.go @@ -4,9 +4,7 @@ package admin import ( "log" - "math/rand" "strings" - "time" "github.com/jmoiron/sqlx" "github.com/velour/catbase/bot" @@ -95,7 +93,6 @@ func (p *AdminPlugin) handleVariables(message msg.Message) bool { // date. func (p *AdminPlugin) LoadData() { // This bot has no data to load - rand.Seed(time.Now().Unix()) } // Help responds to help requests. Every plugin must implement a help function. diff --git a/plugins/dice/dice.go b/plugins/dice/dice.go index 92c613e..104e016 100644 --- a/plugins/dice/dice.go +++ b/plugins/dice/dice.go @@ -3,8 +3,6 @@ package dice import ( - "time" - "github.com/velour/catbase/bot" "github.com/velour/catbase/bot/msg" ) @@ -22,8 +20,6 @@ type DicePlugin struct { // NewDicePlugin creates a new DicePlugin with the Plugin interface func New(bot bot.Bot) *DicePlugin { - rand.Seed(time.Now().Unix()) - return &DicePlugin{ Bot: bot, } diff --git a/plugins/emojifyme/emojifyme.go b/plugins/emojifyme/emojifyme.go index 4ee9282..e6e3e11 100644 --- a/plugins/emojifyme/emojifyme.go +++ b/plugins/emojifyme/emojifyme.go @@ -9,7 +9,6 @@ import ( "math/rand" "net/http" "strings" - "time" "github.com/velour/catbase/bot" "github.com/velour/catbase/bot/msg" @@ -22,8 +21,6 @@ type EmojifyMePlugin struct { } func New(bot bot.Bot) *EmojifyMePlugin { - rand.Seed(time.Now().Unix()) - resp, err := http.Get("https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json") if err != nil { log.Fatalf("Error generic emoji list: %s", err) diff --git a/plugins/picker/picker.go b/plugins/picker/picker.go index 93bc237..c242f6e 100644 --- a/plugins/picker/picker.go +++ b/plugins/picker/picker.go @@ -4,7 +4,6 @@ package picker import ( "strings" - "time" "fmt" "math/rand" @@ -19,17 +18,11 @@ type PickerPlugin struct { // NewPickerPlugin creates a new PickerPlugin with the Plugin interface func New(bot bot.Bot) *PickerPlugin { - rand.Seed(time.Now().Unix()) - return &PickerPlugin{ Bot: bot, } } -func rollDie(sides int) int { - return rand.Intn(sides) + 1 -} - // Message responds to the bot hook on recieving messages. // This function returns true if the plugin responds in a meaningful way to the users message. // Otherwise, the function returns false and the bot continues execution of other plugins. diff --git a/plugins/reaction/reaction.go b/plugins/reaction/reaction.go index aacdbb0..266a4ab 100644 --- a/plugins/reaction/reaction.go +++ b/plugins/reaction/reaction.go @@ -4,7 +4,6 @@ package reaction import ( "math/rand" - "time" "github.com/velour/catbase/bot" "github.com/velour/catbase/bot/msg" @@ -17,8 +16,6 @@ type ReactionPlugin struct { } func New(bot bot.Bot) *ReactionPlugin { - rand.Seed(time.Now().Unix()) - return &ReactionPlugin{ Bot: bot, Config: bot.Config(), diff --git a/plugins/talker/talker.go b/plugins/talker/talker.go index 17e9d1b..143e17b 100644 --- a/plugins/talker/talker.go +++ b/plugins/talker/talker.go @@ -6,7 +6,6 @@ import ( "fmt" "math/rand" "strings" - "time" "github.com/velour/catbase/bot" "github.com/velour/catbase/bot/msg" @@ -47,7 +46,6 @@ type TalkerPlugin struct { } func New(bot bot.Bot) *TalkerPlugin { - rand.Seed(time.Now().Unix()) return &TalkerPlugin{ Bot: bot, enforceNicks: bot.Config().EnforceNicks, diff --git a/plugins/your/your.go b/plugins/your/your.go index c8805b2..810b6fe 100644 --- a/plugins/your/your.go +++ b/plugins/your/your.go @@ -5,7 +5,6 @@ package your import ( "math/rand" "strings" - "time" "github.com/velour/catbase/bot" "github.com/velour/catbase/bot/msg" @@ -19,7 +18,6 @@ type YourPlugin struct { // NewYourPlugin creates a new YourPlugin with the Plugin interface func New(bot bot.Bot) *YourPlugin { - rand.Seed(time.Now().Unix()) return &YourPlugin{ bot: bot, config: bot.Config(),