bot: refactor all rand seeds into main.go

This commit is contained in:
Chris Sexton 2018-07-23 13:00:19 -04:00
parent 01056f1956
commit e15122cfe9
9 changed files with 4 additions and 26 deletions

View File

@ -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 // Take an input string and mutate it based on $vars in the string
func (b *bot) Filter(message msg.Message, input string) string { func (b *bot) Filter(message msg.Message, input string) string {
rand.Seed(time.Now().Unix())
if strings.Contains(input, "$NICK") { if strings.Contains(input, "$NICK") {
nick := strings.ToUpper(message.User.Name) nick := strings.ToUpper(message.User.Name)
input = strings.Replace(input, "$NICK", nick, -1) input = strings.Replace(input, "$NICK", nick, -1)

View File

@ -5,6 +5,8 @@ package main
import ( import (
"flag" "flag"
"log" "log"
"math/rand"
"time"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/config" "github.com/velour/catbase/config"
@ -37,6 +39,8 @@ import (
) )
func main() { func main() {
rand.Seed(time.Now().Unix())
var cfile = flag.String("config", "config.lua", var cfile = flag.String("config", "config.lua",
"Config file to load. (Defaults to config.lua)") "Config file to load. (Defaults to config.lua)")
flag.Parse() // parses the logging flags. flag.Parse() // parses the logging flags.

View File

@ -4,9 +4,7 @@ package admin
import ( import (
"log" "log"
"math/rand"
"strings" "strings"
"time"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
@ -95,7 +93,6 @@ func (p *AdminPlugin) handleVariables(message msg.Message) bool {
// date. // date.
func (p *AdminPlugin) LoadData() { func (p *AdminPlugin) LoadData() {
// This bot has no data to load // This bot has no data to load
rand.Seed(time.Now().Unix())
} }
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.

View File

@ -3,8 +3,6 @@
package dice package dice
import ( import (
"time"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
) )
@ -22,8 +20,6 @@ type DicePlugin struct {
// NewDicePlugin creates a new DicePlugin with the Plugin interface // NewDicePlugin creates a new DicePlugin with the Plugin interface
func New(bot bot.Bot) *DicePlugin { func New(bot bot.Bot) *DicePlugin {
rand.Seed(time.Now().Unix())
return &DicePlugin{ return &DicePlugin{
Bot: bot, Bot: bot,
} }

View File

@ -9,7 +9,6 @@ import (
"math/rand" "math/rand"
"net/http" "net/http"
"strings" "strings"
"time"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
@ -22,8 +21,6 @@ type EmojifyMePlugin struct {
} }
func New(bot bot.Bot) *EmojifyMePlugin { 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") resp, err := http.Get("https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json")
if err != nil { if err != nil {
log.Fatalf("Error generic emoji list: %s", err) log.Fatalf("Error generic emoji list: %s", err)

View File

@ -4,7 +4,6 @@ package picker
import ( import (
"strings" "strings"
"time"
"fmt" "fmt"
"math/rand" "math/rand"
@ -19,17 +18,11 @@ type PickerPlugin struct {
// NewPickerPlugin creates a new PickerPlugin with the Plugin interface // NewPickerPlugin creates a new PickerPlugin with the Plugin interface
func New(bot bot.Bot) *PickerPlugin { func New(bot bot.Bot) *PickerPlugin {
rand.Seed(time.Now().Unix())
return &PickerPlugin{ return &PickerPlugin{
Bot: bot, Bot: bot,
} }
} }
func rollDie(sides int) int {
return rand.Intn(sides) + 1
}
// Message responds to the bot hook on recieving messages. // 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. // 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. // Otherwise, the function returns false and the bot continues execution of other plugins.

View File

@ -4,7 +4,6 @@ package reaction
import ( import (
"math/rand" "math/rand"
"time"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
@ -17,8 +16,6 @@ type ReactionPlugin struct {
} }
func New(bot bot.Bot) *ReactionPlugin { func New(bot bot.Bot) *ReactionPlugin {
rand.Seed(time.Now().Unix())
return &ReactionPlugin{ return &ReactionPlugin{
Bot: bot, Bot: bot,
Config: bot.Config(), Config: bot.Config(),

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"strings" "strings"
"time"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
@ -47,7 +46,6 @@ type TalkerPlugin struct {
} }
func New(bot bot.Bot) *TalkerPlugin { func New(bot bot.Bot) *TalkerPlugin {
rand.Seed(time.Now().Unix())
return &TalkerPlugin{ return &TalkerPlugin{
Bot: bot, Bot: bot,
enforceNicks: bot.Config().EnforceNicks, enforceNicks: bot.Config().EnforceNicks,

View File

@ -5,7 +5,6 @@ package your
import ( import (
"math/rand" "math/rand"
"strings" "strings"
"time"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
@ -19,7 +18,6 @@ type YourPlugin struct {
// NewYourPlugin creates a new YourPlugin with the Plugin interface // NewYourPlugin creates a new YourPlugin with the Plugin interface
func New(bot bot.Bot) *YourPlugin { func New(bot bot.Bot) *YourPlugin {
rand.Seed(time.Now().Unix())
return &YourPlugin{ return &YourPlugin{
bot: bot, bot: bot,
config: bot.Config(), config: bot.Config(),