1
0
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:
2017-04-01 16:19:56 -05:00
parent d2d9b08f8c
commit 93e6c54976
11 changed files with 34 additions and 52 deletions

3
.gitignore vendored
View File

@@ -1 +1,2 @@
config.json
config.json
dist

View File

@@ -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",

Binary file not shown.

BIN
dist/ServerStatus-mac vendored

Binary file not shown.

Binary file not shown.

32
dist/config.json vendored
View File

@@ -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
}
]
}

View File

@@ -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`

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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{})
}

View File

@@ -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!")