mirror of
https://github.com/mgerb/ServerStatus
synced 2026-01-11 03:32:50 +00:00
added current playing game - also refactored some things
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
config.json
|
config.json
|
||||||
|
dist
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"Token": "your_bot_token_id",
|
"Token": "your_bot_token_id",
|
||||||
"RoomIDList": ["id_1", "id_2", "id_3"],
|
"RoomIDList": ["id_1", "id_2", "id_3"],
|
||||||
"RoleToNotify": "@Elysium",
|
"RoleToNotify": "@Elysium",
|
||||||
|
"GameStatus": "current playing game",
|
||||||
"Servers": [
|
"Servers": [
|
||||||
{
|
{
|
||||||
"Name": "Elysium PvP",
|
"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
|
## 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.
|
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
|
## Configuration
|
||||||
|
|
||||||
- Download or Clone the repository
|
- Download the latest release [here](https://github.com/mgerb/ServerStatus/releases)
|
||||||
- Add your bot token and room ID to the config.json in the dist folder
|
- Add your bot token as well as other configurations to config.json
|
||||||
- Execute the correct binary according to your operating system!
|
- Execute the OS specific binary!
|
||||||
|
|
||||||
|
## Compiling from source
|
||||||
|
|
||||||
|
- Make sure Go and Make are installed
|
||||||
|
- make all
|
||||||
|
|
||||||
### How to get the bot token
|
### How to get the bot token
|
||||||
https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-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!
|
Darrowshire PvE is online!
|
||||||
Elysium Authentication Server 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.")
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type configStruct struct {
|
|||||||
RoomIDList []string `json:"RoomIDList"`
|
RoomIDList []string `json:"RoomIDList"`
|
||||||
RoleToNotify string `json:"RoleToNotify"`
|
RoleToNotify string `json:"RoleToNotify"`
|
||||||
Servers []server `json:"Servers"`
|
Servers []server `json:"Servers"`
|
||||||
|
GameStatus string `json:"GameStatus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type server struct {
|
type server struct {
|
||||||
|
|||||||
10
src/main.go
10
src/main.go
@@ -18,11 +18,15 @@ func main() {
|
|||||||
//connect bot to account with token
|
//connect bot to account with token
|
||||||
bot.Connect(config.Config.Token)
|
bot.Connect(config.Config.Token)
|
||||||
|
|
||||||
//start side tasks
|
// add handlers
|
||||||
serverstatus.Start()
|
|
||||||
|
|
||||||
bot.AddHandler(serverstatus.MessageHandler)
|
bot.AddHandler(serverstatus.MessageHandler)
|
||||||
|
|
||||||
//start websocket to listen for messages
|
//start websocket to listen for messages
|
||||||
bot.Start()
|
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"
|
"fmt"
|
||||||
"github.com/anvie/port-scanner"
|
"github.com/anvie/port-scanner"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,11 +16,17 @@ func Start() {
|
|||||||
config.Config.Servers[i].Online = true
|
config.Config.Servers[i].Online = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//start a new go routine
|
err := bot.Session.UpdateStatus(0, config.Config.GameStatus)
|
||||||
go loop()
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loop() {
|
//start a new go routine
|
||||||
|
go scanServers()
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanServers() {
|
||||||
|
|
||||||
//check if server are in config file
|
//check if server are in config file
|
||||||
if len(config.Config.Servers) < 1 {
|
if len(config.Config.Servers) < 1 {
|
||||||
@@ -32,8 +39,8 @@ func loop() {
|
|||||||
for index, server := range config.Config.Servers {
|
for index, server := range config.Config.Servers {
|
||||||
prevServerUp := server.Online //set value to previous server status
|
prevServerUp := server.Online //set value to previous server status
|
||||||
|
|
||||||
elysiumPvP := portscanner.NewPortScanner(server.Address, time.Second*2)
|
serverScanner := portscanner.NewPortScanner(server.Address, time.Second*2)
|
||||||
serverUp := elysiumPvP.IsOpen(server.Port) //check if the port is open
|
serverUp := serverScanner.IsOpen(server.Port) //check if the port is open
|
||||||
|
|
||||||
if serverUp && serverUp != prevServerUp {
|
if serverUp && serverUp != prevServerUp {
|
||||||
sendMessage(config.Config.RoleToNotify + " " + server.Name + " is now online!")
|
sendMessage(config.Config.RoleToNotify + " " + server.Name + " is now online!")
|
||||||
|
|||||||
Reference in New Issue
Block a user