@ezzi/base 1.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/README.md +29 -0
- package/dist/app.d.ts +47 -0
- package/dist/app.js +54 -0
- package/dist/bootstrap.d.ts +68 -0
- package/dist/bootstrap.js +35 -0
- package/dist/client.d.ts +12 -0
- package/dist/client.js +42 -0
- package/dist/creators/commands/command.d.ts +140 -0
- package/dist/creators/commands/command.js +63 -0
- package/dist/creators/commands/context.d.ts +33 -0
- package/dist/creators/commands/context.js +204 -0
- package/dist/creators/commands/manager.d.ts +50 -0
- package/dist/creators/commands/manager.js +560 -0
- package/dist/creators/events/event.d.ts +21 -0
- package/dist/creators/events/event.js +10 -0
- package/dist/creators/events/manager.d.ts +12 -0
- package/dist/creators/events/manager.js +71 -0
- package/dist/creators/index.d.ts +5 -0
- package/dist/creators/index.js +11 -0
- package/dist/creators/manager.d.ts +6 -0
- package/dist/creators/manager.js +12 -0
- package/dist/creators/responders/emit.d.ts +12 -0
- package/dist/creators/responders/emit.js +10 -0
- package/dist/creators/responders/manager.d.ts +14 -0
- package/dist/creators/responders/manager.js +61 -0
- package/dist/creators/responders/responder.d.ts +45 -0
- package/dist/creators/responders/responder.js +26 -0
- package/dist/creators/setup.d.ts +25 -0
- package/dist/creators/setup.js +86 -0
- package/dist/env.d.ts +25 -0
- package/dist/env.js +15 -0
- package/dist/error.d.ts +7 -0
- package/dist/error.js +78 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/modules.d.ts +9 -0
- package/dist/modules.js +18 -0
- package/dist/standard-schema.d.ts +59 -0
- package/dist/standard-schema.js +0 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/logger.d.ts +12 -0
- package/dist/tools/logger.js +23 -0
- package/dist/tools/parseCommand.d.ts +15 -0
- package/dist/tools/parseCommand.js +144 -0
- package/dist/utils/router.d.ts +9 -0
- package/dist/utils/router.js +24 -0
- package/dist/utils/types.d.ts +7 -0
- package/dist/utils/types.js +0 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.js +5 -0
- package/package.json +79 -0
- package/tsconfig/base.json +21 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// src/creators/commands/context.ts
|
|
2
|
+
import {
|
|
3
|
+
ApplicationCommandOptionType,
|
|
4
|
+
CommandInteraction,
|
|
5
|
+
GuildMember,
|
|
6
|
+
Message
|
|
7
|
+
} from "discord.js";
|
|
8
|
+
|
|
9
|
+
class CommandContext {
|
|
10
|
+
client;
|
|
11
|
+
source;
|
|
12
|
+
_botReply = null;
|
|
13
|
+
args;
|
|
14
|
+
_parsedOptions = new Map;
|
|
15
|
+
constructor(client, source, args = [], optionDefs = []) {
|
|
16
|
+
this.client = client;
|
|
17
|
+
this.source = source;
|
|
18
|
+
this.args = args;
|
|
19
|
+
if (source instanceof Message && args.length && optionDefs.length) {
|
|
20
|
+
this._parsePrefixOptions(args, optionDefs);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
_parsePrefixOptions(args, defs) {
|
|
24
|
+
defs.forEach((def, index) => {
|
|
25
|
+
const raw = args[index];
|
|
26
|
+
if (raw === undefined)
|
|
27
|
+
return;
|
|
28
|
+
let value = null;
|
|
29
|
+
switch (def.type) {
|
|
30
|
+
case ApplicationCommandOptionType.Integer:
|
|
31
|
+
value = parseInt(raw, 10);
|
|
32
|
+
if (isNaN(value))
|
|
33
|
+
value = null;
|
|
34
|
+
break;
|
|
35
|
+
case ApplicationCommandOptionType.Number:
|
|
36
|
+
value = parseFloat(raw);
|
|
37
|
+
if (isNaN(value))
|
|
38
|
+
value = null;
|
|
39
|
+
break;
|
|
40
|
+
case ApplicationCommandOptionType.Boolean:
|
|
41
|
+
value = raw === "true" || raw === "1" || raw === "yes";
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
value = raw;
|
|
45
|
+
}
|
|
46
|
+
this._parsedOptions.set(def.name, { name: def.name, value });
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
get user() {
|
|
50
|
+
return this.source instanceof Message ? this.source.author : this.source.user;
|
|
51
|
+
}
|
|
52
|
+
get member() {
|
|
53
|
+
return this.source.member instanceof GuildMember ? this.source.member : null;
|
|
54
|
+
}
|
|
55
|
+
get message() {
|
|
56
|
+
return this.source instanceof Message ? this.source : null;
|
|
57
|
+
}
|
|
58
|
+
get guild() {
|
|
59
|
+
return this.source.guild;
|
|
60
|
+
}
|
|
61
|
+
get guildId() {
|
|
62
|
+
return this.source.guildId;
|
|
63
|
+
}
|
|
64
|
+
get channel() {
|
|
65
|
+
return this.source.channel;
|
|
66
|
+
}
|
|
67
|
+
isInteraction() {
|
|
68
|
+
return this.source instanceof CommandInteraction;
|
|
69
|
+
}
|
|
70
|
+
isMessage() {
|
|
71
|
+
return this.source instanceof Message;
|
|
72
|
+
}
|
|
73
|
+
get options() {
|
|
74
|
+
return {
|
|
75
|
+
getString: (name, required) => {
|
|
76
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
77
|
+
return this.source.options.getString(name, required);
|
|
78
|
+
}
|
|
79
|
+
return this._parsedOptions.get(name)?.value;
|
|
80
|
+
},
|
|
81
|
+
getNumber: (name, required) => {
|
|
82
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
83
|
+
return this.source.options.getNumber(name, required);
|
|
84
|
+
}
|
|
85
|
+
return this._parsedOptions.get(name)?.value;
|
|
86
|
+
},
|
|
87
|
+
getInteger: (name, required) => {
|
|
88
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
89
|
+
return this.source.options.getInteger(name, required);
|
|
90
|
+
}
|
|
91
|
+
return this._parsedOptions.get(name)?.value;
|
|
92
|
+
},
|
|
93
|
+
getBoolean: (name, required) => {
|
|
94
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
95
|
+
return this.source.options.getBoolean(name, required);
|
|
96
|
+
}
|
|
97
|
+
return this._parsedOptions.get(name)?.value;
|
|
98
|
+
},
|
|
99
|
+
getUser: (name, required) => {
|
|
100
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
101
|
+
return this.source.options.getUser(name, required);
|
|
102
|
+
}
|
|
103
|
+
return this._parsedOptions.get(name)?.value;
|
|
104
|
+
},
|
|
105
|
+
getMember: (name) => {
|
|
106
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
107
|
+
return this.source.options.getMember(name);
|
|
108
|
+
}
|
|
109
|
+
return this._parsedOptions.get(name)?.value;
|
|
110
|
+
},
|
|
111
|
+
getRole: (name, required) => {
|
|
112
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
113
|
+
return this.source.options.getRole(name, required);
|
|
114
|
+
}
|
|
115
|
+
return this._parsedOptions.get(name)?.value;
|
|
116
|
+
},
|
|
117
|
+
getChannel: (name, required) => {
|
|
118
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
119
|
+
return this.source.options.getChannel(name, required);
|
|
120
|
+
}
|
|
121
|
+
return this._parsedOptions.get(name)?.value;
|
|
122
|
+
},
|
|
123
|
+
getMentionable: (name, required) => {
|
|
124
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
125
|
+
return this.source.options.getMentionable(name, required);
|
|
126
|
+
}
|
|
127
|
+
return this._parsedOptions.get(name)?.value;
|
|
128
|
+
},
|
|
129
|
+
getAttachment: (name, required) => {
|
|
130
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
131
|
+
return this.source.options.getAttachment(name, required);
|
|
132
|
+
}
|
|
133
|
+
return this._parsedOptions.get(name)?.value;
|
|
134
|
+
},
|
|
135
|
+
getSubcommand: (required) => {
|
|
136
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
137
|
+
try {
|
|
138
|
+
return this.source.options.getSubcommand(required);
|
|
139
|
+
} catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return this._parsedOptions.get("subcommand")?.value;
|
|
144
|
+
},
|
|
145
|
+
getSubcommandGroup: (required) => {
|
|
146
|
+
if (this.isInteraction() && this.source.isChatInputCommand()) {
|
|
147
|
+
try {
|
|
148
|
+
return this.source.options.getSubcommandGroup(required);
|
|
149
|
+
} catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return this._parsedOptions.get("subcommandGroup")?.value;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
getRaw(name) {
|
|
158
|
+
if (this.isInteraction())
|
|
159
|
+
return null;
|
|
160
|
+
return this._parsedOptions.get(name)?.value;
|
|
161
|
+
}
|
|
162
|
+
async deferReply(ephemeral = false) {
|
|
163
|
+
if (this.isInteraction() && !this.source.replied && !this.source.deferred) {
|
|
164
|
+
await this.source.deferReply(ephemeral ? { flags: ["Ephemeral"] } : {});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async reply(options) {
|
|
168
|
+
const payload = typeof options === "string" ? { content: options } : options;
|
|
169
|
+
if (this.source instanceof Message) {
|
|
170
|
+
const sent = await this.source.reply(payload);
|
|
171
|
+
this._botReply = sent;
|
|
172
|
+
return sent;
|
|
173
|
+
}
|
|
174
|
+
if (this.isInteraction()) {
|
|
175
|
+
if (this.source.replied || this.source.deferred) {
|
|
176
|
+
return this.source.followUp(payload);
|
|
177
|
+
}
|
|
178
|
+
return this.source.reply(payload);
|
|
179
|
+
}
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
async editReply(options) {
|
|
183
|
+
const payload = typeof options === "string" ? { content: options } : options;
|
|
184
|
+
if (this.isInteraction()) {
|
|
185
|
+
return this.source.editReply(payload);
|
|
186
|
+
}
|
|
187
|
+
if (this.source instanceof Message && this._botReply) {
|
|
188
|
+
return this._botReply.edit(payload);
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
async delete() {
|
|
193
|
+
if (this.isInteraction() && (this.source.replied || this.source.deferred)) {
|
|
194
|
+
await this.source.deleteReply();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (this.source instanceof Message) {
|
|
198
|
+
await this.source.delete();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
export {
|
|
203
|
+
CommandContext
|
|
204
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type ApplicationCommandData, ApplicationCommandType, AutocompleteInteraction, Client, CommandInteraction, Message, type PermissionResolvable } from "discord.js";
|
|
2
|
+
import { EzziApp } from "../../app.js";
|
|
3
|
+
import { type AutocompleteRun, type CommandModule, type GenericAppCommandData, type SlashCommandPrimitiveOptionData } from "./command.js";
|
|
4
|
+
type StoredAppCommandData = GenericAppCommandData & Required<Pick<GenericAppCommandData, "type">> & {
|
|
5
|
+
modules?: CommandModule[];
|
|
6
|
+
category?: string;
|
|
7
|
+
};
|
|
8
|
+
type BuildedCommandData = ApplicationCommandData & {
|
|
9
|
+
global?: boolean;
|
|
10
|
+
category?: string;
|
|
11
|
+
};
|
|
12
|
+
type Runner = Function | null | undefined;
|
|
13
|
+
export declare class CommandManager {
|
|
14
|
+
private app;
|
|
15
|
+
constructor(app: EzziApp);
|
|
16
|
+
private get config();
|
|
17
|
+
private readonly collection;
|
|
18
|
+
private runtimeCollection;
|
|
19
|
+
private readonly aliasCollection;
|
|
20
|
+
private readonly commandRunners;
|
|
21
|
+
private readonly autocompleteRunners;
|
|
22
|
+
private readonly optionDefs;
|
|
23
|
+
private readonly shortcuts;
|
|
24
|
+
private readonly botPermissionsMap;
|
|
25
|
+
readonly logs: string[];
|
|
26
|
+
private formatName;
|
|
27
|
+
clear(): void;
|
|
28
|
+
getAutocompleteHandler(...path: (string | null)[]): AutocompleteRun<string | number, any> | undefined;
|
|
29
|
+
getHandler(type: ApplicationCommandType, ...path: (string | null)[]): Runner[] | undefined;
|
|
30
|
+
getBotPermissions(path: string): PermissionResolvable[] | undefined;
|
|
31
|
+
resolveBotPermissions(commandName: string, subcommandGroup?: string | null, subcommand?: string | null): PermissionResolvable[] | undefined;
|
|
32
|
+
resolvePrefixCommand(commandName: string, args: string[], resolvedCommandData?: StoredAppCommandData): {
|
|
33
|
+
runners: Runner[];
|
|
34
|
+
optionDefs: SlashCommandPrimitiveOptionData<boolean>[];
|
|
35
|
+
botPermissions?: PermissionResolvable[];
|
|
36
|
+
} | undefined;
|
|
37
|
+
getTitle(data: GenericAppCommandData): [string, string];
|
|
38
|
+
private buildOptions;
|
|
39
|
+
private resolveModules;
|
|
40
|
+
set(data: GenericAppCommandData): StoredAppCommandData;
|
|
41
|
+
build(): BuildedCommandData[];
|
|
42
|
+
addLog(data: GenericAppCommandData): void;
|
|
43
|
+
addModule(commandName: string, module: CommandModule): void;
|
|
44
|
+
getPrefixCommandCount(): number;
|
|
45
|
+
onAutocomplete(interaction: AutocompleteInteraction): Promise<void>;
|
|
46
|
+
onPrefixCommand(message: Message): Promise<void>;
|
|
47
|
+
onCommand(interaction: CommandInteraction): Promise<void>;
|
|
48
|
+
register(client: Client<true>): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export {};
|