Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/games.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ or real-money mechanics.
Challenge another nickname and have them accept:

~~~text
!8ball Alex
!9ball Alex
!pool 8 Alex
!pool 9 Alex
!pool accept
!pool decline
~~~

Pool commands are intentionally separate from the magic 8-ball plugin. Use
`!pool 8 <nick>`, `!pool8 <nick>`, or `!8pool <nick>` for 8-ball pool. Use
`!pool 9 <nick>`, `!pool9 <nick>`, or `!9ball <nick>` for 9-ball. Use
`!8ball <question>`, `!8`, or `!eightball` for a magic 8-ball answer.

During a game, the player whose turn it is shoots one numbered ball:

~~~text
Expand All @@ -70,7 +75,8 @@ legal only after the player's assigned group is cleared. In 9-ball, the lowest
remaining ball must be selected first; pocketing the 9-ball wins. A successful
shot keeps the turn, while a miss passes it to the other player.

Aliases include `!8`, `!9ball`, `!9`, `!pool break`, and `!shoot <ball>`.
Aliases include `!pool8`, `!8pool`, `!pool9`, `!9ball`, `!9`, `!pool break`,
and `!shoot <ball>`.
The invited player can use `!pool decline` if they do not want to play.
Use `!poolstats [nick]` for persistent wins and losses or
`!poolleaderboard` for the top five players. Active games are held in memory
Expand Down
3 changes: 3 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ Responses come from quotes/eightball.txt, one per line. Prefix a response with
green|, yellow|, or red| to control its IRC color. Unprefixed responses remain
readable without color. Each request produces one bounded message.

Pool's separate 8-ball mode uses `!pool 8 <nick>`, `!pool8 <nick>`, or
`!8pool <nick>`; `!8ball` is reserved for questions to the magic 8-ball.

## Fun text catalogs

The `fun` plugin provides local text without making an external request. Each
Expand Down
16 changes: 8 additions & 8 deletions plugins/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ type Pool struct {
func (p *Pool) Name() string { return "pool" }

func (p *Pool) Commands() []string {
return []string{"pool", "8ball", "8", "nineball", "9ball", "9", "shoot", "forfeit", "poolstats", "poolleaderboard"}
return []string{"pool", "pool8", "8pool", "pool9", "nineball", "9ball", "9", "shoot", "forfeit", "poolstats", "poolleaderboard"}
}

func (p *Pool) Help() string {
return "!8ball <nick> or !9ball <nick> — challenge someone; !pool accept|status|shoot [ball]|forfeit; !poolstats"
return "!pool 8 <nick> or !pool 9 <nick> — challenge someone; !pool accept|status|shoot [ball]|forfeit; !poolstats"
}

func (p *Pool) Init(c bot.PluginConfig, db *storage.DB) error {
Expand Down Expand Up @@ -141,7 +141,7 @@ func (p *Pool) Handle(b *bot.Bot, m bot.Message) bool {

func poolCommand(command string) bool {
switch strings.ToLower(command) {
case "pool", "8ball", "8", "nineball", "9ball", "9", "shoot", "forfeit", "poolstats", "poolleaderboard":
case "pool", "pool8", "8pool", "pool9", "nineball", "9ball", "9", "shoot", "forfeit", "poolstats", "poolleaderboard":
return true
default:
return false
Expand All @@ -150,9 +150,9 @@ func poolCommand(command string) bool {

func (p *Pool) handleLocked(b *bot.Bot, m bot.Message, key string, game *poolGame, command, arg string) string {
switch command {
case "8ball", "8":
case "pool8", "8pool":
return p.challengeLocked(key, m, poolEightBall, arg)
case "nineball", "9ball", "9":
case "pool9", "nineball", "9ball", "9":
return p.challengeLocked(key, m, poolNineBall, arg)
case "shoot":
return p.shootLocked(m, key, game, arg)
Expand Down Expand Up @@ -197,7 +197,7 @@ func (p *Pool) poolCommandLocked(key string, m bot.Message, game *poolGame, arg

func (p *Pool) challengeLocked(key string, m bot.Message, mode poolMode, rawNick string) string {
if strings.TrimSpace(rawNick) == "" {
return fmt.Sprintf("usage: !%s <nick>", map[poolMode]string{poolEightBall: "8ball", poolNineBall: "9ball"}[mode])
return fmt.Sprintf("usage: !%s <nick>", map[poolMode]string{poolEightBall: "pool 8", poolNineBall: "pool 9"}[mode])
}
nick := strings.TrimSpace(strings.TrimPrefix(rawNick, "@"))
if !validPoolNick(nick) {
Expand Down Expand Up @@ -254,7 +254,7 @@ func (p *Pool) declineLocked(m bot.Message, key string, game *poolGame) string {

func (p *Pool) shootLocked(m bot.Message, key string, game *poolGame, rawBall string) string {
if game == nil || game.Pending {
return "no pool game is active; use !8ball <nick> or !9ball <nick>"
return "no pool game is active; use !pool 8 <nick> or !pool 9 <nick>"
}
player := p.currentPlayer(game)
if !samePoolIdentity(m, player) {
Expand Down Expand Up @@ -319,7 +319,7 @@ func (p *Pool) forfeitLocked(m bot.Message, key string, game *poolGame) string {

func (p *Pool) statusLocked(m bot.Message, game *poolGame) string {
if game == nil {
return "no pool game is active; use !8ball <nick> or !9ball <nick>"
return "no pool game is active; use !pool 8 <nick> or !pool 9 <nick>"
}
if game.Pending {
return fmt.Sprintf("pending %s challenge: %s invited %s; waiting for !pool accept.", game.Mode, game.Players[0].Name, game.Players[1].Name)
Expand Down
8 changes: 7 additions & 1 deletion plugins/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ func TestPoolDefaultsAndCommands(t *testing.T) {
t.Fatalf("unexpected pool defaults: %+v", plugin.cfg)
}
commands := strings.Join(plugin.Commands(), " ")
for _, command := range []string{"pool", "8ball", "8", "9ball", "9", "shoot", "forfeit", "poolstats"} {
for _, command := range []string{"pool", "pool8", "8pool", "pool9", "9ball", "9", "shoot", "forfeit", "poolstats"} {
if !strings.Contains(commands, command) {
t.Fatalf("command %q missing from %q", command, commands)
}
}
if poolCommand("8ball") || poolCommand("8") {
t.Fatal("pool must not claim the magic 8-ball commands")
}
if !poolCommand("pool8") || !poolCommand("8pool") {
t.Fatal("pool 8 aliases are not registered correctly")
}
}

func TestPoolBallSets(t *testing.T) {
Expand Down