updates
This commit is contained in:
@@ -12,6 +12,7 @@ RUN go build -o bot
|
|||||||
# Set the DISCORD_BOT_TOKEN environment variable
|
# Set the DISCORD_BOT_TOKEN environment variable
|
||||||
ENV TOKEN=${DISCORD_TOKEN}
|
ENV TOKEN=${DISCORD_TOKEN}
|
||||||
ENV BOTPREFIX="!"
|
ENV BOTPREFIX="!"
|
||||||
|
ENV ChannelID=${ChannelID}
|
||||||
|
|
||||||
# Run the bot binary
|
# Run the bot binary
|
||||||
CMD ["./bot"]
|
CMD ["./bot"]
|
||||||
28
main.go
28
main.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -13,6 +14,9 @@ import (
|
|||||||
var (
|
var (
|
||||||
Token string
|
Token string
|
||||||
BotPrefix string
|
BotPrefix string
|
||||||
|
ChannelID string
|
||||||
|
BotId string
|
||||||
|
goBot *discordgo.Session
|
||||||
|
|
||||||
config *configStruct
|
config *configStruct
|
||||||
)
|
)
|
||||||
@@ -20,6 +24,7 @@ var (
|
|||||||
type configStruct struct {
|
type configStruct struct {
|
||||||
Token string `json : "Token"`
|
Token string `json : "Token"`
|
||||||
BotPrefix string `json : "BotPrefix"`
|
BotPrefix string `json : "BotPrefix"`
|
||||||
|
ChannelID string `json : "ChannelID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type jingleBellsResponse struct {
|
type jingleBellsResponse struct {
|
||||||
@@ -48,14 +53,12 @@ func ReadConfig() error {
|
|||||||
|
|
||||||
Token = os.Getenv("TOKEN")
|
Token = os.Getenv("TOKEN")
|
||||||
BotPrefix = os.Getenv("BOTPREFIX")
|
BotPrefix = os.Getenv("BOTPREFIX")
|
||||||
|
ChannelID = os.Getenv("ChannelID")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var BotId string
|
|
||||||
var goBot *discordgo.Session
|
|
||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
goBot, err := discordgo.New("Bot " + Token)
|
goBot, err := discordgo.New("Bot " + Token)
|
||||||
|
|
||||||
@@ -74,6 +77,8 @@ func Start() {
|
|||||||
BotId = u.ID
|
BotId = u.ID
|
||||||
|
|
||||||
goBot.AddHandler(messageHandler)
|
goBot.AddHandler(messageHandler)
|
||||||
|
goBot.AddHandler(handleGuildMemberAdd)
|
||||||
|
goBot.AddHandler(handleGuildMemberRemove)
|
||||||
|
|
||||||
err = goBot.Open()
|
err = goBot.Open()
|
||||||
|
|
||||||
@@ -217,3 +222,20 @@ func sendAPIRequest(s *discordgo.Session, m *discordgo.MessageCreate, url string
|
|||||||
s.ChannelMessageSend(m.ChannelID, data.Joke)
|
s.ChannelMessageSend(m.ChannelID, data.Joke)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleGuildMemberAdd(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
|
||||||
|
message := fmt.Sprintf("Welcome <@%s> to our server!", m.Member.User.ID)
|
||||||
|
_, err := s.ChannelMessageSend(ChannelID, message)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error sending welcome message: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleGuildMemberRemove(s *discordgo.Session, m *discordgo.GuildMemberRemove) {
|
||||||
|
|
||||||
|
message := fmt.Sprintf("Goodbye %s", m.Member.User.Username)
|
||||||
|
_, err := s.ChannelMessageSend(ChannelID, message)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error sending goodbye message: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user