-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package status | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/gadost/telescope/conf" | ||
) | ||
|
||
func DiscordHandler() { | ||
dg, err := discordgo.New("Bot " + conf.MainConfig.Discord.Token) | ||
if err != nil { | ||
log.Println("error creating Discord session,", err) | ||
return | ||
} | ||
dg.AddHandler(messageCreate) | ||
|
||
// Open a websocket connection to Discord and begin listening. | ||
err = dg.Open() | ||
if err != nil { | ||
fmt.Println("error opening connection,", err) | ||
return | ||
} | ||
|
||
// Cleanly close down the Discord session. | ||
defer dg.Close() | ||
} | ||
|
||
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { | ||
|
||
// Ignore all messages created by the bot itself | ||
if m.Author.ID == s.State.User.ID { | ||
return | ||
} | ||
// If the message is "ping" reply with "Pong!" | ||
if m.Content == "$status" { | ||
s.ChannelMessageSend(m.ChannelID, StatusCollection()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,44 @@ | ||
package status | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/gadost/telescope/watcher" | ||
) | ||
|
||
// StatusCollection collect status from Chain struct | ||
func StatusCollection() string { | ||
var collection string | ||
var cu string | ||
var badRPC []string | ||
collection = collection + "*Status:*\n\n" | ||
|
||
for i := range watcher.Chains.Chain { | ||
for _, k := range watcher.Chains.Chain[i].Node { | ||
if k.Status.SyncInfo.LatestBlockHeight > 0 { | ||
collection += "*Net:* `" + k.Status.NodeInfo.Network + "`\n*Moniker:* `" + k.Status.NodeInfo.Moniker + "`\n" | ||
if k.Status.SyncInfo.CatchingUp { | ||
cu = "Yes" | ||
} else { | ||
cu = "No" | ||
} | ||
|
||
collection += "*CatchingUp:* `" + cu + "`\n" | ||
collection += "*Last known height:* `" + strconv.Itoa(int(k.Status.SyncInfo.LatestBlockHeight)) + "`\n" | ||
collection += "*Last known block time :* `" + k.Status.SyncInfo.LatestBlockTime.Format("2006-01-02 15:04:05") + "`\n" | ||
collection += "`_________________________`\n" | ||
} else { | ||
if k.MonitoringEnabled { | ||
badRPC = append(badRPC, k.RPC) | ||
} | ||
} | ||
} | ||
} | ||
|
||
if len(badRPC) > 0 { | ||
collection += "*🔴Unreachable RPCs:*\n`" + strings.Join(badRPC, "\n") + "`" | ||
} | ||
|
||
return collection | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters