-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
3 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { request } from "./src/utils"; | ||
import c from "./src/const"; | ||
|
||
class Disgrowth { | ||
|
||
private base: string | ||
private bot: string | ||
|
||
static default: typeof Disgrowth; | ||
|
||
constructor(bot: string) { | ||
if (!bot) throw new Error(c.error.missingBotId); | ||
this.base = c.endpoint.baseurl; | ||
this.bot = bot; | ||
} | ||
|
||
/** | ||
* Get the summary stats increments of a bots | ||
* @example | ||
* ```js | ||
* Disgrowth.myStats().then((res) => { console.log("myStats", res); }); | ||
* ``` | ||
* https://disgrowth.mod.land/stats/get?id=724047481561809007 | ||
*/ | ||
async myStats(): Promise<object> { | ||
const endpoint = `${this.base}/stats/get?id=${this.bot}`; | ||
const res = await request(endpoint, "GET"); | ||
return res.body as object; | ||
} | ||
|
||
} | ||
|
||
Disgrowth.default = Disgrowth; | ||
export = Disgrowth; |
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,11 @@ | ||
export default { | ||
endpoint: { | ||
baseurl: "https://disgrowth-production.up.railway.app" | ||
}, | ||
error: { | ||
missingBotId: "Missing bot id" | ||
}, | ||
pending: { | ||
limit: 1000 | ||
} | ||
}; |
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,20 @@ | ||
import phin from "phin"; | ||
|
||
/** | ||
* Call api and return the response | ||
* @param {string} url some endpoint | ||
* @param {string} method GET, POST, PUT, DELETE | ||
* @param {object} data data to send | ||
* @returns {Promise<object>} | ||
*/ | ||
export async function request(url: string, method: string, data?: object) { | ||
|
||
return await phin({ | ||
method: method, | ||
url: url, | ||
parse: "json", | ||
data: data | ||
}).catch(err => { | ||
throw new Error(`${err.message} Are you sure this bot listed in top.gg?`); | ||
}); | ||
} |