Skip to content

Commit 1bd71ca

Browse files
committed
Fix obj key names to work with new api (pre6)
1 parent 09a3ee5 commit 1bd71ca

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

README.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,20 @@ if (message.content.includes("<@" + bot.user.id + ">")) {
8080
const DisStat = require("disstat")
8181
const disstat = new DisStat(...)
8282

83-
disstat.on("ready", () => {
84-
console.log("DisStat is ready!")
83+
disstat.on("post", (error, data) => {
84+
if (error) console.log("An error occurred while posting:", error, data)
85+
else console.log("Posted data successfully:", data)
86+
// This event also gets emitted on autoposting.
8587
})
8688

8789
disstat.on("autopostStart", () => {
88-
console.log("Starting autoposting...")
89-
// Emits on every autopost, not once. Use "ready" or .once() for that.
90+
console.log("Started autopost...")
9091
})
9192
disstat.on("autopostError", (error, data) => {
92-
console.log("Autoposting failed: " + error, data)
93+
console.log("Autopost failed: " + error, data)
9394
})
9495
disstat.on("autopostSuccess", data => {
95-
console.log("Finished posting this data:", data)
96-
})
97-
98-
disstat.on("post", error => {
99-
if (error) console.log("An error occurred while posting:", error)
100-
else console.log("Posted data successfully!")
101-
// This event also gets emitted on autoposting.
96+
console.log("Successfully posting data:", data)
10297
})
10398

10499
```

index.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DisStat extends EventEmitter {
1919
if (!apiKeyInput.startsWith("DS-")) console.warn("[DisStat " + new Date().toLocaleTimeString() + "] The provided API key as first argument doesn't start with \"DS-\".")
2020

2121
this.botId = typeof botInput == "object" ? botInput.user.id : botInput
22-
if (!this.botId) throw new TypeError("Missing (falsy) Discord bot ID provided, but a bot ID is required as second argument")
22+
if (!this.botId) throw new TypeError("Missing (falsy) Discord bot ID provided, but a discord.js bot client or ID is required as second argument")
2323
this.apiKey = apiKeyInput
2424

2525
if (typeof botInput == "object") {
@@ -31,21 +31,18 @@ class DisStat extends EventEmitter {
3131
this.bot = botInput
3232
setTimeout(() => this.autopost(), 30000)
3333
}
34-
35-
this.emit("ready")
3634
}
3735

3836
async autopost() {
3937
this.emit("autopostStart")
4038

41-
const data = {
42-
custom: this.unpostedCustom
43-
}
39+
const data = {}
40+
if (this.unpostedCustom.length > 0) data.custom = this.unpostedCustom
4441
if (this.bot) {
45-
data.guildCount = this.bot.guilds.cache.size
46-
data.shardCount = this.bot.shard ? this.bot.shard.count : 0
47-
data.userCount = this.bot.guilds.cache.filter(guild => guild.available).reduce((acc, cur) => acc + cur.memberCount, 0)
48-
data.apiPing = this.bot.ws.ping
42+
data.guilds = this.bot.guilds.cache.size
43+
data.shards = this.bot.shard ? this.bot.shard.count : 0
44+
data.users = this.bot.guilds.cache.filter(guild => guild.available).reduce((acc, cur) => acc + cur.memberCount, 0)
45+
data.apiPing = this.bot.ws.ping > 0 ? this.bot.ws.ping : void 0
4946
}
5047
data.ramUsage = process.memoryUsage.rss()
5148
data.ramTotal = process.memoryUsage().heapTotal
@@ -136,6 +133,7 @@ class DisStat extends EventEmitter {
136133
method: "POST",
137134
headers: {
138135
"Content-Type": "application/json",
136+
Accept: "application/json",
139137
Authorization: this.apiKey
140138
},
141139
body: JSON.stringify(body)

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "disstat",
3-
"version": "1.0.0-pre5",
3+
"version": "1.0.0-pre6",
44
"description": "Post data from a discord.js client automatically, or manually to DisStat for Discord bot statistic tracking.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)