@stonyx/discord 0.1.1-alpha.12 → 0.1.1-alpha.14
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 +3 -3
- package/dist/bot.d.ts +6 -1
- package/dist/bot.js +17 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -241,10 +241,10 @@ const guild = await bot.getGuild();
|
|
|
241
241
|
|
|
242
242
|
### clearChannelMessages(channelId)
|
|
243
243
|
|
|
244
|
-
Delete all fetched messages in a channel (up to `maxMessagesPerRequest`).
|
|
244
|
+
Delete all fetched messages in a channel (up to `maxMessagesPerRequest`). Awaits every delete via `Promise.allSettled` and resolves with a structured `{ deleted, failed, errors }` so callers can act on partial failure. Never throws on individual delete failures; emits a single `log.warn` summary when any deletes fail.
|
|
245
245
|
|
|
246
246
|
```javascript
|
|
247
|
-
await bot.clearChannelMessages('123456789');
|
|
247
|
+
const { deleted, failed, errors } = await bot.clearChannelMessages('123456789');
|
|
248
248
|
```
|
|
249
249
|
|
|
250
250
|
### giveRole(memberId, roleId)
|
|
@@ -297,7 +297,7 @@ Configuration is read from `stonyx/config` under `discord`:
|
|
|
297
297
|
| `getChannelMessages(channelId, options?)` | Fetch channel messages |
|
|
298
298
|
| `getChannelMessage(channelId, messageId)` | Fetch a single message |
|
|
299
299
|
| `getGuild(guildId?)` | Fetch a guild |
|
|
300
|
-
| `clearChannelMessages(channelId)` | Delete messages in a channel |
|
|
300
|
+
| `clearChannelMessages(channelId)` | Delete messages in a channel; returns `{ deleted, failed, errors }` and never throws on partial failure |
|
|
301
301
|
| `giveRole(memberId, roleId)` | Add a role to a member |
|
|
302
302
|
| `close()` | Destroy the Discord client and clear singleton |
|
|
303
303
|
| `reset()` | Close + clear all commands and handlers |
|
package/dist/bot.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Client } from 'discord.js';
|
|
2
2
|
import type { ChatInputCommandInteraction, Message } from 'discord.js';
|
|
3
|
+
export interface ClearChannelMessagesResult {
|
|
4
|
+
deleted: number;
|
|
5
|
+
failed: number;
|
|
6
|
+
errors: Error[];
|
|
7
|
+
}
|
|
3
8
|
interface CommandInstance {
|
|
4
9
|
data?: {
|
|
5
10
|
name: string;
|
|
@@ -36,7 +41,7 @@ export default class DiscordBot {
|
|
|
36
41
|
getChannelMessages(channelId: string, options?: Record<string, unknown>): Promise<unknown>;
|
|
37
42
|
getChannelMessage(channelId: string, messageId: string): Promise<unknown>;
|
|
38
43
|
getGuild(guildId?: string): Promise<unknown>;
|
|
39
|
-
clearChannelMessages(channelId: string): Promise<
|
|
44
|
+
clearChannelMessages(channelId: string): Promise<ClearChannelMessagesResult>;
|
|
40
45
|
giveRole(memberId: string, roleId: string): Promise<void>;
|
|
41
46
|
close(): void;
|
|
42
47
|
reset(): void;
|
package/dist/bot.js
CHANGED
|
@@ -17,6 +17,10 @@ export default class DiscordBot {
|
|
|
17
17
|
DiscordBot.instance = this;
|
|
18
18
|
}
|
|
19
19
|
async init() {
|
|
20
|
+
// Self-register so log.discord works even when @stonyx/discord is in the
|
|
21
|
+
// consumer's `dependencies` (stonyx loader only merges devDependencies).
|
|
22
|
+
const { logColor = '#7289da', logMethod = 'discord' } = config.discord;
|
|
23
|
+
log.defineType(logMethod, logColor);
|
|
20
24
|
if (this.client) {
|
|
21
25
|
// Already initialized — singleton reuse via Discord.init() or a direct
|
|
22
26
|
// new DiscordBot().init() call. Wait for the existing ready promise
|
|
@@ -182,10 +186,20 @@ export default class DiscordBot {
|
|
|
182
186
|
return await this.client.guilds.fetch(guildId || config.discord.serverId || '');
|
|
183
187
|
}
|
|
184
188
|
async clearChannelMessages(channelId) {
|
|
185
|
-
const promises = [];
|
|
186
189
|
const messages = await this.getChannelMessages(channelId);
|
|
187
|
-
messages.
|
|
188
|
-
|
|
190
|
+
const settled = await Promise.allSettled([...messages.values()].map(m => m.delete()));
|
|
191
|
+
const errors = settled
|
|
192
|
+
.filter((s) => s.status === 'rejected')
|
|
193
|
+
.map(s => s.reason instanceof Error ? s.reason : new Error(String(s.reason)));
|
|
194
|
+
const result = {
|
|
195
|
+
deleted: settled.length - errors.length,
|
|
196
|
+
failed: errors.length,
|
|
197
|
+
errors,
|
|
198
|
+
};
|
|
199
|
+
if (result.failed > 0) {
|
|
200
|
+
log.warn(`clearChannelMessages partial failure on channel ${channelId}: deleted=${result.deleted} failed=${result.failed} errors=${errors.map(String).join('; ')}`);
|
|
201
|
+
}
|
|
202
|
+
return result;
|
|
189
203
|
}
|
|
190
204
|
async giveRole(memberId, roleId) {
|
|
191
205
|
const guild = await this.getGuild();
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"stonyx-async",
|
|
5
5
|
"stonyx-module"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.1.1-alpha.
|
|
7
|
+
"version": "0.1.1-alpha.14",
|
|
8
8
|
"description": "Discord bot module for the Stonyx framework",
|
|
9
9
|
"main": "dist/main.js",
|
|
10
10
|
"types": "dist/main.d.ts",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"stonyx": ">=0.2.3-beta.4"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@stonyx/utils": "0.2.3-beta.
|
|
67
|
+
"@stonyx/utils": "0.2.3-beta.24",
|
|
68
68
|
"@types/node": "^25.5.2",
|
|
69
69
|
"@types/qunit": "^2.19.13",
|
|
70
70
|
"@types/sinon": "^21.0.1",
|
|
71
71
|
"qunit": "^2.24.1",
|
|
72
72
|
"sinon": "^21.0.0",
|
|
73
|
-
"stonyx": "0.2.3-beta.
|
|
73
|
+
"stonyx": "0.2.3-beta.65",
|
|
74
74
|
"tsx": "^4.21.0",
|
|
75
75
|
"typescript": "^5.8.3"
|
|
76
76
|
},
|