necord 3.0.8 → 4.0.0
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/.prettierrc +1 -1
- package/README.md +6 -3
- package/dist/context/index.d.ts +0 -1
- package/dist/context/index.js +0 -1
- package/dist/context/necord-arguments-host.d.ts +2 -0
- package/dist/context/necord-arguments-host.js +3 -0
- package/dist/context/necord-execution-context.d.ts +0 -2
- package/dist/context/necord-execution-context.js +0 -6
- package/dist/context/necord-params.factory.d.ts +5 -1
- package/dist/context/necord-params.factory.js +11 -13
- package/dist/decorators/autocomplete.decorator.d.ts +3 -0
- package/dist/decorators/autocomplete.decorator.js +7 -0
- package/dist/decorators/commands.decorator.d.ts +5 -10
- package/dist/decorators/commands.decorator.js +34 -5
- package/dist/decorators/components.decorator.js +5 -3
- package/dist/decorators/guilds.decorator.d.ts +3 -0
- package/dist/decorators/guilds.decorator.js +9 -0
- package/dist/decorators/index.d.ts +2 -1
- package/dist/decorators/index.js +2 -1
- package/dist/decorators/listeners.decorator.d.ts +3 -2
- package/dist/decorators/listeners.decorator.js +10 -3
- package/dist/decorators/options.decorator.d.ts +49 -21
- package/dist/decorators/options.decorator.js +19 -10
- package/dist/decorators/params.decorator.d.ts +3 -3
- package/dist/decorators/params.decorator.js +6 -6
- package/dist/{utils/create-necord-params.util.d.ts → decorators/params.util.d.ts} +0 -0
- package/dist/{utils/create-necord-params.util.js → decorators/params.util.js} +0 -0
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/{services → exceptions}/index.js +1 -5
- package/dist/exceptions/necord.exception.d.ts +2 -0
- package/dist/exceptions/necord.exception.js +6 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/interfaces/index.d.ts +3 -5
- package/dist/interfaces/index.js +3 -5
- package/dist/interfaces/necord-events.interface.d.ts +84 -0
- package/dist/interfaces/{command-metadata.interface.js → necord-events.interface.js} +0 -0
- package/dist/interfaces/necord-metadata.interface.d.ts +38 -0
- package/dist/interfaces/{component-metadata.interface.js → necord-metadata.interface.js} +0 -0
- package/dist/interfaces/{module-options.interface.d.ts → necord-options.interface.d.ts} +2 -3
- package/dist/interfaces/{listener-metadata.interface.js → necord-options.interface.js} +0 -0
- package/dist/necord-explorer.d.ts +29 -0
- package/dist/necord-explorer.js +116 -0
- package/dist/necord-interaction.update.d.ts +9 -0
- package/dist/necord-interaction.update.js +123 -0
- package/dist/necord-registry.d.ts +24 -0
- package/dist/necord-registry.js +78 -0
- package/dist/necord.constants.d.ts +4 -1
- package/dist/necord.constants.js +5 -2
- package/dist/necord.module.d.ts +5 -1
- package/dist/necord.module.js +19 -12
- package/dist/necord.update.d.ts +19 -5
- package/dist/necord.update.js +282 -26
- package/package.json +12 -8
- package/dist/context/necord-paramtype.enum.d.ts +0 -6
- package/dist/context/necord-paramtype.enum.js +0 -10
- package/dist/decorators/groups.decorator.d.ts +0 -3
- package/dist/decorators/groups.decorator.js +0 -9
- package/dist/interfaces/command-metadata.interface.d.ts +0 -6
- package/dist/interfaces/component-metadata.interface.d.ts +0 -5
- package/dist/interfaces/listener-metadata.interface.d.ts +0 -5
- package/dist/interfaces/module-options.interface.js +0 -2
- package/dist/interfaces/option-metadata.interface.d.ts +0 -7
- package/dist/interfaces/option-metadata.interface.js +0 -2
- package/dist/services/commands.service.d.ts +0 -19
- package/dist/services/commands.service.js +0 -169
- package/dist/services/components.service.d.ts +0 -13
- package/dist/services/components.service.js +0 -51
- package/dist/services/explorer.service.d.ts +0 -17
- package/dist/services/explorer.service.js +0 -54
- package/dist/services/index.d.ts +0 -5
- package/dist/services/listeners.service.d.ts +0 -12
- package/dist/services/listeners.service.js +0 -47
- package/dist/services/metadata-accessor.service.d.ts +0 -13
- package/dist/services/metadata-accessor.service.js +0 -44
- package/dist/utils/create-necord-commands.util.d.ts +0 -4
- package/dist/utils/create-necord-commands.util.js +0 -9
- package/dist/utils/create-necord-components.util.d.ts +0 -2
- package/dist/utils/create-necord-components.util.js +0 -9
- package/dist/utils/create-necord-listeners.util.d.ts +0 -3
- package/dist/utils/create-necord-listeners.util.js +0 -12
- package/dist/utils/create-necord-options.util.d.ts +0 -2
- package/dist/utils/create-necord-options.util.js +0 -15
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/index.js +0 -17
package/dist/necord.update.js
CHANGED
|
@@ -11,59 +11,315 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
15
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
24
|
exports.NecordUpdate = void 0;
|
|
17
25
|
const common_1 = require("@nestjs/common");
|
|
18
26
|
const decorators_1 = require("./decorators");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
const discord_js_1 = require("discord.js");
|
|
28
|
+
const necord_constants_1 = require("./necord.constants");
|
|
29
|
+
const necord_registry_1 = require("./necord-registry");
|
|
30
|
+
let NecordUpdate = class NecordUpdate {
|
|
31
|
+
constructor(options, client, registry) {
|
|
32
|
+
var _a;
|
|
33
|
+
this.options = options;
|
|
34
|
+
this.client = client;
|
|
35
|
+
this.registry = registry;
|
|
36
|
+
this.prefix = (_a = this.options.prefix) !== null && _a !== void 0 ? _a : '!';
|
|
37
|
+
}
|
|
38
|
+
onMessageCreate([message]) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (!message || !((_a = message.content) === null || _a === void 0 ? void 0 : _a.length))
|
|
42
|
+
return;
|
|
43
|
+
const content = message.content.toLowerCase();
|
|
44
|
+
const prefix = typeof this.prefix !== 'function' ? this.prefix : yield this.prefix(message);
|
|
45
|
+
if (!prefix || !content.startsWith(prefix))
|
|
46
|
+
return;
|
|
47
|
+
const args = content.substring(prefix.length).split(/ +/g);
|
|
48
|
+
const cmd = args.shift();
|
|
49
|
+
if (!cmd)
|
|
50
|
+
return;
|
|
51
|
+
return (_b = this.registry.getTextCommand(cmd)) === null || _b === void 0 ? void 0 : _b.metadata.execute([message], args);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
emit(event, ...args) {
|
|
55
|
+
this.client.emit(event, ...args);
|
|
22
56
|
}
|
|
23
|
-
|
|
24
|
-
if (!
|
|
57
|
+
onChannelUpdate([oldChannel, newChannel]) {
|
|
58
|
+
if (!Object.prototype.hasOwnProperty.call(oldChannel, 'guild'))
|
|
25
59
|
return;
|
|
60
|
+
if (oldChannel.permissionOverwrites !==
|
|
61
|
+
newChannel.permissionOverwrites) {
|
|
62
|
+
this.emit('guildChannelPermissionsUpdate', newChannel, oldChannel.permissionOverwrites, newChannel.permissionOverwrites);
|
|
63
|
+
}
|
|
64
|
+
if (oldChannel.type === 'GUILD_TEXT' &&
|
|
65
|
+
oldChannel.topic !== newChannel.topic) {
|
|
66
|
+
this.emit('guildChannelTopicUpdate', newChannel, oldChannel.topic, newChannel.topic);
|
|
26
67
|
}
|
|
27
|
-
return this.logger.warn(message);
|
|
28
68
|
}
|
|
29
|
-
|
|
30
|
-
if (
|
|
69
|
+
onGuildMemberUpdate([oldMember, newMember]) {
|
|
70
|
+
if (oldMember.partial)
|
|
31
71
|
return;
|
|
72
|
+
if (!oldMember.premiumSince && newMember.premiumSince) {
|
|
73
|
+
this.emit('guildMemberBoost', newMember);
|
|
74
|
+
}
|
|
75
|
+
if (oldMember.premiumSince && !newMember.premiumSince) {
|
|
76
|
+
this.emit('guildMemberUnboost', newMember);
|
|
77
|
+
}
|
|
78
|
+
const addedRoles = newMember.roles.cache.reduce((acc, role) => (!oldMember.roles.cache.has(role.id) ? acc.push(role) && acc : acc), []);
|
|
79
|
+
addedRoles.forEach(role => {
|
|
80
|
+
this.emit('guildMemberRoleAdd', newMember, role);
|
|
81
|
+
});
|
|
82
|
+
const removedRoles = oldMember.roles.cache.reduce((acc, role) => (!newMember.roles.cache.has(role.id) ? acc.push(role) && acc : acc), []);
|
|
83
|
+
removedRoles.forEach(role => {
|
|
84
|
+
this.emit('guildMemberRoleRemove', newMember, role);
|
|
85
|
+
});
|
|
86
|
+
if (oldMember.nickname !== newMember.nickname) {
|
|
87
|
+
this.emit('guildMemberNicknameUpdate', newMember, oldMember.nickname, newMember.nickname);
|
|
88
|
+
}
|
|
89
|
+
if (oldMember.pending !== newMember.pending) {
|
|
90
|
+
this.emit('guildMemberEntered', newMember);
|
|
91
|
+
}
|
|
92
|
+
if (!oldMember.avatar && newMember.avatar) {
|
|
93
|
+
this.emit('guildMemberAvatarAdd', newMember, newMember.avatarURL());
|
|
94
|
+
}
|
|
95
|
+
if (oldMember.avatar !== newMember.avatar) {
|
|
96
|
+
this.emit('guildMemberAvatarUpdate', newMember, oldMember.avatarURL(), newMember.avatarURL());
|
|
97
|
+
}
|
|
98
|
+
if (oldMember.avatar && !newMember.avatar) {
|
|
99
|
+
this.emit('guildMemberAvatarRemove', newMember, oldMember.avatarURL());
|
|
32
100
|
}
|
|
33
|
-
return this.logger.error(error);
|
|
34
101
|
}
|
|
35
|
-
|
|
36
|
-
if (
|
|
102
|
+
onGuildUpdate([oldGuild, newGuild]) {
|
|
103
|
+
if (oldGuild.premiumTier < newGuild.premiumTier) {
|
|
104
|
+
this.emit('guildBoostLevelUp', newGuild, oldGuild.premiumTier, newGuild.premiumTier);
|
|
105
|
+
}
|
|
106
|
+
if (oldGuild.premiumTier > newGuild.premiumTier) {
|
|
107
|
+
this.emit('guildBoostLevelDown', oldGuild, newGuild);
|
|
108
|
+
}
|
|
109
|
+
if (!oldGuild.banner && newGuild.banner) {
|
|
110
|
+
this.emit('guildBannerAdd', newGuild, newGuild.bannerURL());
|
|
111
|
+
}
|
|
112
|
+
if (!oldGuild.afkChannel && newGuild.afkChannel) {
|
|
113
|
+
this.emit('guildAfkChannelAdd', newGuild, newGuild.afkChannel);
|
|
114
|
+
}
|
|
115
|
+
if (!oldGuild.vanityURLCode && newGuild.vanityURLCode) {
|
|
116
|
+
this.emit('guildVanityURLAdd', newGuild, newGuild.vanityURLCode);
|
|
117
|
+
}
|
|
118
|
+
if (oldGuild.vanityURLCode !== newGuild.vanityURLCode) {
|
|
119
|
+
this.emit('guildVanityURLUpdate', newGuild, oldGuild.vanityURLCode, newGuild.vanityURLCode);
|
|
120
|
+
}
|
|
121
|
+
if (oldGuild.vanityURLCode && !newGuild.vanityURLCode) {
|
|
122
|
+
this.emit('guildVanityURLRemove', newGuild, oldGuild.vanityURLCode);
|
|
123
|
+
}
|
|
124
|
+
if (oldGuild.features.length !== newGuild.features.length) {
|
|
125
|
+
this.emit('guildFeaturesUpdate', newGuild, oldGuild.features, newGuild.features);
|
|
126
|
+
}
|
|
127
|
+
if (oldGuild.nameAcronym !== newGuild.nameAcronym) {
|
|
128
|
+
this.emit('guildAcronymUpdate', oldGuild, newGuild);
|
|
129
|
+
}
|
|
130
|
+
if (oldGuild.ownerId !== newGuild.ownerId) {
|
|
131
|
+
this.emit('guildOwnerUpdate', oldGuild, newGuild);
|
|
132
|
+
}
|
|
133
|
+
if (!oldGuild.partnered && newGuild.partnered) {
|
|
134
|
+
this.emit('guildPartnerAdd', newGuild);
|
|
135
|
+
}
|
|
136
|
+
if (oldGuild.partnered && !newGuild.partnered) {
|
|
137
|
+
this.emit('guildPartnerRemove', newGuild);
|
|
138
|
+
}
|
|
139
|
+
if (!oldGuild.verified && newGuild.verified) {
|
|
140
|
+
this.emit('guildVerificationAdd', newGuild);
|
|
141
|
+
}
|
|
142
|
+
if (oldGuild.verified && !newGuild.verified) {
|
|
143
|
+
this.emit('guildVerificationRemove', newGuild);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
onMessageUpdate([oldMessage, newMessage]) {
|
|
147
|
+
if (oldMessage.partial || newMessage.partial)
|
|
37
148
|
return;
|
|
149
|
+
if (!oldMessage.pinned && newMessage.pinned) {
|
|
150
|
+
this.emit('messagePinned', newMessage);
|
|
151
|
+
}
|
|
152
|
+
if (oldMessage.content !== newMessage.content) {
|
|
153
|
+
this.emit('messageContentEdited', newMessage, oldMessage.content, newMessage.content);
|
|
38
154
|
}
|
|
39
|
-
return this.logger.debug(message);
|
|
40
155
|
}
|
|
41
|
-
|
|
42
|
-
|
|
156
|
+
onPresenceUpdate([oldPresence, newPresence]) {
|
|
157
|
+
if (!oldPresence)
|
|
158
|
+
return;
|
|
159
|
+
if (oldPresence.status !== 'offline' && newPresence.status === 'offline') {
|
|
160
|
+
this.emit('guildMemberOffline', newPresence.member, oldPresence.status);
|
|
161
|
+
}
|
|
162
|
+
if (oldPresence.status === 'offline' && newPresence.status !== 'offline') {
|
|
163
|
+
this.emit('guildMemberOnline', newPresence.member, newPresence.status);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
onRoleUpdate([oldRole, newRole]) {
|
|
167
|
+
if (oldRole.rawPosition !== newRole.rawPosition) {
|
|
168
|
+
this.emit('rolePositionUpdate', newRole, oldRole.rawPosition, newRole.rawPosition);
|
|
169
|
+
}
|
|
170
|
+
if (oldRole.permissions.bitfield !== newRole.permissions.bitfield) {
|
|
171
|
+
this.emit('rolePermissionsUpdate', newRole, oldRole.permissions, newRole.permissions);
|
|
172
|
+
}
|
|
173
|
+
if (!oldRole.icon && newRole.icon) {
|
|
174
|
+
this.emit('roleIconAdd', newRole, newRole.iconURL());
|
|
175
|
+
}
|
|
176
|
+
if (oldRole.icon !== newRole.icon) {
|
|
177
|
+
this.emit('roleIconUpdate', newRole, oldRole.iconURL(), newRole.iconURL());
|
|
178
|
+
}
|
|
179
|
+
if (oldRole.icon && !newRole.icon) {
|
|
180
|
+
this.emit('roleIconRemove', newRole, oldRole.iconURL());
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
onThreadUpdate([oldThread, newThread]) {
|
|
184
|
+
if (!Object.prototype.hasOwnProperty.call(oldThread, 'guild'))
|
|
185
|
+
return;
|
|
186
|
+
if (oldThread.archived !== newThread.archived) {
|
|
187
|
+
this.emit('threadStateUpdate', oldThread, newThread);
|
|
188
|
+
}
|
|
189
|
+
if (oldThread.name !== newThread.name) {
|
|
190
|
+
this.emit('threadNameUpdate', newThread, oldThread.name, newThread.name);
|
|
191
|
+
}
|
|
192
|
+
if (oldThread.locked !== newThread.locked) {
|
|
193
|
+
this.emit('threadLockStateUpdate', oldThread, newThread);
|
|
194
|
+
}
|
|
195
|
+
if (oldThread.rateLimitPerUser !== newThread.rateLimitPerUser) {
|
|
196
|
+
this.emit('threadRateLimitPerUserUpdate', newThread, oldThread.rateLimitPerUser, newThread.rateLimitPerUser);
|
|
197
|
+
}
|
|
198
|
+
if (oldThread.autoArchiveDuration !== newThread.autoArchiveDuration) {
|
|
199
|
+
this.emit('threadAutoArchiveDurationUpdate', newThread, oldThread.autoArchiveDuration, newThread.autoArchiveDuration);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
onUserUpdate([oldUser, newUser]) {
|
|
203
|
+
if (oldUser.partial)
|
|
204
|
+
return;
|
|
205
|
+
if (oldUser.displayAvatarURL() !== newUser.displayAvatarURL()) {
|
|
206
|
+
this.emit('userAvatarUpdate', newUser, oldUser.displayAvatarURL(), newUser.displayAvatarURL());
|
|
207
|
+
}
|
|
208
|
+
if (oldUser.username !== newUser.username) {
|
|
209
|
+
this.emit('userUsernameUpdate', newUser, oldUser.username, newUser.username);
|
|
210
|
+
}
|
|
211
|
+
if (oldUser.discriminator !== newUser.discriminator) {
|
|
212
|
+
this.emit('userDiscriminatorUpdate', newUser, oldUser.discriminator, newUser.discriminator);
|
|
213
|
+
}
|
|
214
|
+
if (oldUser.flags !== newUser.flags) {
|
|
215
|
+
this.emit('userFlagsUpdate', newUser, oldUser.flags, newUser.flags);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
onVoiceStateUpdate([oldState, newState]) {
|
|
219
|
+
const newMember = newState.member;
|
|
220
|
+
if (!oldState.channel && newState.channel) {
|
|
221
|
+
this.emit('voiceChannelJoin', newMember, newState.channel);
|
|
222
|
+
}
|
|
223
|
+
if (oldState.channel && newState.channel && oldState.channel.id !== newState.channel.id) {
|
|
224
|
+
this.emit('voiceChannelSwitch', newMember, oldState.channel, newState.channel);
|
|
225
|
+
}
|
|
226
|
+
if (oldState.channel && !newState.channel) {
|
|
227
|
+
this.emit('voiceChannelLeave', newMember, oldState.channel);
|
|
228
|
+
}
|
|
229
|
+
if (!oldState.mute && newState.mute) {
|
|
230
|
+
this.emit('voiceChannelMute', newMember, newState.selfMute ? 'self-muted' : 'server-muted');
|
|
231
|
+
}
|
|
232
|
+
if (oldState.mute && !newState.mute) {
|
|
233
|
+
this.emit('voiceChannelUnmute', newMember, oldState.selfMute ? 'self-muted' : 'server-muted');
|
|
234
|
+
}
|
|
235
|
+
if (!oldState.deaf && newState.deaf) {
|
|
236
|
+
this.emit('voiceChannelDeaf', newMember, newState.selfDeaf ? 'self-deafed' : 'server-deafed');
|
|
237
|
+
}
|
|
238
|
+
if (oldState.deaf && !newState.deaf) {
|
|
239
|
+
this.emit('voiceChannelUndeaf', newMember, oldState.selfDeaf ? 'self-deafed' : 'server-deafed');
|
|
240
|
+
}
|
|
241
|
+
if (!oldState.streaming && newState.streaming) {
|
|
242
|
+
this.emit('voiceStreamingStart', newMember, newState.channel);
|
|
243
|
+
}
|
|
244
|
+
if (oldState.streaming && !newState.streaming) {
|
|
245
|
+
this.emit('voiceStreamingStop', newMember, newState.channel);
|
|
246
|
+
}
|
|
43
247
|
}
|
|
44
248
|
};
|
|
45
249
|
__decorate([
|
|
46
|
-
(0, decorators_1.On)('
|
|
250
|
+
(0, decorators_1.On)('messageCreate'),
|
|
251
|
+
__param(0, (0, decorators_1.Context)()),
|
|
252
|
+
__metadata("design:type", Function),
|
|
253
|
+
__metadata("design:paramtypes", [Object]),
|
|
254
|
+
__metadata("design:returntype", Promise)
|
|
255
|
+
], NecordUpdate.prototype, "onMessageCreate", null);
|
|
256
|
+
__decorate([
|
|
257
|
+
(0, decorators_1.On)('channelUpdate'),
|
|
258
|
+
__param(0, (0, decorators_1.Context)()),
|
|
259
|
+
__metadata("design:type", Function),
|
|
260
|
+
__metadata("design:paramtypes", [Object]),
|
|
261
|
+
__metadata("design:returntype", void 0)
|
|
262
|
+
], NecordUpdate.prototype, "onChannelUpdate", null);
|
|
263
|
+
__decorate([
|
|
264
|
+
(0, decorators_1.On)('guildMemberUpdate'),
|
|
265
|
+
__param(0, (0, decorators_1.Context)()),
|
|
266
|
+
__metadata("design:type", Function),
|
|
267
|
+
__metadata("design:paramtypes", [Object]),
|
|
268
|
+
__metadata("design:returntype", void 0)
|
|
269
|
+
], NecordUpdate.prototype, "onGuildMemberUpdate", null);
|
|
270
|
+
__decorate([
|
|
271
|
+
(0, decorators_1.On)('guildUpdate'),
|
|
272
|
+
__param(0, (0, decorators_1.Context)()),
|
|
273
|
+
__metadata("design:type", Function),
|
|
274
|
+
__metadata("design:paramtypes", [Object]),
|
|
275
|
+
__metadata("design:returntype", void 0)
|
|
276
|
+
], NecordUpdate.prototype, "onGuildUpdate", null);
|
|
277
|
+
__decorate([
|
|
278
|
+
(0, decorators_1.On)('messageUpdate'),
|
|
279
|
+
__param(0, (0, decorators_1.Context)()),
|
|
280
|
+
__metadata("design:type", Function),
|
|
281
|
+
__metadata("design:paramtypes", [Object]),
|
|
282
|
+
__metadata("design:returntype", void 0)
|
|
283
|
+
], NecordUpdate.prototype, "onMessageUpdate", null);
|
|
284
|
+
__decorate([
|
|
285
|
+
(0, decorators_1.On)('presenceUpdate'),
|
|
286
|
+
__param(0, (0, decorators_1.Context)()),
|
|
287
|
+
__metadata("design:type", Function),
|
|
288
|
+
__metadata("design:paramtypes", [Object]),
|
|
289
|
+
__metadata("design:returntype", void 0)
|
|
290
|
+
], NecordUpdate.prototype, "onPresenceUpdate", null);
|
|
291
|
+
__decorate([
|
|
292
|
+
(0, decorators_1.On)('roleUpdate'),
|
|
293
|
+
__param(0, (0, decorators_1.Context)()),
|
|
294
|
+
__metadata("design:type", Function),
|
|
295
|
+
__metadata("design:paramtypes", [Object]),
|
|
296
|
+
__metadata("design:returntype", void 0)
|
|
297
|
+
], NecordUpdate.prototype, "onRoleUpdate", null);
|
|
298
|
+
__decorate([
|
|
299
|
+
(0, decorators_1.On)('threadUpdate'),
|
|
47
300
|
__param(0, (0, decorators_1.Context)()),
|
|
48
301
|
__metadata("design:type", Function),
|
|
49
|
-
__metadata("design:paramtypes", [
|
|
302
|
+
__metadata("design:paramtypes", [Object]),
|
|
50
303
|
__metadata("design:returntype", void 0)
|
|
51
|
-
], NecordUpdate.prototype, "
|
|
304
|
+
], NecordUpdate.prototype, "onThreadUpdate", null);
|
|
52
305
|
__decorate([
|
|
53
|
-
(0, decorators_1.On)('
|
|
306
|
+
(0, decorators_1.On)('userUpdate'),
|
|
54
307
|
__param(0, (0, decorators_1.Context)()),
|
|
55
308
|
__metadata("design:type", Function),
|
|
56
|
-
__metadata("design:paramtypes", [
|
|
309
|
+
__metadata("design:paramtypes", [Object]),
|
|
57
310
|
__metadata("design:returntype", void 0)
|
|
58
|
-
], NecordUpdate.prototype, "
|
|
311
|
+
], NecordUpdate.prototype, "onUserUpdate", null);
|
|
59
312
|
__decorate([
|
|
60
|
-
(0, decorators_1.On)('
|
|
313
|
+
(0, decorators_1.On)('voiceStateUpdate'),
|
|
61
314
|
__param(0, (0, decorators_1.Context)()),
|
|
62
315
|
__metadata("design:type", Function),
|
|
63
|
-
__metadata("design:paramtypes", [
|
|
316
|
+
__metadata("design:paramtypes", [Object]),
|
|
64
317
|
__metadata("design:returntype", void 0)
|
|
65
|
-
], NecordUpdate.prototype, "
|
|
66
|
-
NecordUpdate =
|
|
67
|
-
(0, common_1.Injectable)()
|
|
318
|
+
], NecordUpdate.prototype, "onVoiceStateUpdate", null);
|
|
319
|
+
NecordUpdate = __decorate([
|
|
320
|
+
(0, common_1.Injectable)(),
|
|
321
|
+
__param(0, (0, common_1.Inject)(necord_constants_1.NECORD_MODULE_OPTIONS)),
|
|
322
|
+
__metadata("design:paramtypes", [Object, discord_js_1.Client,
|
|
323
|
+
necord_registry_1.NecordRegistry])
|
|
68
324
|
], NecordUpdate);
|
|
69
325
|
exports.NecordUpdate = NecordUpdate;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "necord",
|
|
3
3
|
"description": "A module for creating Discord bots using NestJS, based on Discord.js.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf -rf dist && tsc -p tsconfig.json",
|
|
7
7
|
"prepublish:npm": "npm run build",
|
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
"prepublish:dev": "npm run build",
|
|
10
10
|
"publish:dev": "npm publish --access public --tag dev",
|
|
11
11
|
"prepare": "husky install .github/husky",
|
|
12
|
-
"test": "echo add tests",
|
|
13
12
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
14
|
-
"lint": "eslint --ignore-path .gitignore
|
|
13
|
+
"lint": "eslint --ignore-path .gitignore src/**/*.ts"
|
|
14
|
+
},
|
|
15
|
+
"directories": {
|
|
16
|
+
"lib": "src",
|
|
17
|
+
"test": "test"
|
|
15
18
|
},
|
|
16
19
|
"main": "./dist/index.js",
|
|
17
20
|
"types": "./dist/index.d.ts",
|
|
@@ -42,24 +45,25 @@
|
|
|
42
45
|
],
|
|
43
46
|
"dependencies": {},
|
|
44
47
|
"devDependencies": {
|
|
45
|
-
"@commitlint/cli": "16.0.
|
|
48
|
+
"@commitlint/cli": "16.0.2",
|
|
46
49
|
"@commitlint/config-angular": "16.0.0",
|
|
47
50
|
"@favware/npm-deprecate": "1.0.4",
|
|
48
51
|
"@nestjs/common": "8.2.4",
|
|
49
52
|
"@nestjs/core": "8.2.4",
|
|
50
|
-
"@types/node": "17.0.
|
|
53
|
+
"@types/node": "17.0.8",
|
|
51
54
|
"@typescript-eslint/eslint-plugin": "4.33.0",
|
|
52
55
|
"@typescript-eslint/parser": "4.33.0",
|
|
53
|
-
"discord.js": "13.
|
|
56
|
+
"discord.js": "13.5.1",
|
|
54
57
|
"eslint": "7.32.0",
|
|
55
58
|
"eslint-config-prettier": "8.3.0",
|
|
56
59
|
"eslint-plugin-prettier": "4.0.0",
|
|
57
60
|
"husky": "7.0.4",
|
|
58
61
|
"prettier": "2.5.1",
|
|
59
62
|
"reflect-metadata": "0.1.13",
|
|
60
|
-
"release-it": "14.
|
|
63
|
+
"release-it": "14.12.1",
|
|
61
64
|
"rimraf": "3.0.2",
|
|
62
|
-
"rxjs": "7.
|
|
65
|
+
"rxjs": "7.5.1",
|
|
66
|
+
"ts-node": "^10.4.0",
|
|
63
67
|
"typescript": "4.5.4"
|
|
64
68
|
},
|
|
65
69
|
"peerDependencies": {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NecordParamType = void 0;
|
|
4
|
-
var NecordParamType;
|
|
5
|
-
(function (NecordParamType) {
|
|
6
|
-
NecordParamType[NecordParamType["CONTEXT"] = 0] = "CONTEXT";
|
|
7
|
-
NecordParamType[NecordParamType["VALUES"] = 1] = "VALUES";
|
|
8
|
-
NecordParamType[NecordParamType["OPTIONS"] = 2] = "OPTIONS";
|
|
9
|
-
NecordParamType[NecordParamType["COMPONENT"] = 3] = "COMPONENT";
|
|
10
|
-
})(NecordParamType = exports.NecordParamType || (exports.NecordParamType = {}));
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ApplicationCommandSubGroupData, ChatInputApplicationCommandData } from 'discord.js';
|
|
2
|
-
export declare const CommandGroup: (data?: Omit<ChatInputApplicationCommandData, 'type' | 'options'>) => import("@nestjs/common").CustomDecorator<string>;
|
|
3
|
-
export declare const CommandSubGroup: (data?: Omit<ApplicationCommandSubGroupData, 'type' | 'options'>) => import("@nestjs/common").CustomDecorator<string>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandSubGroup = exports.CommandGroup = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const necord_constants_1 = require("../necord.constants");
|
|
6
|
-
const CommandGroup = (data) => (0, common_1.SetMetadata)(necord_constants_1.GROUP_METADATA, Object.assign({ type: 1 /* CHAT_INPUT */, options: [] }, data));
|
|
7
|
-
exports.CommandGroup = CommandGroup;
|
|
8
|
-
const CommandSubGroup = (data) => (0, common_1.SetMetadata)(necord_constants_1.SUBGROUP_METADATA, Object.assign({ type: 2 /* SUB_COMMAND_GROUP */, options: [] }, data));
|
|
9
|
-
exports.CommandSubGroup = CommandSubGroup;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ApplicationCommandOptionData, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, CommandInteractionOptionResolver } from 'discord.js';
|
|
2
|
-
export declare type OptionData = Exclude<ApplicationCommandOptionData, ApplicationCommandSubGroupData | ApplicationCommandSubCommandData>;
|
|
3
|
-
export declare type OptionTransform = keyof CommandInteractionOptionResolver;
|
|
4
|
-
export declare type OptionMetadata<T extends OptionData['type'] = OptionData['type']> = OptionData & {
|
|
5
|
-
readonly type?: T;
|
|
6
|
-
methodName?: OptionTransform;
|
|
7
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { ExplorerService } from './explorer.service';
|
|
3
|
-
import { ApplicationCommandMetadata, NecordModuleOptions } from '../interfaces';
|
|
4
|
-
import { MetadataAccessorService } from './metadata-accessor.service';
|
|
5
|
-
import { Client } from 'discord.js';
|
|
6
|
-
export declare class CommandsService implements OnModuleInit {
|
|
7
|
-
private readonly explorerService;
|
|
8
|
-
private readonly metadataAccessor;
|
|
9
|
-
private readonly client;
|
|
10
|
-
private readonly options;
|
|
11
|
-
private readonly logger;
|
|
12
|
-
private readonly commands;
|
|
13
|
-
constructor(explorerService: ExplorerService<ApplicationCommandMetadata>, metadataAccessor: MetadataAccessorService, client: Client, options: NecordModuleOptions);
|
|
14
|
-
onModuleInit(): Promise<void>;
|
|
15
|
-
private onReadyRegistration;
|
|
16
|
-
private registerContextMenuHandler;
|
|
17
|
-
private registerSlashCommandHandler;
|
|
18
|
-
private static getCommandKey;
|
|
19
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
24
|
-
var t = {};
|
|
25
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
26
|
-
t[p] = s[p];
|
|
27
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
28
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
29
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
30
|
-
t[p[i]] = s[p[i]];
|
|
31
|
-
}
|
|
32
|
-
return t;
|
|
33
|
-
};
|
|
34
|
-
var CommandsService_1;
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.CommandsService = void 0;
|
|
37
|
-
const common_1 = require("@nestjs/common");
|
|
38
|
-
const explorer_service_1 = require("./explorer.service");
|
|
39
|
-
const metadata_accessor_service_1 = require("./metadata-accessor.service");
|
|
40
|
-
const discord_js_1 = require("discord.js");
|
|
41
|
-
const decorators_1 = require("../decorators");
|
|
42
|
-
const necord_constants_1 = require("../necord.constants");
|
|
43
|
-
let CommandsService = CommandsService_1 = class CommandsService {
|
|
44
|
-
constructor(explorerService, metadataAccessor, client, options) {
|
|
45
|
-
this.explorerService = explorerService;
|
|
46
|
-
this.metadataAccessor = metadataAccessor;
|
|
47
|
-
this.client = client;
|
|
48
|
-
this.options = options;
|
|
49
|
-
this.logger = new common_1.Logger(CommandsService_1.name);
|
|
50
|
-
this.commands = [];
|
|
51
|
-
}
|
|
52
|
-
onModuleInit() {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const commands = this.explorerService.explore((instance, prototype, method) => {
|
|
55
|
-
const command = this.metadataAccessor.getApplicationCommandMetadata(instance, method);
|
|
56
|
-
if (!command)
|
|
57
|
-
return;
|
|
58
|
-
return Object.assign(Object.assign({}, command), { instance,
|
|
59
|
-
prototype,
|
|
60
|
-
method });
|
|
61
|
-
});
|
|
62
|
-
for (let _a of commands) {
|
|
63
|
-
const { instance, prototype, method } = _a, command = __rest(_a, ["instance", "prototype", "method"]);
|
|
64
|
-
const options = this.metadataAccessor.getOptionsMetadata(instance, method);
|
|
65
|
-
let group = this.metadataAccessor.getCommandGroupMetadata(instance, method);
|
|
66
|
-
let subGroup = this.metadataAccessor.getCommandSubGroupMetadata(instance, method);
|
|
67
|
-
if (command.type !== 1 /* CHAT_INPUT */) {
|
|
68
|
-
this.commands.push(command);
|
|
69
|
-
this.registerContextMenuHandler(command, command.execute);
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
else if (!group && subGroup) {
|
|
73
|
-
subGroup = undefined;
|
|
74
|
-
}
|
|
75
|
-
command.options = Object.values(options);
|
|
76
|
-
this.registerSlashCommandHandler(group === null || group === void 0 ? void 0 : group.name, subGroup === null || subGroup === void 0 ? void 0 : subGroup.name, command, options, command.execute);
|
|
77
|
-
if (!group && !subGroup) {
|
|
78
|
-
this.commands.push(command);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const cachedGroup = this.commands.find(c => c.type === 1 /* CHAT_INPUT */ && c.name === group.name);
|
|
82
|
-
group = cachedGroup !== null && cachedGroup !== void 0 ? cachedGroup : group;
|
|
83
|
-
if (!subGroup) {
|
|
84
|
-
group.options.push(command);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
const cachedSubGroup = group.options.find(s => s.type === 2 /* SUB_COMMAND_GROUP */ && s.name === (subGroup === null || subGroup === void 0 ? void 0 : subGroup.name));
|
|
88
|
-
subGroup = cachedSubGroup !== null && cachedSubGroup !== void 0 ? cachedSubGroup : subGroup;
|
|
89
|
-
subGroup.options.push(command);
|
|
90
|
-
!cachedSubGroup && group.options.push(subGroup);
|
|
91
|
-
}
|
|
92
|
-
!cachedGroup && this.commands.push(group);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
onReadyRegistration() {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
if (!this.options.registerApplicationCommands) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (this.client.application.partial) {
|
|
102
|
-
yield this.client.application.fetch();
|
|
103
|
-
}
|
|
104
|
-
this.logger.log(`Started refreshing application commands.`);
|
|
105
|
-
yield this.client.application.commands.set(this.commands, typeof this.options.registerApplicationCommands === 'string'
|
|
106
|
-
? this.options.registerApplicationCommands
|
|
107
|
-
: undefined);
|
|
108
|
-
this.logger.log(`Successfully reloaded application commands.`);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
registerContextMenuHandler(command, execute) {
|
|
112
|
-
this.client.on('interactionCreate', interaction => interaction.isContextMenu() &&
|
|
113
|
-
interaction.targetType === (command.type === 2 /* USER */ ? 'USER' : 'MESSAGE') &&
|
|
114
|
-
interaction.commandName === command.name &&
|
|
115
|
-
execute(interaction, interaction.targetType === 'USER'
|
|
116
|
-
? {
|
|
117
|
-
user: interaction.options.getUser('user'),
|
|
118
|
-
member: interaction.options.getMember('user')
|
|
119
|
-
}
|
|
120
|
-
: { message: interaction.options.getMessage('message') }));
|
|
121
|
-
}
|
|
122
|
-
registerSlashCommandHandler(group, subGroup, command, options, execute) {
|
|
123
|
-
this.client.on('interactionCreate', (interaction) => __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
if (!interaction.isCommand())
|
|
125
|
-
return;
|
|
126
|
-
const rootCommand = interaction.commandName;
|
|
127
|
-
const groupCommand = interaction.options.getSubcommandGroup(false);
|
|
128
|
-
const subCommandGroup = interaction.options.getSubcommand(false);
|
|
129
|
-
if (CommandsService_1.getCommandKey(rootCommand, groupCommand, subCommandGroup) !==
|
|
130
|
-
CommandsService_1.getCommandKey(group, subGroup, command.name))
|
|
131
|
-
return;
|
|
132
|
-
const DTO = Object.entries(options).reduce((prev, [parameter, option]) => {
|
|
133
|
-
const resolve = interaction.options[option.methodName];
|
|
134
|
-
prev[parameter] = resolve.call(interaction.options, option.name, !!option.required);
|
|
135
|
-
return prev;
|
|
136
|
-
}, {});
|
|
137
|
-
return execute(interaction, DTO);
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
static getCommandKey(group, subGroup, command) {
|
|
141
|
-
let commandKey;
|
|
142
|
-
if (!!group) {
|
|
143
|
-
if (!!subGroup) {
|
|
144
|
-
commandKey = `${group}-${subGroup}-${command}`;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
commandKey = `${group}-null-${command}`;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
commandKey = `${command}-null-null`;
|
|
152
|
-
}
|
|
153
|
-
return commandKey;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
__decorate([
|
|
157
|
-
(0, decorators_1.On)('ready'),
|
|
158
|
-
__metadata("design:type", Function),
|
|
159
|
-
__metadata("design:paramtypes", []),
|
|
160
|
-
__metadata("design:returntype", Promise)
|
|
161
|
-
], CommandsService.prototype, "onReadyRegistration", null);
|
|
162
|
-
CommandsService = CommandsService_1 = __decorate([
|
|
163
|
-
(0, common_1.Injectable)(),
|
|
164
|
-
__param(3, (0, common_1.Inject)(necord_constants_1.NECORD_MODULE_OPTIONS)),
|
|
165
|
-
__metadata("design:paramtypes", [explorer_service_1.ExplorerService,
|
|
166
|
-
metadata_accessor_service_1.MetadataAccessorService,
|
|
167
|
-
discord_js_1.Client, Object])
|
|
168
|
-
], CommandsService);
|
|
169
|
-
exports.CommandsService = CommandsService;
|