moved authentication parsing to seperate file; created struct for authentication tokens

This commit is contained in:
2020-06-06 19:50:55 -05:00
parent aa2b9c796c
commit 545591700a
2 changed files with 61 additions and 16 deletions

View File

@@ -1,33 +1,27 @@
package main
import (
//"flag"
"fmt"
"os"
"os/signal"
"syscall"
"strings"
"io/ioutil"
"github.com/bwmarrin/discordgo"
"github.com/buger/jsonparser"
)
var (
auth Auth
)
func init() {
// build the authentication struct
buildAuth()
}
func main() {
// read auth file
auth, err := ioutil.ReadFile("auth.json")
if err != nil {
panic(err)
}
// get our discord token
token,err := jsonparser.GetString(auth, "[0]", "token")
if err != nil {
fmt.Println(err)
}
// create Discord session
dg, err := discordgo.New("Bot " + token)
dg, err := discordgo.New("Bot " + auth.discord)
if err != nil {
fmt.Println("Error creating Discord session, ", err)
return