From c257a8df75a2510792ffb76a73da78b6efe8f17e Mon Sep 17 00:00:00 2001 From: Justin Judd Date: Sun, 6 Jul 2025 13:49:27 -0700 Subject: [PATCH] Moved code to top-level folder, and created dockerfile to containerize the bot. --- Dockerfile | 18 ++++++++++++++++++ voice_announce/main.go => main.go | 15 +++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Dockerfile rename voice_announce/main.go => main.go (87%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e674d14 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:1.24.1-alpine AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 go build -o /app/bot . + +FROM gcr.io/distroless/static-debian11:latest + +WORKDIR /app + +COPY --from=builder /app/bot . + +CMD ["./bot --conf data/.env"] \ No newline at end of file diff --git a/voice_announce/main.go b/main.go similarity index 87% rename from voice_announce/main.go rename to main.go index bbbaa9c..e409dad 100644 --- a/voice_announce/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "log" "math/rand/v2" @@ -17,16 +18,23 @@ var botToken string var announceChannelName string var cleanDelay = 30 +var confFile string + +func init() { + flag.StringVar(&confFile, "conf", ".env", ".env file w/ config variables") + flag.Parse() +} + var joinMessages = []string{ "<@%s> has joined <#%s>", "<@%s> has joined <#%s>; Join in for some nerd talk", - "<#%[2]s> is the place to be, <@%[1]s> just joined", + "<#%[2]s> is the place to be! <@%[1]s> just joined", "<#%[2]s> just go a bit cooler, <@%[1]s> is now in", "<@%s> is hanging out in <#%s>", } func main() { - envs, err := godotenv.Read() + envs, err := godotenv.Read(confFile) if err != nil { log.Fatalf("Unable to get environment variables: %v", err) } @@ -45,12 +53,15 @@ func main() { log.Fatal(err) } + // Log all of the servers tht this bot is installed in. s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) { for _, g := range r.Guilds { g2, _ := s.Guild(g.ID) log.Printf("Bot is connected to %q.", g2.Name) } }) + + // Add different capability handlers: s.AddHandler(voiceStatus) err = s.Open()