bb/bot/roulette.go

85 lines
1.1 KiB
Go
Raw Permalink Normal View History

package bot
2022-08-25 15:00:43 +00:00
import (
"git.kill0.net/chill9/beepboop/lib"
"github.com/bwmarrin/discordgo"
2022-08-25 15:00:43 +00:00
log "github.com/sirupsen/logrus"
)
const (
Bullets = 1
GunFireMessage = "💀🔫"
GunClickMessage = "😌🔫"
)
type (
Gun struct {
C [6]bool
N int
}
)
var (
gun *Gun
)
func init() {
gun = NewGun()
}
func NewGun() *Gun {
return new(Gun)
}
func (g *Gun) Load(n int) {
g.N = 0
for i := 1; i <= n; {
x := lib.RandInt(0, len(g.C)-1)
2022-09-07 05:54:58 +00:00
if !g.C[x] {
2022-08-25 15:00:43 +00:00
g.C[x] = true
i++
} else {
continue
}
}
}
func (g *Gun) Fire() bool {
if g.C[g.N] {
g.C[g.N] = false
g.N++
return true
}
g.N++
return false
}
func (g *Gun) IsEmpty() bool {
for _, v := range g.C {
2022-09-07 05:54:58 +00:00
if v {
2022-08-25 15:00:43 +00:00
return false
}
}
return true
}
func (b *Bot) RouletteCommand() CommandFunc {
return func(args []string, m *discordgo.MessageCreate) error {
if gun.IsEmpty() {
gun.Load(Bullets)
log.Debugf("reloading gun: %+v\n", gun)
}
2022-08-25 15:00:43 +00:00
log.Debugf("firing gun: %+v\n", gun)
if gun.Fire() {
b.Session.ChannelMessageSend(m.ChannelID, GunFireMessage)
} else {
b.Session.ChannelMessageSend(m.ChannelID, GunClickMessage)
}
return nil
2022-08-25 15:00:43 +00:00
}
}