mirror of
https://github.com/mgerb/ServerStatus
synced 2026-01-09 02:52:47 +00:00
discordgo upgraded from 0.20.0 to 0.24.0 which fixed the bot starting with a websocket error and remaining offline. Additionally, the command prefix and MessageHandling commands have been replaced with Discord's newer slash commands.
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// Variables used for command line parameters
|
|
var Config configStruct
|
|
|
|
type configStruct struct {
|
|
Token string `json:"Token"`
|
|
RoomIDList []string `json:"RoomIDList"`
|
|
RolesToNotify []string `json:"RolesToNotify"`
|
|
Servers []Server `json:"Servers"`
|
|
GameStatus string `json:"GameStatus"`
|
|
PollingInterval time.Duration `json:"PollingInterval"`
|
|
}
|
|
|
|
type Server struct {
|
|
Name string `json:"Name"`
|
|
Address string `json:"Address"`
|
|
Port int `json:"Port"`
|
|
Online bool `json:"Online,omitempty"`
|
|
// OnlineTimestamp - time of when the server last came online
|
|
OnlineTimestamp time.Time
|
|
OfflineTimestamp time.Time
|
|
}
|
|
|
|
func Configure() {
|
|
|
|
fmt.Println("Reading config file...")
|
|
|
|
file, e := ioutil.ReadFile("./config.json")
|
|
|
|
if e != nil {
|
|
log.Printf("File error: %v\n", e)
|
|
os.Exit(1)
|
|
}
|
|
|
|
err := json.Unmarshal(file, &Config)
|
|
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
if Config.PollingInterval == 0 {
|
|
log.Fatal("Please set your PollingInterval > 0 in your config file.")
|
|
}
|
|
|
|
}
|