Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.1 #4

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-bots",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"private": true,
"license": "SEE LICENSE IN LICENSE.md",
Expand Down
19 changes: 10 additions & 9 deletions src/network-bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class NetworkBot {
private log: Log
private client: Discord.Client
private interval?: NodeJS.Timeout
private lastSessions?: number
private lastNodeCount?: number

constructor() {
this.log = new Log([new StdioAdaptor()], 'network-bot', LogLevelFromString(GlobalConfig.logLevel))
Expand Down Expand Up @@ -65,28 +65,29 @@ export class NetworkBot {
async updateActivity(): Promise<void> {
try {
this.updateMembers()
this.updateSessions()
this.updateNodes()
}
catch (error) {
this.log.error('Failed to update activity', error as Error)
}
}

async updateSessions(): Promise<void> {
const response = await superagent.get('https://stargate.edge.network/sessions/open')
async updateNodes(): Promise<void> {
const response = await superagent.get('https://index.edge.network/nodes/stats')
if (response.body) {
const sessions = response.body.length
if (this.lastSessions === sessions) return
const count = response.body.total
const nodeCount = count.stargates + count.gateways + count.hosts
if (this.lastNodeCount === nodeCount) return

// Update network status via bot name/activity
const activity = `${sessions} nodes online`
const activity = `${nodeCount} nodes online`
this.log.info(`Updating status ticker to '${activity}'`)
this.client.user?.setActivity('Network Status', { type: 'WATCHING' })
this.client.guilds.cache.forEach(guild => guild.me?.setNickname(activity))
this.lastSessions = sessions
this.lastNodeCount = nodeCount
return
}
this.log.warn('Failed to query open sessions')
this.log.warn('Failed to query node stats')
}

async updateMembers(): Promise<void> {
Expand Down