-
Notifications
You must be signed in to change notification settings - Fork 3
✨feat: replace mobygenerator with local bottools.GetRandomName #2306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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", | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+8
to
+16
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // GetRandomName returns a docker-style random name. | ||||||||||||||||||||||||||||||||
| func GetRandomName(_ int) string { | ||||||||||||||||||||||||||||||||
| left := randomNameLeft[rand.IntN(len(randomNameLeft))] | ||||||||||||||||||||||||||||||||
| right := randomNameRight[rand.IntN(len(randomNameRight))] | ||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+21
|
||||||||||||||||||||||||||||||||
| func GetRandomName(_ int) string { | |
| left := randomNameLeft[rand.IntN(len(randomNameLeft))] | |
| right := randomNameRight[rand.IntN(len(randomNameRight))] | |
| // If seed is non-zero, the returned name is deterministic for that seed. | |
| // If seed is zero, a non-deterministic package-level generator is used. | |
| func GetRandomName(seed int) string { | |
| if seed == 0 { | |
| left := randomNameLeft[rand.IntN(len(randomNameLeft))] | |
| right := randomNameRight[rand.IntN(len(randomNameRight))] | |
| return fmt.Sprintf("%s_%s", left, right) | |
| } | |
| r := rand.New(rand.NewPCG(uint64(seed), uint64(seed)^0x9e3779b97f4a7c15)) | |
| left := randomNameLeft[r.IntN(len(randomNameLeft))] | |
| right := randomNameRight[r.IntN(len(randomNameRight))] |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a new random-name generator that is now used in several user-visible/code-path identifiers. Since the repo runs go test -race ./... in CI and src/bottools already has tests, please add unit coverage for GetRandomName (at least: format invariants, non-empty output, and—if a seed parameter is supported—deterministic output for a fixed seed) to prevent accidental regressions.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||
|
||||||
| trackingName = bottools.GetRandomName(0) | |
| trackingName = fmt.Sprintf("%s-%s", bottools.GetRandomName(0), xid.New().String()[:6]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
🐿️autofill loop incrementsiregardless of whetherAddFarmerToContractactually added a new booster. With random-name IDs, collisions can causeAddFarmerToContractto no-op (existing booster) and the loop will finish with fewer thancontract.CoopSizemembers. Generate IDs guaranteed-unique for the contract (e.g., retry untilcontract.Boosters[cand]==nil, or append a short random suffix/xid).