Compare commits
3 Commits
fde1097851
...
348cd543fc
Author | SHA1 | Date | |
---|---|---|---|
348cd543fc | |||
cd783493c9 | |||
df800efc90 |
7
Dockerfile
Normal file
7
Dockerfile
Normal 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
8
Makefile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.PHONY: build
|
||||||
|
build:
|
||||||
|
DOCKER_BUILDKIT=1
|
||||||
|
docker build --target bin --output bin/ .
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm bin/bb
|
@ -15,10 +15,9 @@ 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"
|
||||||
)
|
)
|
||||||
@ -28,45 +27,7 @@ var (
|
|||||||
|
|
||||||
defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"}
|
defaultReactions []string = []string{"👍", "🌶️", "🤣", "😂", "🍆", "🍑", "❤️", "💦", "😍", "💩", "🔥", "🍒", "🎉", "🥳", "🎊"}
|
||||||
|
|
||||||
commands = []*discordgo.ApplicationCommand{
|
C Config
|
||||||
{
|
|
||||||
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 (
|
||||||
@ -114,7 +75,7 @@ func main() {
|
|||||||
|
|
||||||
Token, ok := viper.Get("discord_token").(string)
|
Token, ok := viper.Get("discord_token").(string)
|
||||||
|
|
||||||
err = viper.Unmarshal(&config)
|
err = viper.Unmarshal(&C)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to decode into struct: %v", err)
|
log.Fatalf("unable to decode into struct: %v", err)
|
||||||
}
|
}
|
||||||
@ -145,19 +106,6 @@ 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()
|
||||||
@ -184,8 +132,8 @@ func reactionHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
emojis := config.Handler.Reaction.Emojis
|
emojis := C.Handler.Reaction.Emojis
|
||||||
channels := config.Handler.Reaction.Channels
|
channels := C.Handler.Reaction.Channels
|
||||||
|
|
||||||
if len(emojis) == 0 {
|
if len(emojis) == 0 {
|
||||||
log.Warning("emoji list is empty")
|
log.Warning("emoji list is empty")
|
||||||
|
Loading…
Reference in New Issue
Block a user