Compare commits

..

No commits in common. "348cd543fcbf85afe3da65e68ff1115c7ddbad9c" and "fde109785102e680286f858c0992d2273680a560" have entirely different histories.

3 changed files with 57 additions and 20 deletions

View File

@ -1,7 +0,0 @@
FROM golang:latest AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build ./cmd/bb
FROM scratch AS bin
COPY --from=build /src/bb /

View File

@ -1,8 +0,0 @@
.PHONY: build
build:
DOCKER_BUILDKIT=1
docker build --target bin --output bin/ .
.PHONY: clean
clean:
rm bin/bb

View File

@ -15,9 +15,10 @@ import (
"syscall" "syscall"
"git.kill0.net/chill9/beepboop/command" "git.kill0.net/chill9/beepboop/command"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
// log "github.com/golang/glog"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -27,7 +28,45 @@ var (
defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"} defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"}
C Config commands = []*discordgo.ApplicationCommand{
{
Name: "poop",
Type: discordgo.ChatApplicationCommand,
Description: "Hot and steamy",
},
{
Name: "ping",
Type: discordgo.ChatApplicationCommand,
Description: "Ping the bot",
},
{
Name: "roll",
Type: discordgo.ChatApplicationCommand,
Description: "Roll a dice",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "dice",
Description: "Dice specification e.g. d4 or 2d6",
Required: true,
},
},
},
{
Name: "coin",
Type: discordgo.ChatApplicationCommand,
Description: "Flip a coin",
},
}
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
"ping": command.PingCommand,
"poop": command.PoopCommand,
"roll": command.RollCommand,
"coin": command.CoinCommand,
}
config Config
) )
type ( type (
@ -75,7 +114,7 @@ func main() {
Token, ok := viper.Get("discord_token").(string) Token, ok := viper.Get("discord_token").(string)
err = viper.Unmarshal(&C) err = viper.Unmarshal(&config)
if err != nil { if err != nil {
log.Fatalf("unable to decode into struct: %v", err) log.Fatalf("unable to decode into struct: %v", err)
} }
@ -106,6 +145,19 @@ func main() {
log.Fatalf("error opening connection: %v\n", err) log.Fatalf("error opening connection: %v\n", err)
} }
for _, c := range commands {
_, err := dg.ApplicationCommandCreate(dg.State.User.ID, "", c)
if err != nil {
log.Errorf("Cannot create '%v' command %v", c.Name, err)
}
}
dg.AddHandler(func(s *discordgo.Session, i *discordgo.InteractionCreate) {
if h, ok := commandHandlers[i.ApplicationCommandData().Name]; ok {
h(s, i)
}
})
log.Info("The bot is now running. Press CTRL-C to exit.") log.Info("The bot is now running. Press CTRL-C to exit.")
defer dg.Close() defer dg.Close()
@ -132,8 +184,8 @@ func reactionHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
return return
} }
emojis := C.Handler.Reaction.Emojis emojis := config.Handler.Reaction.Emojis
channels := C.Handler.Reaction.Channels channels := config.Handler.Reaction.Channels
if len(emojis) == 0 { if len(emojis) == 0 {
log.Warning("emoji list is empty") log.Warning("emoji list is empty")