remove more slash commands
This commit is contained in:
parent
348cd543fc
commit
b1824f8d33
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user