From 6fc7b60d3d5aff626803387f83d8104596effcef Mon Sep 17 00:00:00 2001 From: Michael McCarty Date: Thu, 2 Apr 2026 13:23:07 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feat:=20replace=20mobygenerator=20with?= =?UTF-8?q?=20local=20bottools.GetRandomName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 - go.sum | 2 -- src/boost/boost_reactions.go | 4 ++-- src/boost/contract.go | 5 ++--- src/boost/roles.go | 10 +++++----- src/bottools/random_name.go | 23 +++++++++++++++++++++++ src/track/track_slashcmd.go | 4 +--- 7 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 src/bottools/random_name.go diff --git a/go.mod b/go.mod index 2db9f17a..8fb33d98 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/google/go-github/v33 v33.0.0 github.com/jasonlvhit/gocron v0.0.1 github.com/mattn/go-runewidth v0.0.21 - github.com/moby/moby v28.5.2+incompatible github.com/natefinch/lumberjack/v3 v3.0.0-alpha github.com/peterbourgon/diskv/v3 v3.0.1 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index a3f5cbc1..a545c701 100644 --- a/go.sum +++ b/go.sum @@ -69,8 +69,6 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.21 h1:jJKAZiQH+2mIinzCJIaIG9Be1+0NR+5sz/lYEEjdM8w= github.com/mattn/go-runewidth v0.0.21/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= -github.com/moby/moby v28.5.2+incompatible h1:hIn6qcenb3JY1E3STwqEbBvJ8bha+u1LpqjX4CBvNCk= -github.com/moby/moby v28.5.2+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc= github.com/natefinch/lumberjack/v3 v3.0.0-alpha h1:HZ2AJF20D1lo9S0F/rpgkFbPGam5dgR3X0KUtZA5mlY= github.com/natefinch/lumberjack/v3 v3.0.0-alpha/go.mod h1:rPTlHhMjhrvPAhqKh0FC57E0pXZoanrXgMDj4yv5wcM= github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= diff --git a/src/boost/boost_reactions.go b/src/boost/boost_reactions.go index 198275e8..0717d48a 100644 --- a/src/boost/boost_reactions.go +++ b/src/boost/boost_reactions.go @@ -7,12 +7,12 @@ import ( "strings" "time" + "github.com/mkmccarty/TokenTimeBoostBot/src/bottools" "github.com/mkmccarty/TokenTimeBoostBot/src/ei" "github.com/mkmccarty/TokenTimeBoostBot/src/farmerstate" "github.com/mkmccarty/TokenTimeBoostBot/src/track" "github.com/bwmarrin/discordgo" - "github.com/moby/moby/pkg/namesgenerator" ) // ReactionAdd is called when a reaction is added to a message @@ -180,7 +180,7 @@ func ReactionAdd(s *discordgo.Session, r *discordgo.MessageReaction) string { case "🐿️": if creatorOfContract(s, contract, r.UserID) { for i := len(contract.Order); i < contract.CoopSize; i++ { - _, err := AddFarmerToContract(s, contract, r.GuildID, r.ChannelID, namesgenerator.GetRandomName(0), contract.BoostOrder, true) + _, err := AddFarmerToContract(s, contract, r.GuildID, r.ChannelID, bottools.GetRandomName(0), contract.BoostOrder, true) if err != nil { log.Println(err) } diff --git a/src/boost/contract.go b/src/boost/contract.go index 935e5871..02c2b4be 100644 --- a/src/boost/contract.go +++ b/src/boost/contract.go @@ -16,7 +16,6 @@ import ( "github.com/mkmccarty/TokenTimeBoostBot/src/ei" "github.com/bwmarrin/discordgo" - "github.com/moby/moby/pkg/namesgenerator" ) // GetSlashContractCommand returns the slash command for creating a contract @@ -456,7 +455,7 @@ func CreateContract(s *discordgo.Session, contractID string, coopID string, play // Try a number of random docker-style names first for attempt := 0; attempt < 64; attempt++ { - cand := namesgenerator.GetRandomName(0) + cand := bottools.GetRandomName(0) if Contracts[cand] == nil { ContractHash = cand break @@ -465,7 +464,7 @@ func CreateContract(s *discordgo.Session, contractID string, coopID string, play // Fallback: append a short random suffix to guarantee uniqueness if ContractHash == "" { - base := namesgenerator.GetRandomName(0) + base := bottools.GetRandomName(0) for { suffix := strconv.FormatUint(rand.Uint64(), 36) if len(suffix) > 6 { diff --git a/src/boost/roles.go b/src/boost/roles.go index 661cc6ec..3d130f92 100644 --- a/src/boost/roles.go +++ b/src/boost/roles.go @@ -10,9 +10,9 @@ import ( "sync" "github.com/bwmarrin/discordgo" + "github.com/mkmccarty/TokenTimeBoostBot/src/bottools" "github.com/mkmccarty/TokenTimeBoostBot/src/config" "github.com/mkmccarty/TokenTimeBoostBot/src/ei" - "github.com/moby/moby/pkg/namesgenerator" "google.golang.org/genai" ) @@ -115,7 +115,7 @@ func getContractRoleName(contractID string) string { if len(unusedRoleNames) == 0 { // All names are taken; fall back to a generated team name - teamName = namesgenerator.GetRandomName(0) + teamName = bottools.GetRandomName(0) prefix = "Team " } else { lastChance := false @@ -151,7 +151,7 @@ func getContractRoleName(contractID string) string { } } if teamName == "" { - teamName = namesgenerator.GetRandomName(0) + teamName = bottools.GetRandomName(0) } } @@ -204,7 +204,7 @@ func getContractRole(s *discordgo.Session, guildID string, contract *Contract) e if len(unusedRoleNames) == 0 { // All names are taken; fall back to a generated team name - teamName = namesgenerator.GetRandomName(0) + teamName = bottools.GetRandomName(0) prefix = "Team " } else { lastChance := false @@ -240,7 +240,7 @@ func getContractRole(s *discordgo.Session, guildID string, contract *Contract) e } } if teamName == "" { - teamName = namesgenerator.GetRandomName(0) + teamName = bottools.GetRandomName(0) } } diff --git a/src/bottools/random_name.go b/src/bottools/random_name.go new file mode 100644 index 00000000..8ed5501e --- /dev/null +++ b/src/bottools/random_name.go @@ -0,0 +1,23 @@ +package bottools + +import ( + "fmt" + "math/rand/v2" +) + +var randomNameLeft = []string{ + "brisk", "calm", "clever", "cosmic", "crisp", "daring", "gentle", "lucky", "mellow", "nimble", + "quiet", "rapid", "savvy", "steady", "swift", "vivid", "witty", "bold", "bright", "chill", +} + +var randomNameRight = []string{ + "acorn", "anchor", "aster", "beacon", "bison", "comet", "drifter", "falcon", "harbor", "meadow", + "nebula", "otter", "ranger", "rocket", "sailor", "sprout", "thunder", "valley", "voyager", "zephyr", +} + +// GetRandomName returns a docker-style random name. +func GetRandomName(_ int) string { + left := randomNameLeft[rand.IntN(len(randomNameLeft))] + right := randomNameRight[rand.IntN(len(randomNameRight))] + return fmt.Sprintf("%s_%s", left, right) +} diff --git a/src/track/track_slashcmd.go b/src/track/track_slashcmd.go index 36a5522b..6a862304 100644 --- a/src/track/track_slashcmd.go +++ b/src/track/track_slashcmd.go @@ -11,7 +11,6 @@ import ( "github.com/mkmccarty/TokenTimeBoostBot/src/bottools" "github.com/mkmccarty/TokenTimeBoostBot/src/ei" "github.com/mkmccarty/TokenTimeBoostBot/src/farmerstate" - "github.com/moby/moby/pkg/namesgenerator" "github.com/rs/xid" "github.com/xhit/go-str2duration/v2" ) @@ -158,8 +157,7 @@ func HandleTokenCommand(s *discordgo.Session, i *discordgo.InteractionCreate, co if opt, ok := optionMap["coop-id"]; ok { trackingName = strings.TrimSpace(opt.StringValue()) } else if trackingName == "" { - - trackingName = fmt.Sprintln(namesgenerator.GetRandomName(0)) + trackingName = bottools.GetRandomName(0) } if opt, ok := optionMap["linked"]; ok {