mirror of
https://github.com/mgerb/ServerStatus
synced 2026-01-10 03:03:04 +00:00
added current playing game - also refactored some things
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
config.json
|
||||
config.json
|
||||
dist
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Token": "your_bot_token_id",
|
||||
"RoomIDList": ["id_1", "id_2", "id_3"],
|
||||
"RoleToNotify": "@Elysium",
|
||||
"GameStatus": "current playing game",
|
||||
"Servers": [
|
||||
{
|
||||
"Name": "Elysium PvP",
|
||||
|
||||
BIN
dist/ServerStatus-linux
vendored
BIN
dist/ServerStatus-linux
vendored
Binary file not shown.
BIN
dist/ServerStatus-mac
vendored
BIN
dist/ServerStatus-mac
vendored
Binary file not shown.
BIN
dist/ServerStatus-windows.exe
vendored
BIN
dist/ServerStatus-windows.exe
vendored
Binary file not shown.
32
dist/config.json
vendored
32
dist/config.json
vendored
@@ -1,32 +0,0 @@
|
||||
{
|
||||
"Token": "your_bot_token_id",
|
||||
"RoomIDList": ["id_1", "id_2", "id_3"],
|
||||
"RoleToNotify": "@Elysium",
|
||||
"Servers": [
|
||||
{
|
||||
"Name": "Elysium PvP",
|
||||
"Address": "149.202.207.235",
|
||||
"Port": 8099
|
||||
},
|
||||
{
|
||||
"Name": "Zethkur PvP",
|
||||
"Address": "151.80.103.221",
|
||||
"Port": 8093
|
||||
},
|
||||
{
|
||||
"Name": "Anathema PvP",
|
||||
"Address": "149.202.211.5",
|
||||
"Port": 8095
|
||||
},
|
||||
{
|
||||
"Name": "Darrowshire PvE",
|
||||
"Address": "164.132.233.125",
|
||||
"Port": 8097
|
||||
},
|
||||
{
|
||||
"Name": "Elysium Authentication Server",
|
||||
"Address": "logon.elysium-project.org",
|
||||
"Port": 3724
|
||||
}
|
||||
]
|
||||
}
|
||||
22
readme.md
22
readme.md
@@ -1,13 +1,21 @@
|
||||
## Server Status
|
||||
|
||||
Scans the Elysium servers checking to see if they are up.
|
||||
Scans a list of servers checking whether the ports are open or not.
|
||||
This bot will send a chat notification when the status of a server changes.
|
||||
|
||||
I originally made this bot the check if private World of Warcraft servers were up or not.
|
||||
This bot is actually much more useful than that and can be used for any type of server.
|
||||
|
||||
## Configuration
|
||||
|
||||
- Download or Clone the repository
|
||||
- Add your bot token and room ID to the config.json in the dist folder
|
||||
- Execute the correct binary according to your operating system!
|
||||
- Download the latest release [here](https://github.com/mgerb/ServerStatus/releases)
|
||||
- Add your bot token as well as other configurations to config.json
|
||||
- Execute the OS specific binary!
|
||||
|
||||
## Compiling from source
|
||||
|
||||
- Make sure Go and Make are installed
|
||||
- make all
|
||||
|
||||
### How to get the bot token
|
||||
https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token
|
||||
@@ -29,9 +37,3 @@ Anathema PvP is online!
|
||||
Darrowshire PvE is online!
|
||||
Elysium Authentication Server is online!
|
||||
```
|
||||
|
||||
## Compiling
|
||||
|
||||
Make sure you have Go installed.
|
||||
|
||||
`make clean all`
|
||||
|
||||
@@ -43,8 +43,6 @@ func Start() {
|
||||
|
||||
fmt.Println("Bot is now running. Press CTRL-C to exit.")
|
||||
|
||||
// Simple way to keep program running until CTRL-C is pressed.
|
||||
<-make(chan struct{})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ type configStruct struct {
|
||||
RoomIDList []string `json:"RoomIDList"`
|
||||
RoleToNotify string `json:"RoleToNotify"`
|
||||
Servers []server `json:"Servers"`
|
||||
GameStatus string `json:"GameStatus"`
|
||||
}
|
||||
|
||||
type server struct {
|
||||
|
||||
10
src/main.go
10
src/main.go
@@ -18,11 +18,15 @@ func main() {
|
||||
//connect bot to account with token
|
||||
bot.Connect(config.Config.Token)
|
||||
|
||||
//start side tasks
|
||||
serverstatus.Start()
|
||||
|
||||
// add handlers
|
||||
bot.AddHandler(serverstatus.MessageHandler)
|
||||
|
||||
//start websocket to listen for messages
|
||||
bot.Start()
|
||||
|
||||
//start server status task
|
||||
serverstatus.Start()
|
||||
|
||||
// Simple way to keep program running until CTRL-C is pressed.
|
||||
<-make(chan struct{})
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/anvie/port-scanner"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -15,11 +16,17 @@ func Start() {
|
||||
config.Config.Servers[i].Online = true
|
||||
}
|
||||
|
||||
err := bot.Session.UpdateStatus(0, config.Config.GameStatus)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
//start a new go routine
|
||||
go loop()
|
||||
go scanServers()
|
||||
}
|
||||
|
||||
func loop() {
|
||||
func scanServers() {
|
||||
|
||||
//check if server are in config file
|
||||
if len(config.Config.Servers) < 1 {
|
||||
@@ -32,8 +39,8 @@ func loop() {
|
||||
for index, server := range config.Config.Servers {
|
||||
prevServerUp := server.Online //set value to previous server status
|
||||
|
||||
elysiumPvP := portscanner.NewPortScanner(server.Address, time.Second*2)
|
||||
serverUp := elysiumPvP.IsOpen(server.Port) //check if the port is open
|
||||
serverScanner := portscanner.NewPortScanner(server.Address, time.Second*2)
|
||||
serverUp := serverScanner.IsOpen(server.Port) //check if the port is open
|
||||
|
||||
if serverUp && serverUp != prevServerUp {
|
||||
sendMessage(config.Config.RoleToNotify + " " + server.Name + " is now online!")
|
||||
|
||||
Reference in New Issue
Block a user