Moved code to top-level folder, and created dockerfile to containerize the bot.
This commit is contained in:
parent
0db4546530
commit
c257a8df75
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -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"]
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
@ -17,16 +18,23 @@ var botToken string
|
|||||||
var announceChannelName string
|
var announceChannelName string
|
||||||
var cleanDelay = 30
|
var cleanDelay = 30
|
||||||
|
|
||||||
|
var confFile string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.StringVar(&confFile, "conf", ".env", ".env file w/ config variables")
|
||||||
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
var joinMessages = []string{
|
var joinMessages = []string{
|
||||||
"<@%s> has joined <#%s>",
|
"<@%s> has joined <#%s>",
|
||||||
"<@%s> has joined <#%s>; Join in for some nerd talk",
|
"<@%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",
|
"<#%[2]s> just go a bit cooler, <@%[1]s> is now in",
|
||||||
"<@%s> is hanging out in <#%s>",
|
"<@%s> is hanging out in <#%s>",
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
envs, err := godotenv.Read()
|
envs, err := godotenv.Read(confFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to get environment variables: %v", err)
|
log.Fatalf("Unable to get environment variables: %v", err)
|
||||||
}
|
}
|
||||||
@ -45,12 +53,15 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log all of the servers tht this bot is installed in.
|
||||||
s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
|
s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
|
||||||
for _, g := range r.Guilds {
|
for _, g := range r.Guilds {
|
||||||
g2, _ := s.Guild(g.ID)
|
g2, _ := s.Guild(g.ID)
|
||||||
log.Printf("Bot is connected to %q.", g2.Name)
|
log.Printf("Bot is connected to %q.", g2.Name)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Add different capability handlers:
|
||||||
s.AddHandler(voiceStatus)
|
s.AddHandler(voiceStatus)
|
||||||
|
|
||||||
err = s.Open()
|
err = s.Open()
|
Loading…
x
Reference in New Issue
Block a user