Skip to content

Commit

Permalink
Fix obj key names to work with new api (pre6)
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVTomatoCake committed Dec 17, 2023
1 parent 09a3ee5 commit 1bd71ca
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,20 @@ if (message.content.includes("<@" + bot.user.id + ">")) {
const DisStat = require("disstat")
const disstat = new DisStat(...)

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

disstat.on("autopostStart", () => {
console.log("Starting autoposting...")
// Emits on every autopost, not once. Use "ready" or .once() for that.
console.log("Started autopost...")
})
disstat.on("autopostError", (error, data) => {
console.log("Autoposting failed: " + error, data)
console.log("Autopost failed: " + error, data)
})
disstat.on("autopostSuccess", data => {
console.log("Finished posting this data:", data)
})

disstat.on("post", error => {
if (error) console.log("An error occurred while posting:", error)
else console.log("Posted data successfully!")
// This event also gets emitted on autoposting.
console.log("Successfully posting data:", data)
})

```
18 changes: 8 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DisStat extends EventEmitter {
if (!apiKeyInput.startsWith("DS-")) console.warn("[DisStat " + new Date().toLocaleTimeString() + "] The provided API key as first argument doesn't start with \"DS-\".")

this.botId = typeof botInput == "object" ? botInput.user.id : botInput
if (!this.botId) throw new TypeError("Missing (falsy) Discord bot ID provided, but a bot ID is required as second argument")
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")
this.apiKey = apiKeyInput

if (typeof botInput == "object") {
Expand All @@ -31,21 +31,18 @@ class DisStat extends EventEmitter {
this.bot = botInput
setTimeout(() => this.autopost(), 30000)
}

this.emit("ready")
}

async autopost() {
this.emit("autopostStart")

const data = {
custom: this.unpostedCustom
}
const data = {}
if (this.unpostedCustom.length > 0) data.custom = this.unpostedCustom
if (this.bot) {
data.guildCount = this.bot.guilds.cache.size
data.shardCount = this.bot.shard ? this.bot.shard.count : 0
data.userCount = this.bot.guilds.cache.filter(guild => guild.available).reduce((acc, cur) => acc + cur.memberCount, 0)
data.apiPing = this.bot.ws.ping
data.guilds = this.bot.guilds.cache.size
data.shards = this.bot.shard ? this.bot.shard.count : 0
data.users = this.bot.guilds.cache.filter(guild => guild.available).reduce((acc, cur) => acc + cur.memberCount, 0)
data.apiPing = this.bot.ws.ping > 0 ? this.bot.ws.ping : void 0
}
data.ramUsage = process.memoryUsage.rss()
data.ramTotal = process.memoryUsage().heapTotal
Expand Down Expand Up @@ -136,6 +133,7 @@ class DisStat extends EventEmitter {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: this.apiKey
},
body: JSON.stringify(body)
Expand Down
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": "disstat",
"version": "1.0.0-pre5",
"version": "1.0.0-pre6",
"description": "Post data from a discord.js client automatically, or manually to DisStat for Discord bot statistic tracking.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 1bd71ca

Please sign in to comment.