Skip to content

Commit

Permalink
feat(*): Disgrowth
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkaroid committed Jun 26, 2022
1 parent b017dd7 commit 7b4656b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
34 changes: 34 additions & 0 deletions index.ts
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;
11 changes: 11 additions & 0 deletions src/const.ts
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
}
};
20 changes: 20 additions & 0 deletions src/utils.ts
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?`);
});
}

0 comments on commit 7b4656b

Please sign in to comment.