2022-09-06 05:00:47 +00:00
|
|
|
package commands
|
2022-08-25 15:00:43 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"git.kill0.net/chill9/beepboop/bot"
|
|
|
|
"git.kill0.net/chill9/beepboop/lib"
|
|
|
|
|
|
|
|
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)
|
|
|
|
if g.C[x] == false {
|
|
|
|
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 {
|
|
|
|
if v == true {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-09-06 05:00:47 +00:00
|
|
|
func RouletteCommand(cmd *bot.Command, args []string) error {
|
2022-08-25 15:00:43 +00:00
|
|
|
if gun.IsEmpty() {
|
|
|
|
gun.Load(Bullets)
|
|
|
|
log.Debugf("reloading gun: %+v\n", gun)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debugf("firing gun: %+v\n", gun)
|
|
|
|
if gun.Fire() {
|
2022-09-06 05:00:47 +00:00
|
|
|
cmd.Session.ChannelMessageSend(cmd.Message.ChannelID, GunFireMessage)
|
2022-08-25 15:00:43 +00:00
|
|
|
} else {
|
2022-09-06 05:00:47 +00:00
|
|
|
cmd.Session.ChannelMessageSend(cmd.Message.ChannelID, GunClickMessage)
|
2022-08-25 15:00:43 +00:00
|
|
|
}
|
2022-09-06 05:00:47 +00:00
|
|
|
return nil
|
2022-08-25 15:00:43 +00:00
|
|
|
}
|