zumito-framework 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/dist/ZumitoFramework.d.ts +47 -0
- package/dist/ZumitoFramework.js +278 -0
- package/dist/baseModule/events/discord/interactionCreate.d.ts +6 -0
- package/dist/baseModule/events/discord/interactionCreate.js +40 -0
- package/dist/definitions/ApiResponse.d.ts +4 -0
- package/dist/definitions/ApiResponse.js +20 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +11 -0
- package/dist/types/CommandArgDefinition.d.ts +4 -0
- package/dist/types/CommandArgDefinition.js +0 -0
- package/dist/types/CommandArguments.d.ts +8 -0
- package/dist/types/CommandArguments.js +19 -0
- package/dist/types/CommandParameters.d.ts +15 -0
- package/dist/types/CommandParameters.js +2 -0
- package/dist/types/CommandType.d.ts +6 -0
- package/dist/types/CommandType.js +9 -0
- package/dist/types/Commands.d.ts +23 -0
- package/dist/types/Commands.js +30 -0
- package/dist/types/EventParameters.d.ts +8 -0
- package/dist/types/EventParameters.js +2 -0
- package/dist/types/FrameworkEvent.d.ts +4 -0
- package/dist/types/FrameworkEvent.js +7 -0
- package/dist/types/FrameworkSettings.d.ts +11 -0
- package/dist/types/FrameworkSettings.js +2 -0
- package/dist/types/Module.d.ts +12 -0
- package/dist/types/Module.js +42 -0
- package/dist/types/SelectMenuParameters.d.ts +8 -0
- package/dist/types/SelectMenuParameters.js +2 -0
- package/package.json +32 -0
- package/templateGenerator.js +20 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GuildMember, TextChannel } from "discord.js";
|
|
2
|
+
import { Command } from "./types/Commands";
|
|
3
|
+
import { FrameworkSettings } from "./types/FrameworkSettings";
|
|
4
|
+
import { Module } from "./types/Module";
|
|
5
|
+
import { FrameworkEvent } from "./types/FrameworkEvent";
|
|
6
|
+
/**
|
|
7
|
+
* @class ZumitoFramework
|
|
8
|
+
* @classdesc The main class of the framework.
|
|
9
|
+
*
|
|
10
|
+
* @property {FrameworkSettings} settings - The settings of the framework.
|
|
11
|
+
* @property {Client} client - The client client instance.
|
|
12
|
+
* @property {Collection<string, Module>} modules - The modules loaded in the framework.
|
|
13
|
+
* @property {Collection<string, Command>} commands - The commands loaded in the framework.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ZumitoFramework {
|
|
16
|
+
client: any;
|
|
17
|
+
settings: FrameworkSettings;
|
|
18
|
+
modules: Map<String, Module>;
|
|
19
|
+
commands: Map<String, Command>;
|
|
20
|
+
events: Map<String, FrameworkEvent>;
|
|
21
|
+
routes: any;
|
|
22
|
+
models: any;
|
|
23
|
+
database: any;
|
|
24
|
+
app: any;
|
|
25
|
+
/**
|
|
26
|
+
* @constructor
|
|
27
|
+
* @description Creates a new instance of the framework.
|
|
28
|
+
* @param {FrameworkSettings} settings - The settings of the framework.
|
|
29
|
+
* @example new ZumitoFramework({
|
|
30
|
+
* prefix: '!',
|
|
31
|
+
* discordClientOptions: {
|
|
32
|
+
* token: 'token',
|
|
33
|
+
* clientId: 'clientId',
|
|
34
|
+
* intents: 0
|
|
35
|
+
* }
|
|
36
|
+
* });
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
constructor(settings: FrameworkSettings);
|
|
40
|
+
startApiServer(): void;
|
|
41
|
+
private registerModules;
|
|
42
|
+
private registerModule;
|
|
43
|
+
private initializeDiscordClient;
|
|
44
|
+
private commandHandler;
|
|
45
|
+
static splitCommandLine(commandLine: any): any;
|
|
46
|
+
memberHasPermission(member: GuildMember, channel: TextChannel, permission: bigint): Promise<boolean>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZumitoFramework = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
const Module_1 = require("./types/Module");
|
|
6
|
+
const express_1 = require("express");
|
|
7
|
+
const ApiResponse_1 = require("./definitions/ApiResponse");
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { Collection, Client } = require('discord.js');
|
|
11
|
+
require('better-logging')(console);
|
|
12
|
+
const { REST } = require('@discordjs/rest');
|
|
13
|
+
const { Routes } = require('discord-api-types/v9');
|
|
14
|
+
var mongoose = require("mongoose");
|
|
15
|
+
var cookieParser = require("cookie-parser");
|
|
16
|
+
var cors = require("cors");
|
|
17
|
+
var http = require('http');
|
|
18
|
+
/**
|
|
19
|
+
* @class ZumitoFramework
|
|
20
|
+
* @classdesc The main class of the framework.
|
|
21
|
+
*
|
|
22
|
+
* @property {FrameworkSettings} settings - The settings of the framework.
|
|
23
|
+
* @property {Client} client - The client client instance.
|
|
24
|
+
* @property {Collection<string, Module>} modules - The modules loaded in the framework.
|
|
25
|
+
* @property {Collection<string, Command>} commands - The commands loaded in the framework.
|
|
26
|
+
*/
|
|
27
|
+
class ZumitoFramework {
|
|
28
|
+
client;
|
|
29
|
+
settings;
|
|
30
|
+
modules;
|
|
31
|
+
commands;
|
|
32
|
+
events = new Map();
|
|
33
|
+
routes;
|
|
34
|
+
models;
|
|
35
|
+
database;
|
|
36
|
+
app;
|
|
37
|
+
/**
|
|
38
|
+
* @constructor
|
|
39
|
+
* @description Creates a new instance of the framework.
|
|
40
|
+
* @param {FrameworkSettings} settings - The settings of the framework.
|
|
41
|
+
* @example new ZumitoFramework({
|
|
42
|
+
* prefix: '!',
|
|
43
|
+
* discordClientOptions: {
|
|
44
|
+
* token: 'token',
|
|
45
|
+
* clientId: 'clientId',
|
|
46
|
+
* intents: 0
|
|
47
|
+
* }
|
|
48
|
+
* });
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
constructor(settings) {
|
|
52
|
+
this.settings = settings;
|
|
53
|
+
this.modules = new Map();
|
|
54
|
+
this.commands = new Map();
|
|
55
|
+
mongoose.connect(settings.mongoQueryString, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
|
|
56
|
+
console.log('[✅] DB connection successful');
|
|
57
|
+
}).catch(err => {
|
|
58
|
+
console.error("Database connection error:", err.message);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
});
|
|
61
|
+
this.database = mongoose.connection;
|
|
62
|
+
this.startApiServer();
|
|
63
|
+
this.registerModules();
|
|
64
|
+
this.initializeDiscordClient();
|
|
65
|
+
this.commandHandler();
|
|
66
|
+
}
|
|
67
|
+
startApiServer() {
|
|
68
|
+
this.app = (0, express_1.express)();
|
|
69
|
+
let port = process.env.PORT || '80';
|
|
70
|
+
this.app.set('port', port);
|
|
71
|
+
var server = http.createServer(this.app);
|
|
72
|
+
server.listen(port);
|
|
73
|
+
server.on('error', (err) => {
|
|
74
|
+
console.log('[❎] Error starting API web server: ' + err);
|
|
75
|
+
});
|
|
76
|
+
server.on('listening', () => {
|
|
77
|
+
console.log('[✅] API web server listening on port ' + port);
|
|
78
|
+
});
|
|
79
|
+
this.app.use(express_1.express.json());
|
|
80
|
+
this.app.use(express_1.express.urlencoded({ extended: false }));
|
|
81
|
+
this.app.use(cookieParser());
|
|
82
|
+
//this.app.use(express.static(path.join(__dirname, "public")));
|
|
83
|
+
//To allow cross-origin requests
|
|
84
|
+
this.app.use(cors());
|
|
85
|
+
//Route Prefixes
|
|
86
|
+
//this.app.use("/", indexRouter);
|
|
87
|
+
//this.app.use("/api/", apiRouter);
|
|
88
|
+
// throw 404 if URL not found
|
|
89
|
+
this.app.all("*", function (req, res) {
|
|
90
|
+
return ApiResponse_1.ApiResponse.notFoundResponse(res, "Page not found");
|
|
91
|
+
});
|
|
92
|
+
this.app.use(function (err, req, res) {
|
|
93
|
+
if (err.name === 'UnauthorizedError') {
|
|
94
|
+
return ApiResponse_1.ApiResponse.unauthorizedResponse(res, "Invalid token");
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
registerModules() {
|
|
99
|
+
let modulesFolder;
|
|
100
|
+
if (fs.existsSync(`${process.cwd()}/modules`)) {
|
|
101
|
+
modulesFolder = `${process.cwd()}/modules`;
|
|
102
|
+
}
|
|
103
|
+
else if (fs.existsSync(`${process.cwd()}/src/modules`)) {
|
|
104
|
+
modulesFolder = `${process.cwd()}/src/modules`;
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
return;
|
|
108
|
+
this.registerModule(__dirname, 'baseModule');
|
|
109
|
+
fs.readdirSync(modulesFolder).forEach(file => {
|
|
110
|
+
this.registerModule(modulesFolder, file);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
registerModule(modulesFolder, moduleName) {
|
|
114
|
+
// Import module
|
|
115
|
+
let module;
|
|
116
|
+
if (fs.existsSync(path.join(modulesFolder, moduleName, 'index.js'))) {
|
|
117
|
+
module = require(path.join(modulesFolder, moduleName, 'index.js'));
|
|
118
|
+
module = Object.values(module)[0];
|
|
119
|
+
}
|
|
120
|
+
else if (fs.existsSync(path.join(modulesFolder, moduleName, 'index.ts'))) {
|
|
121
|
+
module = require(path.join(modulesFolder, moduleName, 'index.ts'));
|
|
122
|
+
module = Object.values(module)[0];
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
module = Module_1.Module;
|
|
126
|
+
}
|
|
127
|
+
;
|
|
128
|
+
// Create module instance
|
|
129
|
+
let moduleInstance = new module(path.join(modulesFolder, moduleName));
|
|
130
|
+
this.modules.set(moduleInstance.constructor.name, moduleInstance);
|
|
131
|
+
// Register module commands
|
|
132
|
+
this.commands = new Map([...this.commands, ...moduleInstance.getCommands()]);
|
|
133
|
+
// Register module events
|
|
134
|
+
this.events = new Map([...this.events, ...moduleInstance.getEvents()]);
|
|
135
|
+
/*
|
|
136
|
+
|
|
137
|
+
// Register module routes
|
|
138
|
+
this.routes = new Map([...this.routes, ...moduleInstance.getRoutes()]);
|
|
139
|
+
|
|
140
|
+
// Register module models
|
|
141
|
+
this.models = new Map([...this.models, ...moduleInstance.getModels()]);
|
|
142
|
+
|
|
143
|
+
*/
|
|
144
|
+
}
|
|
145
|
+
initializeDiscordClient() {
|
|
146
|
+
this.client = new Client({
|
|
147
|
+
intents: this.settings.discordClientOptions.intents
|
|
148
|
+
});
|
|
149
|
+
this.client.login(this.settings.discordClientOptions.token);
|
|
150
|
+
}
|
|
151
|
+
commandHandler() {
|
|
152
|
+
this.client.on('messageCreate', async (message) => {
|
|
153
|
+
let channel = message.channel;
|
|
154
|
+
let prefix = this.settings.defaultPrefix;
|
|
155
|
+
const args = ZumitoFramework.splitCommandLine(message.content.slice(prefix.length));
|
|
156
|
+
const command = args.shift().toLowerCase();
|
|
157
|
+
let commandInstance;
|
|
158
|
+
if (message.content.startsWith(prefix)) {
|
|
159
|
+
if (!this.commands.has(command)) {
|
|
160
|
+
let commandNames = Array.from(this.commands.keys());
|
|
161
|
+
var autocorrect = require('autocorrect')({ words: commandNames });
|
|
162
|
+
var correctedCommand = autocorrect(command);
|
|
163
|
+
if (this.commands.has(correctedCommand)) {
|
|
164
|
+
commandInstance = this.commands.get(correctedCommand);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return; // Command not found
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
commandInstance = this.commands.get(command);
|
|
172
|
+
}
|
|
173
|
+
if (message.guild == null && commandInstance.dm == false)
|
|
174
|
+
return;
|
|
175
|
+
if (commandInstance.adminOnly || commandInstance.permissions.length > 0) {
|
|
176
|
+
let denied = false;
|
|
177
|
+
if (this.memberHasPermission(message.member, message.channel, discord_js_1.PermissionsBitField.Flags.Administrator) || message.member.id != message.guild.ownerId) {
|
|
178
|
+
if (commandInstance.permissions.length > 0) {
|
|
179
|
+
commandInstance.permissions.forEach(permission => {
|
|
180
|
+
if (!this.memberHasPermission(message.member, message.channel, permission)) {
|
|
181
|
+
denied = true;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (denied) {
|
|
187
|
+
return message.reply({
|
|
188
|
+
content: 'You do not have permission to use this command.',
|
|
189
|
+
allowedMentions: {
|
|
190
|
+
repliedUser: false,
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (message.channel.isTextBased) {
|
|
196
|
+
let channel = message.channel;
|
|
197
|
+
// Check command is nsfw and if channel is allowed
|
|
198
|
+
if (commandInstance.nsfw && !channel.nsfw && !channel.permissionsFor(message.member).has(discord_js_1.PermissionsBitField.Flags.Administrator) && message.member.id != message.guild.ownerId) {
|
|
199
|
+
return message.reply({
|
|
200
|
+
content: 'This command is nsfw and this channel is not nsfw.',
|
|
201
|
+
allowedMentions: {
|
|
202
|
+
repliedUser: false,
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
let parsedArgs = new Map();
|
|
209
|
+
args.forEach(function (arg, index) {
|
|
210
|
+
parsedArgs.set(commandInstance.args?.[index]?.name || index, {
|
|
211
|
+
name: commandInstance.args?.[index]?.name || index,
|
|
212
|
+
value: arg
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
await commandInstance.execute({
|
|
216
|
+
message,
|
|
217
|
+
args: parsedArgs,
|
|
218
|
+
client: this.client,
|
|
219
|
+
});
|
|
220
|
+
if (!message.channel.isDMBased && !message.deletable && (false)) { // false = settings.deleteCommands
|
|
221
|
+
try {
|
|
222
|
+
message.delete().catch(function () {
|
|
223
|
+
console.error('can\'t delete user command');
|
|
224
|
+
});
|
|
225
|
+
const metadata = await fetch('https://tulipo.ga/api/last_command/' + command).then(res => res.json());
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
console.error(err.name, err.message);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
// let content = await getErrorEmbed({
|
|
234
|
+
// name: error.name,
|
|
235
|
+
// message: error.message,
|
|
236
|
+
// comid: com,
|
|
237
|
+
// args: args,
|
|
238
|
+
// stack: error.stack,
|
|
239
|
+
// }, true);
|
|
240
|
+
// try {
|
|
241
|
+
// message.reply(content);
|
|
242
|
+
// } catch (e) {
|
|
243
|
+
// channel.send(content);
|
|
244
|
+
// }
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
static splitCommandLine(commandLine) {
|
|
250
|
+
//log( 'commandLine', commandLine ) ;
|
|
251
|
+
// Find a unique marker for the space character.
|
|
252
|
+
// Start with '<SP>' and repeatedly append '@' if necessary to make it unique.
|
|
253
|
+
var spaceMarker = '<SP>';
|
|
254
|
+
while (commandLine.indexOf(spaceMarker) > -1)
|
|
255
|
+
spaceMarker += '@';
|
|
256
|
+
// Protect double-quoted strings.
|
|
257
|
+
// o Find strings of non-double-quotes, wrapped in double-quotes.
|
|
258
|
+
// o The final double-quote is optional to allow for an unterminated string.
|
|
259
|
+
// o Replace each double-quoted-string with what's inside the qouble-quotes,
|
|
260
|
+
// after each space character has been replaced with the space-marker above.
|
|
261
|
+
// o The outer double-quotes will not be present.
|
|
262
|
+
var noSpacesInQuotes = commandLine.replace(/"([^"]*)"?/g, (fullMatch, capture) => {
|
|
263
|
+
return capture.replace(/ /g, spaceMarker);
|
|
264
|
+
});
|
|
265
|
+
// Now that it is safe to do so, split the command-line at one-or-more spaces.
|
|
266
|
+
var mangledParamArray = noSpacesInQuotes.split(/ +/);
|
|
267
|
+
// Create a new array by restoring spaces from any space-markers.
|
|
268
|
+
var paramArray = mangledParamArray.map((mangledParam) => {
|
|
269
|
+
return mangledParam.replace(RegExp(spaceMarker, 'g'), ' ');
|
|
270
|
+
});
|
|
271
|
+
return paramArray;
|
|
272
|
+
}
|
|
273
|
+
async memberHasPermission(member, channel, permission) {
|
|
274
|
+
let memberPermission = await channel.permissionsFor(member);
|
|
275
|
+
return memberPermission.has(permission);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports.ZumitoFramework = ZumitoFramework;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EventParameters } from "../../../types/EventParameters";
|
|
2
|
+
import { FrameworkEvent } from "../../../types/FrameworkEvent";
|
|
3
|
+
export declare abstract class InteractionCreate extends FrameworkEvent {
|
|
4
|
+
once: boolean;
|
|
5
|
+
execute({ interaction, client, framework }: EventParameters): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InteractionCreate = void 0;
|
|
4
|
+
const CommandType_1 = require("../../../types/CommandType");
|
|
5
|
+
const FrameworkEvent_1 = require("../../../types/FrameworkEvent");
|
|
6
|
+
class InteractionCreate extends FrameworkEvent_1.FrameworkEvent {
|
|
7
|
+
once = false;
|
|
8
|
+
async execute({ interaction, client, framework }) {
|
|
9
|
+
if (interaction.isCommand()) {
|
|
10
|
+
if (!framework.commands.has(interaction.commandName))
|
|
11
|
+
return;
|
|
12
|
+
const commandInstance = framework.commands.get(interaction.commandName);
|
|
13
|
+
let args = new Map();
|
|
14
|
+
commandInstance.args.forEach(arg => {
|
|
15
|
+
let option = interaction.options.get(arg.name);
|
|
16
|
+
if (option) {
|
|
17
|
+
args.set(arg.name, option.value || option.user || option.role || option.channel || option.options || option.message || option.member || option.focused || option.autocomplete || option.attachment);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (![CommandType_1.CommandType.any, CommandType_1.CommandType.separated, CommandType_1.CommandType.slash].includes(commandInstance.type))
|
|
21
|
+
return;
|
|
22
|
+
if (commandInstance.type === CommandType_1.CommandType.separated || commandInstance.type === CommandType_1.CommandType.slash) {
|
|
23
|
+
await commandInstance.executeSlashCommand({ client, interaction, args });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
await commandInstance.execute({ client, interaction, args });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (interaction.isButton()) {
|
|
30
|
+
}
|
|
31
|
+
else if (interaction.isSelectMenu()) {
|
|
32
|
+
let path = interaction.customId.split('.');
|
|
33
|
+
const command = framework.commands.get(path[0]);
|
|
34
|
+
if (command.selectMenu) {
|
|
35
|
+
command.selectMenu({ path, interaction, client, framework });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.InteractionCreate = InteractionCreate;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiResponse = void 0;
|
|
4
|
+
class ApiResponse {
|
|
5
|
+
static notFoundResponse(res, msg) {
|
|
6
|
+
let data = {
|
|
7
|
+
message: msg,
|
|
8
|
+
};
|
|
9
|
+
return res.status(404).json(data);
|
|
10
|
+
}
|
|
11
|
+
;
|
|
12
|
+
static unauthorizedResponse(res, msg) {
|
|
13
|
+
let data = {
|
|
14
|
+
message: msg,
|
|
15
|
+
};
|
|
16
|
+
return res.status(401).json(data);
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
}
|
|
20
|
+
exports.ApiResponse = ApiResponse;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ZumitoFramework } from './ZumitoFramework';
|
|
2
|
+
export { FrameworkSettings } from './types/FrameworkSettings';
|
|
3
|
+
export { Command } from './types/Commands';
|
|
4
|
+
export { Module } from './types/Module';
|
|
5
|
+
export { CommandParameters } from './types/CommandParameters';
|
|
6
|
+
export { CommandArguments } from './types/CommandArguments';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandArguments = exports.Module = exports.Command = exports.ZumitoFramework = void 0;
|
|
4
|
+
var ZumitoFramework_1 = require("./ZumitoFramework");
|
|
5
|
+
Object.defineProperty(exports, "ZumitoFramework", { enumerable: true, get: function () { return ZumitoFramework_1.ZumitoFramework; } });
|
|
6
|
+
var Commands_1 = require("./types/Commands");
|
|
7
|
+
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return Commands_1.Command; } });
|
|
8
|
+
var Module_1 = require("./types/Module");
|
|
9
|
+
Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return Module_1.Module; } });
|
|
10
|
+
var CommandArguments_1 = require("./types/CommandArguments");
|
|
11
|
+
Object.defineProperty(exports, "CommandArguments", { enumerable: true, get: function () { return CommandArguments_1.CommandArguments; } });
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CommandInteraction } from "discord.js";
|
|
2
|
+
export declare class CommandArguments {
|
|
3
|
+
args: any;
|
|
4
|
+
constructor(args?: {});
|
|
5
|
+
get(key: any): any;
|
|
6
|
+
add(key: any, value: any): void;
|
|
7
|
+
static parseFromInteraction(interaction: CommandInteraction): CommandArguments;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandArguments = void 0;
|
|
4
|
+
class CommandArguments {
|
|
5
|
+
args = {};
|
|
6
|
+
constructor(args = {}) {
|
|
7
|
+
this.args = args;
|
|
8
|
+
}
|
|
9
|
+
get(key) {
|
|
10
|
+
return this.args[key];
|
|
11
|
+
}
|
|
12
|
+
add(key, value) {
|
|
13
|
+
this.args[key] = value;
|
|
14
|
+
}
|
|
15
|
+
static parseFromInteraction(interaction) {
|
|
16
|
+
return new CommandArguments(interaction.options);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CommandArguments = CommandArguments;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Client, Interaction, Message } from "discord.js";
|
|
2
|
+
/**
|
|
3
|
+
* @class CommandParameters
|
|
4
|
+
* @classdesc Parameters passed to a command execution.
|
|
5
|
+
* @property {Client} client - The client client instance.
|
|
6
|
+
* @property {Message} message - The message that triggered the command.
|
|
7
|
+
* @property {interaction} interaction - The interaction that triggered the command.
|
|
8
|
+
* @property {args} args - The arguments passed to the command.
|
|
9
|
+
*/
|
|
10
|
+
export interface CommandParameters {
|
|
11
|
+
message?: Message;
|
|
12
|
+
interaction?: Interaction;
|
|
13
|
+
args: Map<String, any>;
|
|
14
|
+
client: Client;
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CommandParameters } from "./CommandParameters";
|
|
2
|
+
import { SelectMenuParameters } from "./SelectMenuParameters";
|
|
3
|
+
export declare abstract class Command {
|
|
4
|
+
name: string;
|
|
5
|
+
categories: string[];
|
|
6
|
+
aliases?: string[];
|
|
7
|
+
examples?: string[];
|
|
8
|
+
permissions?: bigint[];
|
|
9
|
+
botPermissions?: string[];
|
|
10
|
+
hidden?: boolean;
|
|
11
|
+
adminOnly?: boolean;
|
|
12
|
+
nsfw?: boolean;
|
|
13
|
+
cooldown?: number;
|
|
14
|
+
slashCommand?: boolean;
|
|
15
|
+
dm: boolean;
|
|
16
|
+
args: CommandArgDefinition[];
|
|
17
|
+
type: string;
|
|
18
|
+
constructor();
|
|
19
|
+
abstract execute({ message, interaction, args, client }: CommandParameters): void;
|
|
20
|
+
executePrefixCommand({ message, interaction, args, client }: CommandParameters): void;
|
|
21
|
+
executeSlashCommand({ message, interaction, args, client }: CommandParameters): void;
|
|
22
|
+
selectMenu({ path, interaction, client, framework }: SelectMenuParameters): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Command = void 0;
|
|
4
|
+
const CommandType_1 = require("./CommandType");
|
|
5
|
+
class Command {
|
|
6
|
+
name = this.constructor.name.toLowerCase();
|
|
7
|
+
categories = [];
|
|
8
|
+
aliases = [];
|
|
9
|
+
examples = [];
|
|
10
|
+
permissions = [];
|
|
11
|
+
botPermissions = [];
|
|
12
|
+
hidden = false;
|
|
13
|
+
adminOnly = false;
|
|
14
|
+
nsfw = false;
|
|
15
|
+
cooldown = 0;
|
|
16
|
+
slashCommand = false;
|
|
17
|
+
dm = false;
|
|
18
|
+
args = [];
|
|
19
|
+
type = CommandType_1.CommandType.prefix;
|
|
20
|
+
constructor() {
|
|
21
|
+
}
|
|
22
|
+
executePrefixCommand({ message, interaction, args, client }) {
|
|
23
|
+
this.execute({ message, interaction, args, client });
|
|
24
|
+
}
|
|
25
|
+
executeSlashCommand({ message, interaction, args, client }) {
|
|
26
|
+
this.execute({ message, interaction, args, client });
|
|
27
|
+
}
|
|
28
|
+
selectMenu({ path, interaction, client, framework }) { }
|
|
29
|
+
}
|
|
30
|
+
exports.Command = Command;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from "./Commands";
|
|
2
|
+
import { FrameworkEvent } from "./FrameworkEvent";
|
|
3
|
+
export declare abstract class Module {
|
|
4
|
+
protected path: string;
|
|
5
|
+
protected commands: Map<String, Command>;
|
|
6
|
+
protected events: Map<String, FrameworkEvent>;
|
|
7
|
+
constructor(path: any);
|
|
8
|
+
registerCommands(): void;
|
|
9
|
+
getCommands(): Map<String, Command>;
|
|
10
|
+
registerEvents(): void;
|
|
11
|
+
getEvents(): Map<String, FrameworkEvent>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Module = void 0;
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
class Module {
|
|
7
|
+
path;
|
|
8
|
+
commands = new Map();
|
|
9
|
+
events = new Map();
|
|
10
|
+
constructor(path) {
|
|
11
|
+
this.path = path;
|
|
12
|
+
this.registerCommands();
|
|
13
|
+
this.registerEvents();
|
|
14
|
+
}
|
|
15
|
+
registerCommands() {
|
|
16
|
+
fs.readdirSync(path.join(this.path, 'commands')).forEach(file => {
|
|
17
|
+
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
18
|
+
let command = require(`${this.path}/commands/${file}`);
|
|
19
|
+
command = Object.values(command)[0];
|
|
20
|
+
command = new command();
|
|
21
|
+
this.commands.set(command.constructor.name.toLowerCase(), command);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
getCommands() {
|
|
26
|
+
return this.commands;
|
|
27
|
+
}
|
|
28
|
+
registerEvents() {
|
|
29
|
+
fs.readdirSync(path.join(this.path, 'events')).forEach(file => {
|
|
30
|
+
if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
31
|
+
let event = require(`${this.path}/events/${file}`);
|
|
32
|
+
event = Object.values(event)[0];
|
|
33
|
+
event = new event();
|
|
34
|
+
this.events.set(event.constructor.name.toLowerCase(), event);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getEvents() {
|
|
39
|
+
return this.events;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Module = Module;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zumito-framework",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Discord.js bot framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"bin": {
|
|
11
|
+
"generate": "./templateGenerator.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"publish": "npm publish",
|
|
17
|
+
"docs": "typedoc --out docs src"
|
|
18
|
+
},
|
|
19
|
+
"author": "fernandomema",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"better-logging": "^5.0.0",
|
|
23
|
+
"discord.js": "^14.2.0",
|
|
24
|
+
"express": "^4.18.1",
|
|
25
|
+
"mongoose": "^6.5.2",
|
|
26
|
+
"plop": "^3.1.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typedoc": "^0.23.10",
|
|
30
|
+
"typescript": "^4.7.4"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import minimist from "minimist";
|
|
4
|
+
import { Plop, run } from "plop";
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const argv = minimist(args);
|
|
8
|
+
|
|
9
|
+
import { dirname } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
|
|
14
|
+
Plop.prepare({
|
|
15
|
+
cwd: argv.cwd,
|
|
16
|
+
configPath: path.join(__dirname, 'plopfile.js'),
|
|
17
|
+
preload: argv.preload || [],
|
|
18
|
+
completion: argv.completion,
|
|
19
|
+
dest: process.cwd()
|
|
20
|
+
}, env => Plop.execute(env, run));
|