From b1824f8d3355274a57448db63c3e11e20d7d4aa6 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Wed, 27 Jul 2022 21:58:38 -0500 Subject: [PATCH] remove more slash commands --- cmd/bb/main.go | 9 +++++- command/ping.go | 18 ------------ command/random.go | 72 ++++++++++++++++++----------------------------- 3 files changed, 36 insertions(+), 63 deletions(-) diff --git a/cmd/bb/main.go b/cmd/bb/main.go index a0fb641..f5aa9f4 100644 --- a/cmd/bb/main.go +++ b/cmd/bb/main.go @@ -36,7 +36,8 @@ type ( } HandlerConfig struct { - Reaction ReactionConfig `mapstructure:"reaction"` + Reaction ReactionConfig `mapstructure:"reaction"` + Weather command.WeatherConfig `mapstructure:"weather"` } ReactionConfig struct { @@ -99,6 +100,12 @@ func main() { dg.AddHandler(command.RollHandler) dg.AddHandler(command.RouletteHandler) + h := command.NewWeatherHandler(C.Handler.Weather) + dg.AddHandler(h.Handle) + + dg.AddHandler(command.NewCoinHandler().Handle) + dg.AddHandler(command.NewTimeHandler().Handle) + dg.Identify.Intents = discordgo.IntentsGuildMessages err = dg.Open() diff --git a/command/ping.go b/command/ping.go index b5b1791..07e9faf 100644 --- a/command/ping.go +++ b/command/ping.go @@ -8,24 +8,6 @@ import ( log "github.com/sirupsen/logrus" ) -func PoopCommand(s *discordgo.Session, i *discordgo.InteractionCreate) { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "💩", - }, - }) -} - -func PingCommand(s *discordgo.Session, i *discordgo.InteractionCreate) { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: "Pong", - }, - }) -} - func PingHandler(s *discordgo.Session, m *discordgo.MessageCreate) { if m.Author.ID == s.State.User.ID { return diff --git a/command/random.go b/command/random.go index c7d11a0..de4b0b2 100644 --- a/command/random.go +++ b/command/random.go @@ -28,10 +28,14 @@ type ( S string } + Coin bool + Gun struct { C [6]bool N int } + + CoinHandler struct{} ) var ( @@ -94,6 +98,11 @@ func (r *Roll) RollDice() { } } +func (c *Coin) Flip() bool { + *c = Coin(Itob(RandInt(0, 1))) + return bool(*c) +} + func NewGun() *Gun { return new(Gun) } @@ -192,64 +201,31 @@ func RouletteHandler(s *discordgo.Session, m *discordgo.MessageCreate) { } } -func RollCommand(s *discordgo.Session, i *discordgo.InteractionCreate) { +func NewCoinHandler() *CoinHandler { + return new(CoinHandler) +} + +func (h *CoinHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) { var ( - err error + c Coin msg string - r *Roll ) - options := i.ApplicationCommandData().Options - - roll := options[0].StringValue() - - r, err = ParseRoll(roll) - - if err != nil { - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: err.Error(), - }, - }) + if m.Author.ID == s.State.User.ID { return } - r.RollDice() - log.Debugf("rolled dice: %+v", r) - - if msg == "" { - msg = fmt.Sprintf("🎲 %s = %d", JoinInt(r.Rolls, " + "), r.Sum) + if !strings.HasPrefix(m.Content, "!coin") { + return } - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: msg, - }, - }) -} - -func CoinCommand(s *discordgo.Session, i *discordgo.InteractionCreate) { - var ( - r int - msg string - ) - - r = RandInt(1, 2) - - if r == 1 { + if c.Flip() { msg = "heads" } else { msg = "tails" } - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: msg, - }, - }) + s.ChannelMessageSend(m.ChannelID, msg) } func RandInt(min int, max int) int { @@ -275,3 +251,11 @@ func SumInt(a []int) int { } return sum } + +func Itob(v int) bool { + if v == 1 { + return true + } + + return false +}