discordthings-api 1.1.1 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,7 +38,10 @@ const BOT_ID = '123456789012345678'; // Your Bot ID
38
38
  ```javascript
39
39
  async function updateStats() {
40
40
  try {
41
- await dthings.postStats(BOT_ID, 1250);
41
+ await dthings.postStats(BOT_ID, 1250, 0, 50000, [
42
+ { name: "play", count: 120 },
43
+ { name: "profile", count: 50 },
44
+ ]);
42
45
  console.log('Stats updated on DiscordThings!');
43
46
  } catch (err) {
44
47
  console.error('Error updating stats:', err.message);
@@ -94,8 +97,10 @@ async function syncCommands() {
94
97
  - `token` (String): Your personal API Token.
95
98
  - `options.baseUrl` (String): Override default API endpoint.
96
99
 
97
- ### `postStats(botId, serverCount, [shardCount])`
100
+ ### `postStats(botId, serverCount, [shardCount], [userCount], [commandStats])`
98
101
  - Updates the bot's server and shard presence.
102
+ - `userCount`: Total user count (Number).
103
+ - `commandStats`: Array of `{ name, count }`.
99
104
  - Returns `Promise<Object>`.
100
105
 
101
106
  ### `checkVote(botId, userId)`
@@ -0,0 +1,62 @@
1
+ export interface DiscordThingsOptions {
2
+ baseUrl?: string;
3
+ }
4
+ export interface VoteResult {
5
+ voted: boolean;
6
+ lastVote: string | null;
7
+ nextVote: string | null;
8
+ }
9
+ export interface CommandOption {
10
+ name: string;
11
+ description: string;
12
+ type: number;
13
+ required?: boolean;
14
+ choices?: {
15
+ name: string;
16
+ value: string | number;
17
+ }[];
18
+ options?: CommandOption[];
19
+ }
20
+ export interface Command {
21
+ name: string;
22
+ description: string;
23
+ type?: number;
24
+ options?: CommandOption[];
25
+ }
26
+ export declare class DiscordThings {
27
+ private client;
28
+ /**
29
+ * @param {string} token - Your User API Token
30
+ * @param {DiscordThingsOptions} [options] - Configuration options
31
+ */
32
+ constructor(token: string, options?: DiscordThingsOptions);
33
+ /**
34
+ * Post bot statistics to DiscordThings
35
+ * @param {string} botId - The ID of the bot
36
+ * @param {number} serverCount - Total number of servers the bot is in
37
+ * @param {number} [shardCount] - Total number of shards (optional)
38
+ * @param {number} [userCount] - Total number of users (optional)
39
+ * @param {Array<{name: string, count: number}>} [commandStats] - Array of command usage stats (optional)
40
+ * @returns {Promise<any>} API Response
41
+ */
42
+ postStats(botId: string, serverCount: number, shardCount?: number, userCount?: number, commandStats?: {
43
+ name: string;
44
+ count: number;
45
+ }[]): Promise<any>;
46
+ /**
47
+ * Check if a user has voted for the bot
48
+ * @param {string} botId - The ID of the bot
49
+ * @param {string} userId - The ID of the user
50
+ * @returns {Promise<VoteResult>} Vote status object
51
+ */
52
+ checkVote(botId: string, userId: string): Promise<VoteResult | undefined>;
53
+ /**
54
+ * Sync commands for the bot
55
+ * @param {string} botId - The ID of the bot
56
+ * @param {Command[]} commands - Array of command objects
57
+ * @returns {Promise<any>} API Response
58
+ */
59
+ syncCommands(botId: string, commands: Command[]): Promise<any>;
60
+ private _handleError;
61
+ }
62
+ export default DiscordThings;
package/dist/index.js ADDED
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DiscordThings = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class DiscordThings {
9
+ /**
10
+ * @param {string} token - Your User API Token
11
+ * @param {DiscordThingsOptions} [options] - Configuration options
12
+ */
13
+ constructor(token, options = {}) {
14
+ if (!token)
15
+ throw new Error('API Token is required');
16
+ this.client = axios_1.default.create({
17
+ baseURL: options.baseUrl || 'https://discordthings.com/api',
18
+ headers: {
19
+ 'Authorization': token,
20
+ 'Content-Type': 'application/json'
21
+ }
22
+ });
23
+ }
24
+ /**
25
+ * Post bot statistics to DiscordThings
26
+ * @param {string} botId - The ID of the bot
27
+ * @param {number} serverCount - Total number of servers the bot is in
28
+ * @param {number} [shardCount] - Total number of shards (optional)
29
+ * @param {number} [userCount] - Total number of users (optional)
30
+ * @param {Array<{name: string, count: number}>} [commandStats] - Array of command usage stats (optional)
31
+ * @returns {Promise<any>} API Response
32
+ */
33
+ async postStats(botId, serverCount, shardCount, userCount, commandStats) {
34
+ if (!botId || serverCount === undefined)
35
+ throw new Error('Bot ID and server count are required');
36
+ try {
37
+ const payload = {
38
+ server_count: serverCount
39
+ };
40
+ if (shardCount !== undefined)
41
+ payload.shard_count = shardCount;
42
+ if (userCount !== undefined)
43
+ payload.user_count = userCount;
44
+ if (commandStats !== undefined)
45
+ payload.commandStats = commandStats;
46
+ const response = await this.client.post(`/bots/${botId}/stats`, payload);
47
+ return response.data;
48
+ }
49
+ catch (error) {
50
+ this._handleError(error);
51
+ }
52
+ }
53
+ /**
54
+ * Check if a user has voted for the bot
55
+ * @param {string} botId - The ID of the bot
56
+ * @param {string} userId - The ID of the user
57
+ * @returns {Promise<VoteResult>} Vote status object
58
+ */
59
+ async checkVote(botId, userId) {
60
+ if (!botId || !userId)
61
+ throw new Error('Bot ID and User ID are required');
62
+ try {
63
+ const response = await this.client.get(`/bots/${botId}/check-vote`, {
64
+ params: { userId }
65
+ });
66
+ return response.data;
67
+ }
68
+ catch (error) {
69
+ this._handleError(error);
70
+ }
71
+ }
72
+ /**
73
+ * Sync commands for the bot
74
+ * @param {string} botId - The ID of the bot
75
+ * @param {Command[]} commands - Array of command objects
76
+ * @returns {Promise<any>} API Response
77
+ */
78
+ async syncCommands(botId, commands) {
79
+ if (!botId || !Array.isArray(commands))
80
+ throw new Error('Bot ID and commands array are required');
81
+ try {
82
+ const response = await this.client.post(`/bots/${botId}/commands`, {
83
+ commands
84
+ });
85
+ return response.data;
86
+ }
87
+ catch (error) {
88
+ this._handleError(error);
89
+ }
90
+ }
91
+ _handleError(error) {
92
+ if (axios_1.default.isAxiosError(error) && error.response) {
93
+ throw new Error(`API Error [${error.response.status}]: ${error.response.data.error || error.response.statusText}`);
94
+ }
95
+ throw error;
96
+ }
97
+ }
98
+ exports.DiscordThings = DiscordThings;
99
+ // Support CommonJS require and ES imports
100
+ exports.default = DiscordThings;
101
+ module.exports = DiscordThings;
102
+ // To maintain compatibility with the previous require('discordthings-api') pattern
103
+ module.exports.default = DiscordThings;
104
+ module.exports.DiscordThings = DiscordThings;
105
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AA4B7C,MAAa,aAAa;IAGtB;;;OAGG;IACH,YAAY,KAAa,EAAE,UAAgC,EAAE;QACzD,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAErD,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC;YACvB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,+BAA+B;YAC3D,OAAO,EAAE;gBACL,eAAe,EAAE,KAAK;gBACtB,cAAc,EAAE,kBAAkB;aACrC;SACJ,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,SAAS,CAAC,KAAa,EAAE,WAAmB,EAAE,UAAmB,EAAE,SAAkB,EAAE,YAAgD;QACzI,IAAI,CAAC,KAAK,IAAI,WAAW,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAEjG,IAAI,CAAC;YACD,MAAM,OAAO,GAAQ;gBACjB,YAAY,EAAE,WAAW;aAC5B,CAAC;YACF,IAAI,UAAU,KAAK,SAAS;gBAAE,OAAO,CAAC,WAAW,GAAG,UAAU,CAAC;YAC/D,IAAI,SAAS,KAAK,SAAS;gBAAE,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;YAC5D,IAAI,YAAY,KAAK,SAAS;gBAAE,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;YAEpE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM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,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,CAAC,QAAQ,CAAC,MAAM,MAAM,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACvH,CAAC;QACD,MAAM,KAAK,CAAC;IAChB,CAAC;CACJ;AA1FD,sCA0FC;AAED,0CAA0C;AAC1C,kBAAe,aAAa,CAAC;AAC7B,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;AAC/B,mFAAmF;AACnF,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,aAAa,CAAC;AACvC,MAAM,CAAC,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "discordthings-api",
3
- "version": "1.1.1",
3
+ "version": "1.1.6",
4
4
  "description": "Official API Wrapper for DiscordThings.com",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
6
10
  "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build",
7
13
  "test": "echo \"Error: no test specified\" && exit 1"
8
14
  },
9
15
  "keywords": [
@@ -22,5 +28,9 @@
22
28
  "repository": {
23
29
  "type": "git",
24
30
  "url": "https://github.com/wdiscordthings/discordthings-api.git"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^25.0.3",
34
+ "typescript": "^5.9.3"
25
35
  }
26
36
  }
package/index.js DELETED
@@ -1,91 +0,0 @@
1
- const axios = require('axios');
2
-
3
- class DiscordThings {
4
- /**
5
- * @param {string} token - Your Bot's API Token (from User Profile)
6
- * @param {Object} options - Optional settings
7
- * @param {string} [options.baseUrl='https://discordthings.com/api'] - API Base URL
8
- */
9
- constructor(token, options = {}) {
10
- if (!token) throw new Error('A valid API Token is required');
11
-
12
- this.token = token;
13
- this.baseUrl = options.baseUrl || 'https://discordthings.com/api';
14
-
15
- this.client = axios.create({
16
- baseURL: this.baseUrl,
17
- headers: {
18
- 'Content-Type': 'application/json',
19
- 'Authorization': this.token
20
- }
21
- });
22
- }
23
-
24
- /**
25
- * Post Server and Shard Count Stats
26
- * @param {string} botId - The ID of the bot
27
- * @param {number} serverCount - Total number of servers
28
- * @param {number} [shardCount=0] - Total number of shards (optional)
29
- * @returns {Promise<Object>} API Response
30
- */
31
- async postStats(botId, serverCount, shardCount = 0) {
32
- if (!botId) throw new Error('Bot ID is required');
33
-
34
- try {
35
- const response = await this.client.post(`/bots/${botId}/stats`, {
36
- server_count: serverCount,
37
- shard_count: shardCount
38
- });
39
- return response.data;
40
- } catch (error) {
41
- this._handleError(error);
42
- }
43
- }
44
-
45
- /**
46
- * Check if a user has voted for a bot
47
- * @param {string} botId - The ID of the bot
48
- * @param {string} userId - The ID of the user to check
49
- * @returns {Promise<Object>} { voted: boolean, lastVote: Date, nextVote: Date }
50
- */
51
- async checkVote(botId, userId) {
52
- if (!botId || !userId) throw new Error('Bot ID and User ID are required');
53
-
54
- try {
55
- const response = await this.client.get(`/bots/${botId}/check-vote`, {
56
- params: { userId }
57
- });
58
- return response.data;
59
- } catch (error) {
60
- this._handleError(error);
61
- }
62
- }
63
-
64
- /**
65
- * Sync commands for the bot
66
- * @param {string} botId - The ID of the bot
67
- * @param {Array} commands - Array of command objects
68
- * @returns {Promise<Object>} API Response
69
- */
70
- async syncCommands(botId, commands) {
71
- if (!botId || !Array.isArray(commands)) throw new Error('Bot ID and commands array are required');
72
-
73
- try {
74
- const response = await this.client.post(`/bots/${botId}/commands`, {
75
- commands
76
- });
77
- return response.data;
78
- } catch (error) {
79
- this._handleError(error);
80
- }
81
- }
82
-
83
- _handleError(error) {
84
- if (error.response) {
85
- throw new Error(`API Error [${error.response.status}]: ${error.response.data.error || error.response.statusText}`);
86
- }
87
- throw error;
88
- }
89
- }
90
-
91
- module.exports = DiscordThings;