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
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ApplicationCommandData, ApplicationCommandOptionChoice, ApplicationCommandOptionData, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, AutocompleteInteraction, ChatInputApplicationCommandData, CommandInteractionOptionResolver, MessageApplicationCommandData, MessageComponentType, UserApplicationCommandData } from 'discord.js';
|
|
2
|
+
import { NecordEvents } from './necord-events.interface';
|
|
3
|
+
import { Module } from '@nestjs/core/injector/module';
|
|
4
|
+
import { Type } from '@nestjs/common';
|
|
5
|
+
export declare type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
6
|
+
export interface BaseMetadata {
|
|
7
|
+
metadata?: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
host?: Module;
|
|
10
|
+
class?: Type;
|
|
11
|
+
handler?: Function;
|
|
12
|
+
execute?: Function;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface ListenerMetadata<T extends keyof NecordEvents = keyof NecordEvents> extends BaseMetadata {
|
|
16
|
+
type: 'once' | 'on';
|
|
17
|
+
event: T;
|
|
18
|
+
}
|
|
19
|
+
export interface ComponentMetadata extends BaseMetadata {
|
|
20
|
+
type: Exclude<MessageComponentType, 'ACTION_ROW'>;
|
|
21
|
+
customId: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TextCommandMetadata extends BaseMetadata {
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare type ContextMenuMetadata = (UserApplicationCommandData | MessageApplicationCommandData) & BaseMetadata;
|
|
28
|
+
export declare type SlashCommandMetadata = ChatInputApplicationCommandData & BaseMetadata;
|
|
29
|
+
export declare type ApplicationCommandMetadata = ApplicationCommandData & BaseMetadata;
|
|
30
|
+
export declare type CommandOptionData = Exclude<ApplicationCommandOptionData, ApplicationCommandSubCommandData | ApplicationCommandSubGroupData>;
|
|
31
|
+
export declare type OptionMetadata<T extends CommandOptionData['type'] = any> = Extract<CommandOptionData & {
|
|
32
|
+
type: T;
|
|
33
|
+
}, ApplicationCommandOptionData> & {
|
|
34
|
+
methodName?: keyof CommandInteractionOptionResolver;
|
|
35
|
+
};
|
|
36
|
+
export interface TransformOptions {
|
|
37
|
+
transformOptions(interaction: AutocompleteInteraction, focused: ApplicationCommandOptionChoice): ApplicationCommandOptionChoice[] | Promise<ApplicationCommandOptionChoice[]>;
|
|
38
|
+
}
|
|
File without changes
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
2
|
import { ClientOptions as DiscordClientOptions } from 'discord.js';
|
|
3
3
|
export interface NecordModuleOptions extends DiscordClientOptions {
|
|
4
|
-
token
|
|
5
|
-
|
|
6
|
-
registerApplicationCommands?: boolean | string;
|
|
4
|
+
token: string;
|
|
5
|
+
prefix?: string | Function;
|
|
7
6
|
}
|
|
8
7
|
export interface NecordOptionsFactory {
|
|
9
8
|
createNecordOptions(): Promise<NecordModuleOptions> | NecordModuleOptions;
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
2
|
+
import { DiscoveryService, MetadataScanner, Reflector } from '@nestjs/core';
|
|
3
|
+
import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator';
|
|
4
|
+
import { ApplicationCommandMetadata, ComponentMetadata, ListenerMetadata, TextCommandMetadata } from './interfaces';
|
|
5
|
+
declare type OptionMetadata = string | {
|
|
6
|
+
key: string;
|
|
7
|
+
fn: (key: string, targets: any[]) => unknown;
|
|
8
|
+
};
|
|
9
|
+
export declare class NecordExplorer {
|
|
10
|
+
private readonly discoveryService;
|
|
11
|
+
private readonly externalContextCreator;
|
|
12
|
+
private readonly metadataScanner;
|
|
13
|
+
private readonly reflector;
|
|
14
|
+
private readonly necordParamsFactory;
|
|
15
|
+
private readonly wrappers;
|
|
16
|
+
constructor(discoveryService: DiscoveryService, externalContextCreator: ExternalContextCreator, metadataScanner: MetadataScanner, reflector: Reflector);
|
|
17
|
+
explore(): {
|
|
18
|
+
listeners: ListenerMetadata<keyof import("./interfaces").NecordEvents>[];
|
|
19
|
+
components: ComponentMetadata[];
|
|
20
|
+
appCommands: ApplicationCommandMetadata[];
|
|
21
|
+
textCommands: TextCommandMetadata[];
|
|
22
|
+
};
|
|
23
|
+
private flatMap;
|
|
24
|
+
filterProvider<T = any>(wrapper: InstanceWrapper, metadataKey: string): T | undefined;
|
|
25
|
+
filterProperties({ instance, host }: InstanceWrapper, metadataKey: string, optionalMetadataKeys?: OptionMetadata[]): any[];
|
|
26
|
+
private extractOptionalMetadata;
|
|
27
|
+
private createContextCallback;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NecordExplorer = void 0;
|
|
13
|
+
const discord_js_1 = require("discord.js");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const core_1 = require("@nestjs/core");
|
|
16
|
+
const external_context_creator_1 = require("@nestjs/core/helpers/external-context-creator");
|
|
17
|
+
const context_1 = require("./context");
|
|
18
|
+
const constants_1 = require("@nestjs/core/injector/constants");
|
|
19
|
+
const necord_constants_1 = require("./necord.constants");
|
|
20
|
+
let NecordExplorer = class NecordExplorer {
|
|
21
|
+
constructor(discoveryService, externalContextCreator, metadataScanner, reflector) {
|
|
22
|
+
this.discoveryService = discoveryService;
|
|
23
|
+
this.externalContextCreator = externalContextCreator;
|
|
24
|
+
this.metadataScanner = metadataScanner;
|
|
25
|
+
this.reflector = reflector;
|
|
26
|
+
this.necordParamsFactory = new context_1.NecordParamsFactory();
|
|
27
|
+
this.wrappers = this.discoveryService.getProviders().filter(wrapper => {
|
|
28
|
+
const { instance } = wrapper;
|
|
29
|
+
const prototype = instance ? Object.getPrototypeOf(instance) : null;
|
|
30
|
+
return instance && prototype && wrapper.isDependencyTreeStatic();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
explore() {
|
|
34
|
+
const listeners = this.flatMap(wrapper => this.filterProperties(wrapper, necord_constants_1.LISTENERS_METADATA));
|
|
35
|
+
const components = this.flatMap(wrapper => this.filterProperties(wrapper, necord_constants_1.MESSAGE_COMPONENT_METADATA));
|
|
36
|
+
const textCommands = this.flatMap(wrapper => this.filterProperties(wrapper, necord_constants_1.TEXT_COMMAND_METADATA));
|
|
37
|
+
const appCommands = this.flatMap(wrapper => {
|
|
38
|
+
var _a;
|
|
39
|
+
const commandGroup = this.filterProvider(wrapper, necord_constants_1.GROUP_METADATA);
|
|
40
|
+
const subGroups = new discord_js_1.Collection();
|
|
41
|
+
const subCommands = [];
|
|
42
|
+
const commands = [];
|
|
43
|
+
const metadataKey = necord_constants_1.APPLICATION_COMMAND_METADATA;
|
|
44
|
+
const optionalKeys = [
|
|
45
|
+
necord_constants_1.GROUP_METADATA,
|
|
46
|
+
necord_constants_1.OPTIONS_METADATA,
|
|
47
|
+
necord_constants_1.AUTOCOMPLETE_METADATA,
|
|
48
|
+
{
|
|
49
|
+
key: necord_constants_1.GUILDS_METADATA,
|
|
50
|
+
fn: (key, targets) => this.reflector.getAllAndOverride(key, targets)
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
for (const command of this.filterProperties(wrapper, metadataKey, optionalKeys)) {
|
|
54
|
+
command.options = Object.values((_a = command.metadata[necord_constants_1.OPTIONS_METADATA]) !== null && _a !== void 0 ? _a : []);
|
|
55
|
+
if (!commandGroup || command.type !== 1) {
|
|
56
|
+
commands.push(command);
|
|
57
|
+
}
|
|
58
|
+
const subGroup = command.metadata[necord_constants_1.GROUP_METADATA];
|
|
59
|
+
subGroup
|
|
60
|
+
? subGroups.ensure(subGroup.name, () => subGroup).options.push(command)
|
|
61
|
+
: subCommands.push(command);
|
|
62
|
+
}
|
|
63
|
+
if (commandGroup) {
|
|
64
|
+
commandGroup.metadata = this.extractOptionalMetadata([necord_constants_1.GUILDS_METADATA], wrapper.instance);
|
|
65
|
+
commandGroup.options = [...subGroups.values(), ...subCommands];
|
|
66
|
+
}
|
|
67
|
+
return commands.concat(commandGroup);
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
listeners,
|
|
71
|
+
components,
|
|
72
|
+
appCommands,
|
|
73
|
+
textCommands
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
flatMap(callback) {
|
|
77
|
+
return this.wrappers.flatMap(callback).filter(Boolean);
|
|
78
|
+
}
|
|
79
|
+
filterProvider(wrapper, metadataKey) {
|
|
80
|
+
return this.reflector.get(metadataKey, wrapper.instance.constructor);
|
|
81
|
+
}
|
|
82
|
+
filterProperties({ instance, host }, metadataKey, optionalMetadataKeys = []) {
|
|
83
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
84
|
+
return this.metadataScanner.scanFromPrototype(instance, prototype, name => {
|
|
85
|
+
const item = this.reflector.get(metadataKey, instance[name]);
|
|
86
|
+
if (!item)
|
|
87
|
+
return;
|
|
88
|
+
return Object.assign(item, {
|
|
89
|
+
metadata: Object.assign({ host, class: instance.constructor, handler: prototype[name], execute: this.createContextCallback(instance, prototype, name) }, this.extractOptionalMetadata(optionalMetadataKeys, instance, name))
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
extractOptionalMetadata(keys, instance, propertyKey) {
|
|
94
|
+
const defaultTarget = propertyKey ? instance[propertyKey] : instance.constructor;
|
|
95
|
+
const defaultTargets = [instance[propertyKey], instance.constructor].filter(Boolean);
|
|
96
|
+
return keys.reduce((acc, option) => {
|
|
97
|
+
const isOptionString = typeof option === 'string';
|
|
98
|
+
const key = isOptionString ? option : option.key;
|
|
99
|
+
const value = isOptionString
|
|
100
|
+
? this.reflector.get(key, defaultTarget)
|
|
101
|
+
: option.fn(key, defaultTargets);
|
|
102
|
+
return Object.assign(Object.assign({}, acc), { [key]: value });
|
|
103
|
+
}, {});
|
|
104
|
+
}
|
|
105
|
+
createContextCallback(instance, prototype, methodName) {
|
|
106
|
+
return this.externalContextCreator.create(instance, prototype[methodName], methodName, necord_constants_1.PARAM_ARGS_METADATA, this.necordParamsFactory, constants_1.STATIC_CONTEXT, undefined, { guards: true, filters: true, interceptors: true }, 'necord');
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
NecordExplorer = __decorate([
|
|
110
|
+
(0, common_1.Injectable)(),
|
|
111
|
+
__metadata("design:paramtypes", [core_1.DiscoveryService,
|
|
112
|
+
external_context_creator_1.ExternalContextCreator,
|
|
113
|
+
core_1.MetadataScanner,
|
|
114
|
+
core_1.Reflector])
|
|
115
|
+
], NecordExplorer);
|
|
116
|
+
exports.NecordExplorer = NecordExplorer;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NecordRegistry } from './necord-registry';
|
|
2
|
+
export declare class NecordInteractionUpdate {
|
|
3
|
+
private readonly registry;
|
|
4
|
+
private readonly logger;
|
|
5
|
+
constructor(registry: NecordRegistry);
|
|
6
|
+
private onReady;
|
|
7
|
+
private onInteractionCreate;
|
|
8
|
+
private transformOptions;
|
|
9
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
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 NecordInteractionUpdate_1;
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.NecordInteractionUpdate = void 0;
|
|
26
|
+
const common_1 = require("@nestjs/common");
|
|
27
|
+
const decorators_1 = require("./decorators");
|
|
28
|
+
const necord_registry_1 = require("./necord-registry");
|
|
29
|
+
const necord_constants_1 = require("./necord.constants");
|
|
30
|
+
const core_1 = require("@nestjs/core");
|
|
31
|
+
const constants_1 = require("@nestjs/core/injector/constants");
|
|
32
|
+
let NecordInteractionUpdate = NecordInteractionUpdate_1 = class NecordInteractionUpdate {
|
|
33
|
+
constructor(registry) {
|
|
34
|
+
this.registry = registry;
|
|
35
|
+
this.logger = new common_1.Logger(NecordInteractionUpdate_1.name);
|
|
36
|
+
}
|
|
37
|
+
onReady([client]) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (client.application.partial) {
|
|
41
|
+
yield client.application.fetch();
|
|
42
|
+
}
|
|
43
|
+
const commands = new Map([[undefined, []]]);
|
|
44
|
+
for (const command of this.registry.getApplicationCommands()) {
|
|
45
|
+
const guilds = (_a = command.metadata[necord_constants_1.GUILDS_METADATA]) !== null && _a !== void 0 ? _a : [undefined];
|
|
46
|
+
for (const guild of guilds) {
|
|
47
|
+
const cmds = (_b = commands.get(guild)) !== null && _b !== void 0 ? _b : [];
|
|
48
|
+
commands.set(guild, cmds.concat(command));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.logger.log(`Started refreshing application commands.`);
|
|
52
|
+
yield Promise.all([...commands.entries()].map(([key, cmds]) => client.application.commands.set(cmds, key)));
|
|
53
|
+
this.logger.log(`Successfully reloaded application commands.`);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
onInteractionCreate([interaction]) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
if (interaction.isMessageComponent()) {
|
|
60
|
+
return (_a = this.registry
|
|
61
|
+
.getMessageComponent(interaction.componentType, interaction.customId)) === null || _a === void 0 ? void 0 : _a.metadata.execute([interaction], interaction.isSelectMenu() ? interaction.values : undefined);
|
|
62
|
+
}
|
|
63
|
+
if (interaction.isContextMenu()) {
|
|
64
|
+
const options = interaction.isUserContextMenu()
|
|
65
|
+
? {
|
|
66
|
+
user: interaction.options.getUser('user', false),
|
|
67
|
+
member: interaction.options.getMember('user', false)
|
|
68
|
+
}
|
|
69
|
+
: { message: interaction.options.getMessage('message', false) };
|
|
70
|
+
return (_b = this.registry
|
|
71
|
+
.getContextMenu(interaction.targetType, interaction.commandName)) === null || _b === void 0 ? void 0 : _b.metadata.execute([interaction], options);
|
|
72
|
+
}
|
|
73
|
+
if (interaction.isCommand() || interaction.isAutocomplete()) {
|
|
74
|
+
const rootCommand = interaction.commandName;
|
|
75
|
+
const groupCommand = interaction.options.getSubcommandGroup(false);
|
|
76
|
+
const subCommand = interaction.options.getSubcommand(false);
|
|
77
|
+
const command = this.registry.getSlashCommand(...[rootCommand, groupCommand, subCommand].filter(Boolean));
|
|
78
|
+
if (!command)
|
|
79
|
+
return;
|
|
80
|
+
if (interaction.isCommand()) {
|
|
81
|
+
return command === null || command === void 0 ? void 0 : command.metadata.execute([interaction], this.transformOptions(command, interaction));
|
|
82
|
+
}
|
|
83
|
+
const module = command.metadata.host;
|
|
84
|
+
const autocompleteMetadata = command.metadata[necord_constants_1.AUTOCOMPLETE_METADATA];
|
|
85
|
+
const { instance: moduleRef } = module.getProviderByKey(core_1.ModuleRef);
|
|
86
|
+
if (!module || !autocompleteMetadata || !moduleRef)
|
|
87
|
+
return;
|
|
88
|
+
const autocomplete = yield moduleRef
|
|
89
|
+
.resolve(autocompleteMetadata, constants_1.STATIC_CONTEXT, { strict: true })
|
|
90
|
+
.catch(() => moduleRef.create(autocompleteMetadata));
|
|
91
|
+
const options = yield (autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.transformOptions(interaction, interaction.options.getFocused(true)));
|
|
92
|
+
return interaction.respond(options !== null && options !== void 0 ? options : []);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
transformOptions(command, interaction) {
|
|
97
|
+
var _a;
|
|
98
|
+
const rawOptions = (_a = command.metadata[necord_constants_1.OPTIONS_METADATA]) !== null && _a !== void 0 ? _a : {};
|
|
99
|
+
return Object.entries(rawOptions).reduce((acc, [parameter, option]) => {
|
|
100
|
+
acc[parameter] = interaction.options[option.methodName].call(interaction.options, option.name, !!option.required);
|
|
101
|
+
return acc;
|
|
102
|
+
}, {});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, decorators_1.Once)('ready'),
|
|
107
|
+
__param(0, (0, decorators_1.Context)()),
|
|
108
|
+
__metadata("design:type", Function),
|
|
109
|
+
__metadata("design:paramtypes", [Object]),
|
|
110
|
+
__metadata("design:returntype", Promise)
|
|
111
|
+
], NecordInteractionUpdate.prototype, "onReady", null);
|
|
112
|
+
__decorate([
|
|
113
|
+
(0, decorators_1.On)('interactionCreate'),
|
|
114
|
+
__param(0, (0, decorators_1.Context)()),
|
|
115
|
+
__metadata("design:type", Function),
|
|
116
|
+
__metadata("design:paramtypes", [Object]),
|
|
117
|
+
__metadata("design:returntype", Promise)
|
|
118
|
+
], NecordInteractionUpdate.prototype, "onInteractionCreate", null);
|
|
119
|
+
NecordInteractionUpdate = NecordInteractionUpdate_1 = __decorate([
|
|
120
|
+
(0, common_1.Injectable)(),
|
|
121
|
+
__metadata("design:paramtypes", [necord_registry_1.NecordRegistry])
|
|
122
|
+
], NecordInteractionUpdate);
|
|
123
|
+
exports.NecordInteractionUpdate = NecordInteractionUpdate;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Client } from 'discord.js';
|
|
2
|
+
import { ApplicationCommandMetadata, ComponentMetadata, ContextMenuMetadata, ListenerMetadata, SlashCommandMetadata, TextCommandMetadata } from './interfaces';
|
|
3
|
+
export declare class NecordRegistry {
|
|
4
|
+
private readonly client;
|
|
5
|
+
private static readonly GENERATE_KEY;
|
|
6
|
+
private readonly textCommands;
|
|
7
|
+
private readonly messageComponents;
|
|
8
|
+
private readonly applicationCommands;
|
|
9
|
+
private readonly applicationCommandsData;
|
|
10
|
+
constructor(client: Client);
|
|
11
|
+
registerListeners(listeners: ListenerMetadata[]): void;
|
|
12
|
+
addTextCommands(textCommands: TextCommandMetadata[]): void;
|
|
13
|
+
getTextCommands(): TextCommandMetadata[];
|
|
14
|
+
getTextCommand(name: string): TextCommandMetadata;
|
|
15
|
+
addApplicationCommands(appCommands: ApplicationCommandMetadata[]): void;
|
|
16
|
+
getApplicationCommands(): ApplicationCommandMetadata[];
|
|
17
|
+
getContextMenu(type: 'USER' | 'MESSAGE', name: string): ContextMenuMetadata;
|
|
18
|
+
getSlashCommand(...args: string[]): SlashCommandMetadata;
|
|
19
|
+
addMessageComponents(messageComponents: ComponentMetadata[]): void;
|
|
20
|
+
getMessageComponents(): ComponentMetadata[];
|
|
21
|
+
getMessageComponent(componentType: ComponentMetadata['type'], customId: string): ComponentMetadata;
|
|
22
|
+
getButton(customId: string): ComponentMetadata;
|
|
23
|
+
getSelectMenu(customId: string): ComponentMetadata;
|
|
24
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 NecordRegistry_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.NecordRegistry = void 0;
|
|
14
|
+
const discord_js_1 = require("discord.js");
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
let NecordRegistry = NecordRegistry_1 = class NecordRegistry {
|
|
17
|
+
constructor(client) {
|
|
18
|
+
this.client = client;
|
|
19
|
+
this.textCommands = new discord_js_1.Collection();
|
|
20
|
+
this.messageComponents = new discord_js_1.Collection();
|
|
21
|
+
this.applicationCommands = new discord_js_1.Collection();
|
|
22
|
+
this.applicationCommandsData = [];
|
|
23
|
+
}
|
|
24
|
+
registerListeners(listeners) {
|
|
25
|
+
listeners.forEach(listener => {
|
|
26
|
+
this.client[listener.type](listener.event, (...args) => listener.metadata.execute(args));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
addTextCommands(textCommands) {
|
|
30
|
+
textCommands.forEach(command => this.textCommands.set(command.name, command));
|
|
31
|
+
}
|
|
32
|
+
getTextCommands() {
|
|
33
|
+
return [...this.textCommands.values()];
|
|
34
|
+
}
|
|
35
|
+
getTextCommand(name) {
|
|
36
|
+
return this.textCommands.get(name);
|
|
37
|
+
}
|
|
38
|
+
addApplicationCommands(appCommands) {
|
|
39
|
+
const recursive = (command, tree) => {
|
|
40
|
+
const options = 'options' in command ? command.options : [];
|
|
41
|
+
options.every(option => option.type !== 1 && option.type !== 2)
|
|
42
|
+
? this.applicationCommands.set(NecordRegistry_1.GENERATE_KEY(...tree), command)
|
|
43
|
+
: options.map((command) => recursive(command, tree.concat(command.name)));
|
|
44
|
+
};
|
|
45
|
+
appCommands.forEach(command => recursive(command, [command.type, command.name]));
|
|
46
|
+
this.applicationCommandsData.push(...appCommands);
|
|
47
|
+
}
|
|
48
|
+
getApplicationCommands() {
|
|
49
|
+
return this.applicationCommandsData;
|
|
50
|
+
}
|
|
51
|
+
getContextMenu(type, name) {
|
|
52
|
+
return this.applicationCommands.get(NecordRegistry_1.GENERATE_KEY(type, name));
|
|
53
|
+
}
|
|
54
|
+
getSlashCommand(...args) {
|
|
55
|
+
return this.applicationCommands.get(NecordRegistry_1.GENERATE_KEY(1, ...args));
|
|
56
|
+
}
|
|
57
|
+
addMessageComponents(messageComponents) {
|
|
58
|
+
messageComponents.forEach(component => this.messageComponents.set(NecordRegistry_1.GENERATE_KEY(component.type, component.customId), component));
|
|
59
|
+
}
|
|
60
|
+
getMessageComponents() {
|
|
61
|
+
return [...this.messageComponents.values()];
|
|
62
|
+
}
|
|
63
|
+
getMessageComponent(componentType, customId) {
|
|
64
|
+
return this.messageComponents.get(NecordRegistry_1.GENERATE_KEY(componentType, customId));
|
|
65
|
+
}
|
|
66
|
+
getButton(customId) {
|
|
67
|
+
return this.getMessageComponent('BUTTON', customId);
|
|
68
|
+
}
|
|
69
|
+
getSelectMenu(customId) {
|
|
70
|
+
return this.getMessageComponent('SELECT_MENU', customId);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
NecordRegistry.GENERATE_KEY = (...args) => args.map(String).join(':');
|
|
74
|
+
NecordRegistry = NecordRegistry_1 = __decorate([
|
|
75
|
+
(0, common_1.Injectable)(),
|
|
76
|
+
__metadata("design:paramtypes", [discord_js_1.Client])
|
|
77
|
+
], NecordRegistry);
|
|
78
|
+
exports.NecordRegistry = NecordRegistry;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export declare const NECORD_MODULE_OPTIONS = "necord:module_options";
|
|
2
2
|
export declare const PARAM_ARGS_METADATA = "__routeArguments__";
|
|
3
|
+
export declare const TEXT_COMMAND_METADATA = "necord:text_command_meta";
|
|
3
4
|
export declare const APPLICATION_COMMAND_METADATA = "necord:application_command_meta";
|
|
4
5
|
export declare const MESSAGE_COMPONENT_METADATA = "necord:message_component_meta";
|
|
5
6
|
export declare const LISTENERS_METADATA = "necord:listeners_meta";
|
|
7
|
+
export declare const AUTOCOMPLETE_METADATA = "necord:autocomplete_metadata";
|
|
6
8
|
export declare const GROUP_METADATA = "necord:group_meta";
|
|
7
|
-
export declare const SUBGROUP_METADATA = "necord:subgroup_meta";
|
|
8
9
|
export declare const OPTIONS_METADATA = "necord:options_meta";
|
|
10
|
+
export declare const GUILDS_METADATA = "necord:guilds_meta";
|
|
11
|
+
export declare const PERMISSIONS_METADATA = "necord:permissions_meta";
|
package/dist/necord.constants.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PERMISSIONS_METADATA = exports.GUILDS_METADATA = exports.OPTIONS_METADATA = exports.GROUP_METADATA = exports.AUTOCOMPLETE_METADATA = exports.LISTENERS_METADATA = exports.MESSAGE_COMPONENT_METADATA = exports.APPLICATION_COMMAND_METADATA = exports.TEXT_COMMAND_METADATA = exports.PARAM_ARGS_METADATA = exports.NECORD_MODULE_OPTIONS = void 0;
|
|
4
4
|
const constants_1 = require("@nestjs/common/constants");
|
|
5
5
|
exports.NECORD_MODULE_OPTIONS = 'necord:module_options';
|
|
6
6
|
exports.PARAM_ARGS_METADATA = constants_1.ROUTE_ARGS_METADATA;
|
|
7
|
+
exports.TEXT_COMMAND_METADATA = 'necord:text_command_meta';
|
|
7
8
|
exports.APPLICATION_COMMAND_METADATA = 'necord:application_command_meta';
|
|
8
9
|
exports.MESSAGE_COMPONENT_METADATA = 'necord:message_component_meta';
|
|
9
10
|
exports.LISTENERS_METADATA = 'necord:listeners_meta';
|
|
11
|
+
exports.AUTOCOMPLETE_METADATA = 'necord:autocomplete_metadata';
|
|
10
12
|
exports.GROUP_METADATA = 'necord:group_meta';
|
|
11
|
-
exports.SUBGROUP_METADATA = 'necord:subgroup_meta';
|
|
12
13
|
exports.OPTIONS_METADATA = 'necord:options_meta';
|
|
14
|
+
exports.GUILDS_METADATA = 'necord:guilds_meta';
|
|
15
|
+
exports.PERMISSIONS_METADATA = 'necord:permissions_meta';
|
package/dist/necord.module.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { DynamicModule, OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { Client } from 'discord.js';
|
|
3
3
|
import { NecordModuleAsyncOptions, NecordModuleOptions } from './interfaces';
|
|
4
|
+
import { NecordRegistry } from './necord-registry';
|
|
5
|
+
import { NecordExplorer } from './necord-explorer';
|
|
4
6
|
export declare class NecordModule implements OnApplicationBootstrap, OnApplicationShutdown {
|
|
5
7
|
private readonly options;
|
|
6
8
|
private readonly client;
|
|
7
|
-
|
|
9
|
+
private readonly explorer;
|
|
10
|
+
private readonly registry;
|
|
11
|
+
constructor(options: NecordModuleOptions, client: Client, explorer: NecordExplorer, registry: NecordRegistry);
|
|
8
12
|
onApplicationBootstrap(): Promise<string>;
|
|
9
13
|
onApplicationShutdown(signal?: string): void;
|
|
10
14
|
static forRoot(options: NecordModuleOptions): DynamicModule;
|
package/dist/necord.module.js
CHANGED
|
@@ -27,15 +27,26 @@ const common_1 = require("@nestjs/common");
|
|
|
27
27
|
const discord_js_1 = require("discord.js");
|
|
28
28
|
const core_1 = require("@nestjs/core");
|
|
29
29
|
const necord_constants_1 = require("./necord.constants");
|
|
30
|
-
const
|
|
30
|
+
const necord_registry_1 = require("./necord-registry");
|
|
31
|
+
const necord_explorer_1 = require("./necord-explorer");
|
|
32
|
+
const necord_interaction_update_1 = require("./necord-interaction.update");
|
|
31
33
|
const necord_update_1 = require("./necord.update");
|
|
32
34
|
let NecordModule = NecordModule_1 = class NecordModule {
|
|
33
|
-
constructor(options, client) {
|
|
35
|
+
constructor(options, client, explorer, registry) {
|
|
34
36
|
this.options = options;
|
|
35
37
|
this.client = client;
|
|
38
|
+
this.explorer = explorer;
|
|
39
|
+
this.registry = registry;
|
|
36
40
|
}
|
|
37
41
|
onApplicationBootstrap() {
|
|
38
|
-
return this
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const { listeners, components, appCommands, textCommands } = this.explorer.explore();
|
|
44
|
+
this.registry.registerListeners(listeners);
|
|
45
|
+
this.registry.addTextCommands(textCommands);
|
|
46
|
+
this.registry.addMessageComponents(components);
|
|
47
|
+
this.registry.addApplicationCommands(appCommands);
|
|
48
|
+
return this.client.login(this.options.token);
|
|
49
|
+
});
|
|
39
50
|
}
|
|
40
51
|
onApplicationShutdown(signal) {
|
|
41
52
|
return this.client.destroy();
|
|
@@ -101,16 +112,12 @@ NecordModule = NecordModule_1 = __decorate([
|
|
|
101
112
|
(0, common_1.Global)(),
|
|
102
113
|
(0, common_1.Module)({
|
|
103
114
|
imports: [core_1.DiscoveryModule],
|
|
104
|
-
providers: [
|
|
105
|
-
|
|
106
|
-
services_1.ComponentsService,
|
|
107
|
-
services_1.ListenersService,
|
|
108
|
-
services_1.ExplorerService,
|
|
109
|
-
services_1.MetadataAccessorService,
|
|
110
|
-
necord_update_1.NecordUpdate
|
|
111
|
-
]
|
|
115
|
+
providers: [necord_explorer_1.NecordExplorer, necord_update_1.NecordUpdate, necord_interaction_update_1.NecordInteractionUpdate, necord_registry_1.NecordRegistry],
|
|
116
|
+
exports: [necord_registry_1.NecordRegistry]
|
|
112
117
|
}),
|
|
113
118
|
__param(0, (0, common_1.Inject)(necord_constants_1.NECORD_MODULE_OPTIONS)),
|
|
114
|
-
__metadata("design:paramtypes", [Object, discord_js_1.Client
|
|
119
|
+
__metadata("design:paramtypes", [Object, discord_js_1.Client,
|
|
120
|
+
necord_explorer_1.NecordExplorer,
|
|
121
|
+
necord_registry_1.NecordRegistry])
|
|
115
122
|
], NecordModule);
|
|
116
123
|
exports.NecordModule = NecordModule;
|
package/dist/necord.update.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
import { Client } from 'discord.js';
|
|
2
|
+
import { NecordModuleOptions } from './interfaces';
|
|
3
|
+
import { NecordRegistry } from './necord-registry';
|
|
1
4
|
export declare class NecordUpdate {
|
|
2
|
-
private readonly
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
private readonly options;
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly registry;
|
|
8
|
+
private readonly prefix;
|
|
9
|
+
constructor(options: NecordModuleOptions, client: Client, registry: NecordRegistry);
|
|
10
|
+
private onMessageCreate;
|
|
11
|
+
private emit;
|
|
12
|
+
private onChannelUpdate;
|
|
13
|
+
private onGuildMemberUpdate;
|
|
14
|
+
private onGuildUpdate;
|
|
15
|
+
private onMessageUpdate;
|
|
16
|
+
private onPresenceUpdate;
|
|
17
|
+
private onRoleUpdate;
|
|
18
|
+
private onThreadUpdate;
|
|
19
|
+
private onUserUpdate;
|
|
20
|
+
private onVoiceStateUpdate;
|
|
7
21
|
}
|