Compare commits

..

3 Commits

Author SHA1 Message Date
348cd543fc
rename config var 2022-07-27 19:35:13 -05:00
cd783493c9
remove slash commands 2022-07-27 19:34:34 -05:00
df800efc90
add Dockerfile and Makefile 2022-07-26 10:40:45 -05:00
3 changed files with 20 additions and 57 deletions

7
Dockerfile Normal file
View File

@ -0,0 +1,7 @@
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 /

8
Makefile Normal file
View File

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

View File

@ -15,10 +15,9 @@ import (
"syscall"
"git.kill0.net/chill9/beepboop/command"
"github.com/bwmarrin/discordgo"
log "github.com/sirupsen/logrus"
// log "github.com/golang/glog"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
@ -28,45 +27,7 @@ var (
defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"}
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
C Config
)
type (
@ -114,7 +75,7 @@ func main() {
Token, ok := viper.Get("discord_token").(string)
err = viper.Unmarshal(&config)
err = viper.Unmarshal(&C)
if err != nil {
log.Fatalf("unable to decode into struct: %v", err)
}
@ -145,19 +106,6 @@ func main() {
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.")
defer dg.Close()
@ -184,8 +132,8 @@ func reactionHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
return
}
emojis := config.Handler.Reaction.Emojis
channels := config.Handler.Reaction.Channels
emojis := C.Handler.Reaction.Emojis
channels := C.Handler.Reaction.Channels
if len(emojis) == 0 {
log.Warning("emoji list is empty")