@statcord-ts/sapphire-plugin 0.0.0-stage → 0.0.1-dev
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/LICENSE +19 -0
- package/README.md +22 -2
- package/dist/index.d.mts +14 -0
- package/dist/index.mjs +1 -0
- package/dist/register.d.mts +8 -0
- package/dist/register.mjs +117 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Vorasion Development
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tsdown-starter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A starter for creating a TypeScript package.
|
|
4
|
+
|
|
5
|
+
## Development
|
|
6
|
+
|
|
7
|
+
- Install dependencies:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Run the unit tests:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm run test
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Build the library:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm run build
|
|
23
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Statcord } from "@statcord-ts/core";
|
|
2
|
+
import { StatcordPluginOptions } from "@statcord-ts/plugin-options";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare module '@sapphire/pieces' {
|
|
5
|
+
interface Container {
|
|
6
|
+
statcord: Statcord;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare module 'discord.js' {
|
|
10
|
+
interface ClientOptions {
|
|
11
|
+
statcord?: StatcordPluginOptions;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "./index.mjs";
|
|
2
|
+
import { Plugin, SapphireClient, postInitialization, postLogin } from "@sapphire/framework";
|
|
3
|
+
//#region src/register.d.ts
|
|
4
|
+
export declare class StatcordPlugin extends Plugin {
|
|
5
|
+
static [postInitialization](this: SapphireClient): void;
|
|
6
|
+
static [postLogin](this: SapphireClient): void;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Events, Listener, Plugin, SapphireClient, container, postInitialization, postLogin } from "@sapphire/framework";
|
|
2
|
+
import { Time } from "@sapphire/timestamp";
|
|
3
|
+
import { Statcord } from "@statcord-ts/core";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { container as container$1 } from "@sapphire/pieces";
|
|
6
|
+
import { OSUtils } from "node-os-utils";
|
|
7
|
+
//#region src/maps.ts
|
|
8
|
+
const charts = /* @__PURE__ */ new Map();
|
|
9
|
+
const commands = /* @__PURE__ */ new Map();
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/lib/postStats.ts
|
|
12
|
+
const osUtils = new OSUtils();
|
|
13
|
+
async function getCpuUsage() {
|
|
14
|
+
return await osUtils.cpu.usage();
|
|
15
|
+
}
|
|
16
|
+
function getRamUsage() {
|
|
17
|
+
return (os.totalmem() - os.freemem()) / os.totalmem() * 100;
|
|
18
|
+
}
|
|
19
|
+
async function postStats() {
|
|
20
|
+
const { client, statcord } = container$1;
|
|
21
|
+
const guildCount = client.guilds.cache.size;
|
|
22
|
+
const shardCount = client.ws.shards.size;
|
|
23
|
+
const userCount = client.users.cache.size;
|
|
24
|
+
const memberCount = client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0);
|
|
25
|
+
const builder = statcord.createPayloadBuilder().setGuildCount(guildCount).setShardCount(shardCount).setUserCount(userCount).setMemberCount(memberCount);
|
|
26
|
+
if (charts.size > 0) builder.setCustomCharts(Array.from(charts.values()));
|
|
27
|
+
if (commands.size > 0) builder.setTopCommands(Array.from(commands.values()));
|
|
28
|
+
const statcordAutopostOptions = container$1.client.options.statcord?.autopost;
|
|
29
|
+
if (typeof statcordAutopostOptions === "object" && statcordAutopostOptions.includeRam) builder.setRamUsage(getRamUsage()).setTotalRam(os.totalmem());
|
|
30
|
+
if (typeof statcordAutopostOptions === "object" && statcordAutopostOptions.includeCpu) {
|
|
31
|
+
const cpuUsage = await getCpuUsage();
|
|
32
|
+
if (!cpuUsage.success) {
|
|
33
|
+
container$1.logger.warn("Failed to retrieve CPU usage, pushing without it.");
|
|
34
|
+
await statcord.postStats(builder.build());
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
builder.setCpuUsage(cpuUsage.data);
|
|
38
|
+
}
|
|
39
|
+
await statcord.postStats(builder.build());
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/listeners/PluginChatInputCommandAccepted.ts
|
|
43
|
+
var StatcordPluginChatInputCommandAcceptedListener = class extends Listener {
|
|
44
|
+
constructor(context, options) {
|
|
45
|
+
super(context, {
|
|
46
|
+
...options,
|
|
47
|
+
name: "PluginStatcordChatInputCommandAccepted",
|
|
48
|
+
event: Events.ChatInputCommandAccepted
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
run({ command }) {
|
|
52
|
+
if (this.container.client.options.statcord?.debug) this.container.logger.debug(`[Statcord] Logging use of the ${command.name} interaction command`);
|
|
53
|
+
const currentCommand = commands.get(command.name);
|
|
54
|
+
if (currentCommand) currentCommand.count++;
|
|
55
|
+
else {
|
|
56
|
+
if (this.container.client.options.statcord?.debug) this.container.logger.debug(`[Statcord] Command ${command.name} not found in the commands map, setting it...`);
|
|
57
|
+
commands.set(command.name, {
|
|
58
|
+
name: command.name,
|
|
59
|
+
count: 1
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/listeners/PluginMessageCommandAccepted.ts
|
|
66
|
+
var StatcordPluginMessageCommandAcceptedListener = class extends Listener {
|
|
67
|
+
constructor(context, options) {
|
|
68
|
+
super(context, {
|
|
69
|
+
...options,
|
|
70
|
+
name: "PluginStatcordMessageCommandAccepted",
|
|
71
|
+
event: Events.MessageCommandAccepted
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
run({ command }) {
|
|
75
|
+
if (this.container.client.options.statcord?.debug) this.container.logger.debug(`[Statcord] Logging use of the ${command.name} message command`);
|
|
76
|
+
const currentCommand = commands.get(command.name);
|
|
77
|
+
if (currentCommand) currentCommand.count++;
|
|
78
|
+
else {
|
|
79
|
+
if (this.container.client.options.statcord?.debug) this.container.logger.debug(`[Statcord] Command ${command.name} not found in the commands map, setting it...`);
|
|
80
|
+
commands.set(command.name, {
|
|
81
|
+
name: command.name,
|
|
82
|
+
count: 1
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/listeners/load.ts
|
|
89
|
+
function loadListeners() {
|
|
90
|
+
const store = "listeners";
|
|
91
|
+
container$1.stores.loadPiece({
|
|
92
|
+
name: "PluginStatcordChatInputCommandAccepted",
|
|
93
|
+
piece: StatcordPluginChatInputCommandAcceptedListener,
|
|
94
|
+
store
|
|
95
|
+
});
|
|
96
|
+
container$1.stores.loadPiece({
|
|
97
|
+
name: "PluginStatcordMessageCommandAccepted",
|
|
98
|
+
piece: StatcordPluginMessageCommandAcceptedListener,
|
|
99
|
+
store
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/register.ts
|
|
104
|
+
var StatcordPlugin = class extends Plugin {
|
|
105
|
+
static [postInitialization]() {
|
|
106
|
+
loadListeners();
|
|
107
|
+
}
|
|
108
|
+
static [postLogin]() {
|
|
109
|
+
container.statcord = new Statcord(this.user.id, this.options.statcord?.apiKey, this.options.statcord?.httpTimeout);
|
|
110
|
+
const statcordAutoposting = this.options.statcord?.autopost;
|
|
111
|
+
if (typeof statcordAutoposting === "object" && statcordAutoposting?.enabled || statcordAutoposting === true) setInterval(() => void postStats(), typeof statcordAutoposting === "object" ? statcordAutoposting?.interval ?? Time.Minute : Time.Minute);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
SapphireClient.plugins.registerPostInitializationHook(StatcordPlugin[postInitialization], "Statcord-PostInitialization");
|
|
115
|
+
SapphireClient.plugins.registerPostLoginHook(StatcordPlugin[postLogin], "Statcord-PostLogin");
|
|
116
|
+
//#endregion
|
|
117
|
+
export { StatcordPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statcord-ts/sapphire-plugin",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-dev",
|
|
4
|
+
"description": "The Sapphire plugin for Statcord.",
|
|
5
|
+
"homepage": "https://github.com/Vorasion-Development/statcord.ts#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Vorasion-Development/statcord.ts/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Vorasion Development",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Vorasion-Development/statcord.ts.git"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md",
|
|
19
|
+
"package.json"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./dist/index.mjs",
|
|
24
|
+
"./register": "./dist/register.mjs",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@sapphire/timestamp": "^1.0.5",
|
|
32
|
+
"@statcord-ts/core": "^0.0.1-dev",
|
|
33
|
+
"@statcord-ts/plugin-options": "^0.0.1-dev",
|
|
34
|
+
"node-os-utils": "^3.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@sapphire/framework": "^5",
|
|
38
|
+
"@sapphire/pieces": "^4.4.1",
|
|
39
|
+
"@types/node": "^26.1.1",
|
|
40
|
+
"bumpp": "^11.1.0",
|
|
41
|
+
"discord.js": "^14",
|
|
42
|
+
"tsdown": "^0.23",
|
|
43
|
+
"typescript": "^7.0.2",
|
|
44
|
+
"vitest": "^5.0.4"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@sapphire/framework": "^5",
|
|
48
|
+
"@sapphire/pieces": "^4",
|
|
49
|
+
"discord.js": "^14"
|
|
50
|
+
},
|
|
51
|
+
"readme": "README.md"
|
|
52
|
+
}
|