mirror of
https://github.com/the-programmers-hangout/swiftspiracy-bot.git
synced 2026-09-04 01:06:01 +02:00
load messages at build time
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"Taylor Swift is secretly an immortal time traveler. 👀",
|
||||
"Is her cat actually the mastermind behind her songwriting? 🤔"
|
||||
]
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -11,6 +13,17 @@ import (
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
//go:embed praises.json
|
||||
var praisesFile embed.FS
|
||||
|
||||
//go:embed conspiracies.json
|
||||
var conspiraciesFile embed.FS
|
||||
|
||||
var (
|
||||
praises []string
|
||||
conspiracies []string
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
@@ -25,6 +38,13 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// load messages at build time
|
||||
err = loadMessages()
|
||||
if err != nil {
|
||||
fmt.Println("Error loading embedded messages: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// initialize bot session
|
||||
dg, err := discordgo.New("Bot " + botToken)
|
||||
if err != nil {
|
||||
@@ -53,6 +73,30 @@ func main() {
|
||||
dg.Close()
|
||||
}
|
||||
|
||||
func loadMessages() error {
|
||||
file, err := praisesFile.ReadFile("praises.json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(file, &praises)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err = conspiraciesFile.ReadFile("conspiracies.json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(file, &conspiracies)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func readyHandler(s *discordgo.Session, r *discordgo.Ready) {
|
||||
fmt.Println("Ready to rumble!")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
"I love *All Too Well*, the lyrics are so beautiful: 'Maybe we got lost in translation...'",
|
||||
"*Enchanted* is such a masterpiece. 'This night is sparkling, don’t you let it go.'"
|
||||
]
|
||||
Reference in New Issue
Block a user