mirror of
https://github.com/the-programmers-hangout/swiftspiracy-bot.git
synced 2026-09-10 07:56:26 +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -11,6 +13,17 @@ import (
|
|||||||
"github.com/joho/godotenv"
|
"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() {
|
func main() {
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -25,6 +38,13 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load messages at build time
|
||||||
|
err = loadMessages()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error loading embedded messages: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// initialize bot session
|
// initialize bot session
|
||||||
dg, err := discordgo.New("Bot " + botToken)
|
dg, err := discordgo.New("Bot " + botToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,6 +73,30 @@ func main() {
|
|||||||
dg.Close()
|
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) {
|
func readyHandler(s *discordgo.Session, r *discordgo.Ready) {
|
||||||
fmt.Println("Ready to rumble!")
|
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