2024-07-06 16:18:05 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-07-06 16:55:30 +02:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2024-07-06 16:29:25 +02:00
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
2024-07-06 16:18:05 +02:00
|
|
|
)
|
|
|
|
|
2024-07-06 16:55:30 +02:00
|
|
|
var client *discordgo.Session
|
|
|
|
|
2024-07-06 16:29:25 +02:00
|
|
|
type Config struct {
|
2024-07-06 16:55:30 +02:00
|
|
|
Token string `toml:"token"`
|
|
|
|
GuildID string `toml:"guildId"`
|
2024-07-06 16:29:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfig(filename string) (Config, error) {
|
|
|
|
var config Config
|
|
|
|
_, err := toml.DecodeFile(filename, &config)
|
|
|
|
return config, err
|
|
|
|
}
|
|
|
|
|
2024-07-06 16:55:30 +02:00
|
|
|
func init() {
|
2024-07-06 16:29:25 +02:00
|
|
|
config, err := loadConfig("config.toml")
|
|
|
|
if err != nil {
|
2024-07-06 16:55:30 +02:00
|
|
|
fmt.Println("Error occurred whilst trying to load config:", err)
|
2024-07-06 16:29:25 +02:00
|
|
|
return
|
|
|
|
}
|
2024-07-06 16:55:30 +02:00
|
|
|
|
|
|
|
client, err = discordgo.New("Bot " + config.Token)
|
2024-07-06 16:29:25 +02:00
|
|
|
if err != nil {
|
2024-07-06 16:55:30 +02:00
|
|
|
fmt.Println("Error initializing bot:", err)
|
2024-07-06 16:29:25 +02:00
|
|
|
return
|
|
|
|
}
|
2024-07-06 16:55:30 +02:00
|
|
|
|
|
|
|
|
2024-07-06 16:18:05 +02:00
|
|
|
}
|
2024-07-06 16:55:30 +02:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
if client == nil {
|
|
|
|
fmt.Println("Bot client is not initialized")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
client.AddHandler(func(client *discordgo.Session, r *discordgo.Ready) {
|
|
|
|
fmt.Println("Bot is online")
|
|
|
|
})
|
|
|
|
|
|
|
|
err := client.Open()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error opening connection:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
stop := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
|
|
|
|
<-stop
|
|
|
|
|
|
|
|
fmt.Println("Gracefully shutting down.")
|
|
|
|
client.Close()
|
|
|
|
}
|
|
|
|
|