mirror of
https://github.com/mgerb/ServerStatus
synced 2026-01-09 02:52:47 +00:00
Updates and maintenance
- switch from dep to go modules - update to discordgo v0.27.1 - fix offline/online message bug
This commit is contained in:
90
Gopkg.lock
generated
90
Gopkg.lock
generated
@@ -1,90 +0,0 @@
|
|||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:05eebdd5727fea23083fce0d98d307d70c86baed644178e81608aaa9f09ea469"
|
|
||||||
name = "github.com/Sirupsen/logrus"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "60c74ad9be0d874af0ab0daef6ab07c5c5911f0d"
|
|
||||||
version = "v1.6.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:b7e05c8da029b985907b15e126cde5f42f2814b08211a184dac436eeec6fe780"
|
|
||||||
name = "github.com/anvie/port-scanner"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"predictors",
|
|
||||||
"predictors/webserver",
|
|
||||||
]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "8159197d3770eb6dbf3a9706a6d40462ebb69cec"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:d87c9221a974263e3b369bfd3513707b2a53e27a6cd799d472f94dc6a6157e59"
|
|
||||||
name = "github.com/bwmarrin/discordgo"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "ed4d6904961d1688b3f5601b3d73e95a71046734"
|
|
||||||
version = "v0.20.3"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:6d29f02f0f01c627c2be40fb7347669a9ff2aa215cb97747294c1d13ffa74bdd"
|
|
||||||
name = "github.com/gorilla/websocket"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "b65e62901fc1c0d968042419e74789f6af455eb9"
|
|
||||||
version = "v1.4.2"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:50993a8fbb3042b88dfecb8f4473a42f13ac70d6fd86f64df525a28b357c2d5b"
|
|
||||||
name = "github.com/kidoman/go-steam"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "2e40e0d508cbac591bab4ae18b231153295f3a0a"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:09cb61dc19af93deae01587e2fdb1c081e0bf48f1a5ad5fa24f48750dc57dce8"
|
|
||||||
name = "github.com/konsorten/go-windows-terminal-sequences"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "edb144dfd453055e1e49a3d8b410a660b5a87613"
|
|
||||||
version = "v1.0.3"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:1714bd928fd176237ccdea21695bf72801c1ee5f51bccefb69b87f0fd376a6aa"
|
|
||||||
name = "golang.org/x/crypto"
|
|
||||||
packages = [
|
|
||||||
"internal/subtle",
|
|
||||||
"nacl/secretbox",
|
|
||||||
"poly1305",
|
|
||||||
"salsa20/salsa",
|
|
||||||
]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "70a84ac30bf957c7df57edd1935d2081871515e1"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:145abe7dfa46d17ef35e5126ed1cc87b9100e78b9f428c9460deea34bfeabafb"
|
|
||||||
name = "golang.org/x/sys"
|
|
||||||
packages = [
|
|
||||||
"cpu",
|
|
||||||
"internal/unsafeheader",
|
|
||||||
"unix",
|
|
||||||
]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "226ff32320da7b90d0b5bc2365f4e359c466fb78"
|
|
||||||
|
|
||||||
[solve-meta]
|
|
||||||
analyzer-name = "dep"
|
|
||||||
analyzer-version = 1
|
|
||||||
input-imports = [
|
|
||||||
"github.com/anvie/port-scanner",
|
|
||||||
"github.com/bwmarrin/discordgo",
|
|
||||||
"github.com/kidoman/go-steam",
|
|
||||||
]
|
|
||||||
solver-name = "gps-cdcl"
|
|
||||||
solver-version = 1
|
|
||||||
42
Gopkg.toml
42
Gopkg.toml
@@ -1,42 +0,0 @@
|
|||||||
# Gopkg.toml example
|
|
||||||
#
|
|
||||||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
|
|
||||||
# for detailed Gopkg.toml documentation.
|
|
||||||
#
|
|
||||||
# required = ["github.com/user/thing/cmd/thing"]
|
|
||||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project"
|
|
||||||
# version = "1.0.0"
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project2"
|
|
||||||
# branch = "dev"
|
|
||||||
# source = "github.com/myfork/project2"
|
|
||||||
#
|
|
||||||
# [[override]]
|
|
||||||
# name = "github.com/x/y"
|
|
||||||
# version = "2.4.0"
|
|
||||||
#
|
|
||||||
# [prune]
|
|
||||||
# non-go = false
|
|
||||||
# go-tests = true
|
|
||||||
# unused-packages = true
|
|
||||||
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/anvie/port-scanner"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
name = "github.com/bwmarrin/discordgo"
|
|
||||||
version = "0.24.0"
|
|
||||||
|
|
||||||
[prune]
|
|
||||||
go-tests = true
|
|
||||||
unused-packages = true
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/kidoman/go-steam"
|
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"Token": "your bot token",
|
"Token": "your bot token",
|
||||||
"RoomIDList":["room id list goes here"],
|
"RoomIDList": ["room id list goes here"],
|
||||||
"RolesToNotify": ["<@&roleid>", "<@userid>"],
|
"RolesToNotify": ["<@&roleid>", "<@userid>"],
|
||||||
"GameStatus": "current playing game",
|
"GameStatus": "current playing game",
|
||||||
"PollingInterval": 10,
|
"PollingInterval": 10,
|
||||||
"BotPrefix": "!",
|
"Servers": [
|
||||||
"Servers": [
|
{
|
||||||
{
|
"Name": "Your awesome server",
|
||||||
"Name": "Your awesome server",
|
"Address": "game.server.com",
|
||||||
"Address": "game.server.com",
|
"Port": 80
|
||||||
"Port": 80
|
},
|
||||||
}, {
|
{
|
||||||
"Name": "Another awesome server",
|
"Name": "Another awesome server",
|
||||||
"Address": "awesome.server.com",
|
"Address": "awesome.server.com",
|
||||||
"Port": 8080
|
"Port": 8080
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
17
go.mod
Normal file
17
go.mod
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
module github.com/mgerb/ServerStatus
|
||||||
|
|
||||||
|
go 1.22.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/anvie/port-scanner v0.0.0-20180225151059-8159197d3770
|
||||||
|
github.com/bwmarrin/discordgo v0.27.1
|
||||||
|
github.com/kidoman/go-steam v0.0.0-20141221015629-2e40e0d508cb
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/Sirupsen/logrus v1.0.6 // indirect
|
||||||
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
|
||||||
|
)
|
||||||
19
go.sum
Normal file
19
go.sum
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
github.com/Sirupsen/logrus v1.0.6 h1:HCAGQRk48dRVPA5Y+Yh0qdCSTzPOyU1tBJ7Q9YzotII=
|
||||||
|
github.com/Sirupsen/logrus v1.0.6/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U=
|
||||||
|
github.com/anvie/port-scanner v0.0.0-20180225151059-8159197d3770 h1:1KEvfMGAjISVzk3Ti6pfaOgtoC3naoU0LfiJooZDNO8=
|
||||||
|
github.com/anvie/port-scanner v0.0.0-20180225151059-8159197d3770/go.mod h1:QGzdstKeoHmMWwi9oNHZ7DQzEj9pi7H42171pkj9htk=
|
||||||
|
github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY=
|
||||||
|
github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||||
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/kidoman/go-steam v0.0.0-20141221015629-2e40e0d508cb h1:+3H4rb1CvcN/BEuBlk774uxxab272M6YU9nb9p/GZm8=
|
||||||
|
github.com/kidoman/go-steam v0.0.0-20141221015629-2e40e0d508cb/go.mod h1:PKiM4eL8SN6mJ38F9m6ZJpVtJKnmSxOxBsi2p3TOru4=
|
||||||
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
|
||||||
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
# Server Status
|
# Server Status
|
||||||
Monitors a list of servers and sends a chat notification when a server goes on or offline.
|
Monitors a list of servers and sends a chat notification when a server goes on or offline.
|
||||||
|
|
||||||
Enjoy the bot?
|
|
||||||
|
|
||||||
<a href="https://www.buymeacoffee.com/mgerb" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- send channel notifications
|
- send channel notifications
|
||||||
@@ -54,7 +50,7 @@ services:
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
To get the current status of your servers simply type `!ServerStatus` in chat.
|
To get the current status of your servers simply type `/server-status` in chat.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -23,32 +23,32 @@ const (
|
|||||||
|
|
||||||
// Start - add command, start port scanner and bot listeners
|
// Start - add command, start port scanner and bot listeners
|
||||||
func Start() {
|
func Start() {
|
||||||
//add command
|
//add command
|
||||||
_, err := bot.Session.ApplicationCommandCreate(bot.Session.State.User.ID, "", &discordgo.ApplicationCommand {
|
_, err := bot.Session.ApplicationCommandCreate(bot.Session.State.User.ID, "", &discordgo.ApplicationCommand{
|
||||||
Name: "server-status",
|
Name: "server-status",
|
||||||
Description: "Get the status of the servers.",
|
Description: "Get the status of the servers.",
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("Cannot create status command '%v'", err)
|
log.Panicf("Cannot create status command '%v'", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//set each server status as online to start
|
//set each server status as online to start
|
||||||
for i := range config.Config.Servers {
|
for i := range config.Config.Servers {
|
||||||
config.Config.Servers[i].Online = true
|
config.Config.Servers[i].Online = true
|
||||||
config.Config.Servers[i].OnlineTimestamp = time.Now()
|
config.Config.Servers[i].OnlineTimestamp = time.Now()
|
||||||
config.Config.Servers[i].OfflineTimestamp = time.Now()
|
config.Config.Servers[i].OfflineTimestamp = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bot.Session.UpdateStatusComplex(discordgo.UpdateStatusData {
|
err = bot.Session.UpdateStatusComplex(discordgo.UpdateStatusData{
|
||||||
Status: "online",
|
Status: "online",
|
||||||
Activities: []*discordgo.Activity {
|
Activities: []*discordgo.Activity{
|
||||||
&discordgo.Activity {
|
&discordgo.Activity{
|
||||||
Type: discordgo.ActivityTypeGame,
|
Type: discordgo.ActivityTypeGame,
|
||||||
Name: config.Config.GameStatus,
|
Name: config.Config.GameStatus,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
sendMessageToRooms(blue, "Server Status", "Bot started! Type /server-status to see the status of your servers :smiley:", false)
|
sendMessageToRooms(blue, "Server Status", "Bot started! Type /server-status to see the status of your servers :smiley:", false)
|
||||||
|
|
||||||
@@ -153,40 +153,47 @@ func sendEmbeddedMessage(roomID string, color int, title, description string) {
|
|||||||
// InteractionHandler will be called every time an interaction from a user occurs
|
// InteractionHandler will be called every time an interaction from a user occurs
|
||||||
// Command interaction handling requires bot command scope
|
// Command interaction handling requires bot command scope
|
||||||
func InteractionHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func InteractionHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
// A user is calling us with our status command
|
// A user is calling us with our status command
|
||||||
if i.ApplicationCommandData().Name == "server-status" {
|
if i.ApplicationCommandData().Name == "server-status" {
|
||||||
online := ""
|
online := ""
|
||||||
offline := ""
|
offline := ""
|
||||||
|
|
||||||
for _, server := range config.Config.Servers {
|
for _, server := range config.Config.Servers {
|
||||||
if server.Online {
|
if server.Online {
|
||||||
online = online + server.Name + " : " + fmtDuration(time.Since(server.OnlineTimestamp)) + "\n"
|
online = online + server.Name + " : " + fmtDuration(time.Since(server.OnlineTimestamp)) + "\n"
|
||||||
} else {
|
} else {
|
||||||
offline = offline + server.Name + " : " + fmtDuration(time.Since(server.OfflineTimestamp)) + "\n"
|
offline = offline + server.Name + " : " + fmtDuration(time.Since(server.OfflineTimestamp)) + "\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only one message can be an interaction response. Messages can only contain up to 10 embeds.
|
embeds := []*discordgo.MessageEmbed{}
|
||||||
// Our message will therefore instead be two embeds (online and offline), each with a list of servers in text.
|
|
||||||
// Embed descriptions can be ~4096 characters, so no limits should get hit with this.
|
if online != "" {
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse {
|
embeds = append(embeds, &discordgo.MessageEmbed{
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Title: ":white_check_mark: Online",
|
||||||
Data: &discordgo.InteractionResponseData {
|
Color: green,
|
||||||
Embeds: []*discordgo.MessageEmbed {
|
Description: online,
|
||||||
{
|
})
|
||||||
Title: ":white_check_mark: Online",
|
}
|
||||||
Color: green,
|
|
||||||
Description: online,
|
if offline != "" {
|
||||||
},
|
embeds = append(embeds, &discordgo.MessageEmbed{
|
||||||
{
|
Title: ":x: Offline",
|
||||||
Title: ":x: Offline",
|
Color: red,
|
||||||
Color: red,
|
Description: offline,
|
||||||
Description: offline,
|
})
|
||||||
},
|
}
|
||||||
},
|
|
||||||
},
|
// Only one message can be an interaction response. Messages can only contain up to 10 embeds.
|
||||||
})
|
// Our message will therefore instead be two embeds (online and offline), each with a list of servers in text.
|
||||||
}
|
// Embed descriptions can be ~4096 characters, so no limits should get hit with this.
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Embeds: embeds,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fmtDuration(d time.Duration) string {
|
func fmtDuration(d time.Duration) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user