zumito-framework 1.1.54 → 1.1.56

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.
@@ -1,22 +1,22 @@
1
1
  import * as url from 'url';
2
- import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, PermissionsBitField } from "discord.js";
2
+ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, PermissionsBitField, } from 'discord.js';
3
3
  import ErrorStackParser from 'error-stack-parser';
4
- import { FrameworkEvent } from "../../../types/FrameworkEvent.js";
5
- import { ZumitoFramework } from "../../../ZumitoFramework.js";
4
+ import { FrameworkEvent } from '../../../types/FrameworkEvent.js';
5
+ import { ZumitoFramework } from '../../../ZumitoFramework.js';
6
6
  import leven from 'leven';
7
- import path from "path";
7
+ import path from 'path';
8
8
  export class MessageCreate extends FrameworkEvent {
9
9
  once = false;
10
10
  async execute({ message, client, framework }) {
11
- let channel = message.channel;
12
- let prefix = framework.settings.defaultPrefix;
11
+ const channel = message.channel;
12
+ const prefix = framework.settings.defaultPrefix;
13
13
  const args = ZumitoFramework.splitCommandLine(message.content.slice(prefix.length));
14
14
  const command = args.shift().toLowerCase();
15
15
  let commandInstance;
16
16
  if (message.content.startsWith(prefix)) {
17
17
  if (!framework.commands.has(command)) {
18
- let commandNames = Array.from(framework.commands.keys());
19
- var correctedCommand = this.autocorrect(command, commandNames);
18
+ const commandNames = Array.from(framework.commands.keys());
19
+ const correctedCommand = this.autocorrect(command, commandNames);
20
20
  if (framework.commands.has(correctedCommand)) {
21
21
  commandInstance = framework.commands.get(correctedCommand);
22
22
  }
@@ -29,11 +29,13 @@ export class MessageCreate extends FrameworkEvent {
29
29
  }
30
30
  if (message.guild == null && commandInstance.dm == false)
31
31
  return;
32
- if (commandInstance.adminOnly || commandInstance.userPermissions.length > 0) {
32
+ if (commandInstance.adminOnly ||
33
+ commandInstance.userPermissions.length > 0) {
33
34
  let denied = false;
34
- if (framework.memberHasPermission(message.member, message.channel, PermissionsBitField.Flags.Administrator) || message.member.id != message.guild.ownerId) {
35
+ if (framework.memberHasPermission(message.member, message.channel, PermissionsBitField.Flags.Administrator) ||
36
+ message.member.id != message.guild.ownerId) {
35
37
  if (commandInstance.userPermissions.length > 0) {
36
- commandInstance.userPermissions.forEach(permission => {
38
+ commandInstance.userPermissions.forEach((permission) => {
37
39
  if (!framework.memberHasPermission(message.member, message.channel, permission)) {
38
40
  denied = true;
39
41
  }
@@ -45,29 +47,34 @@ export class MessageCreate extends FrameworkEvent {
45
47
  content: 'You do not have permission to use this command.',
46
48
  allowedMentions: {
47
49
  repliedUser: false,
48
- }
50
+ },
49
51
  });
50
52
  }
51
53
  }
52
54
  if (message.channel.isTextBased) {
53
- let channel = message.channel;
55
+ const channel = message.channel;
54
56
  // Check command is nsfw and if channel is allowed
55
- if (commandInstance.nsfw && !channel.nsfw && !channel.permissionsFor(message.member).has(PermissionsBitField.Flags.Administrator) && message.member.id != message.guild.ownerId) {
57
+ if (commandInstance.nsfw &&
58
+ !channel.nsfw &&
59
+ !channel
60
+ .permissionsFor(message.member)
61
+ .has(PermissionsBitField.Flags.Administrator) &&
62
+ message.member.id != message.guild.ownerId) {
56
63
  return message.reply({
57
64
  content: 'This command is nsfw and this channel is not nsfw.',
58
65
  allowedMentions: {
59
66
  repliedUser: false,
60
- }
67
+ },
61
68
  });
62
69
  }
63
70
  }
64
71
  try {
65
- let guildSettings = await framework.getGuildSettings(message.guildId);
66
- let parsedArgs = new Map();
67
- let userMentionCount = 0;
72
+ const guildSettings = await framework.getGuildSettings(message.guildId);
73
+ const parsedArgs = new Map();
74
+ const userMentionCount = 0;
68
75
  for (let i = 0; i < args.length; i++) {
69
- let arg = args[i];
70
- let type = commandInstance.args[i]?.type;
76
+ const arg = args[i];
77
+ const type = commandInstance.args[i]?.type;
71
78
  if (type) {
72
79
  if (type == 'member' || type == 'user') {
73
80
  const member = await message.guild.members.cache.get(arg.replace(/[<@!>]/g, ''));
@@ -84,7 +91,7 @@ export class MessageCreate extends FrameworkEvent {
84
91
  content: 'Invalid user.',
85
92
  allowedMentions: {
86
93
  repliedUser: false,
87
- }
94
+ },
88
95
  });
89
96
  }
90
97
  }
@@ -106,14 +113,15 @@ export class MessageCreate extends FrameworkEvent {
106
113
  else {
107
114
  return framework.translations.get('command.' + commandInstance.name + '.' + key, guildSettings.lang, params);
108
115
  }
109
- }
116
+ },
110
117
  });
111
- if (!message.channel.isDMBased && !message.deletable && (false)) { // false = settings.deleteCommands
118
+ if (!message.channel.isDMBased && !message.deletable && false) {
119
+ // false = settings.deleteCommands
112
120
  try {
113
121
  message.delete().catch(function () {
114
- console.error('can\'t delete user command');
122
+ console.error("can't delete user command");
115
123
  });
116
- const metadata = await fetch('https://tulipo.ga/api/last_command/' + command).then(res => res.json());
124
+ const metadata = await fetch('https://tulipo.ga/api/last_command/' + command).then((res) => res.json());
117
125
  }
118
126
  catch (err) {
119
127
  console.error(err.name, err.message);
@@ -121,7 +129,7 @@ export class MessageCreate extends FrameworkEvent {
121
129
  }
122
130
  }
123
131
  catch (error) {
124
- let content = await this.getErrorEmbed({
132
+ const content = await this.getErrorEmbed({
125
133
  name: error.name,
126
134
  message: error.message,
127
135
  command: commandInstance,
@@ -138,9 +146,9 @@ export class MessageCreate extends FrameworkEvent {
138
146
  }
139
147
  }
140
148
  autocorrect(str, words) {
141
- var distance, bestWord, i, word, min;
142
- var dictionary = words || [];
143
- var len = dictionary.length;
149
+ let distance, bestWord, i, word, min;
150
+ const dictionary = words || [];
151
+ const len = dictionary.length;
144
152
  for (i = 0; i < len; i++) {
145
153
  word = dictionary[i];
146
154
  distance = leven(str, word);
@@ -162,60 +170,77 @@ export class MessageCreate extends FrameworkEvent {
162
170
  else {
163
171
  parsedError = error;
164
172
  }
165
- let embed = new EmbedBuilder()
173
+ const embed = new EmbedBuilder()
166
174
  .setTitle('Error')
167
175
  .setDescription('An error has occured while executing this command.')
168
176
  .setTimestamp()
169
- .addFields([{
177
+ .addFields([
178
+ {
170
179
  name: 'Command:',
171
- value: (error.command.name || 'Not defined')
172
- }])
173
- .addFields([{
180
+ value: error.command.name || 'Not defined',
181
+ },
182
+ ])
183
+ .addFields([
184
+ {
174
185
  name: 'Arguments:',
175
- value: (error.args.toString() || 'None')
176
- }])
177
- .addFields([{
186
+ value: error.args.toString() || 'None',
187
+ },
188
+ ])
189
+ .addFields([
190
+ {
178
191
  name: 'Error name:',
179
- value: (error.name || 'Not defined')
180
- }])
181
- .addFields([{
192
+ value: error.name || 'Not defined',
193
+ },
194
+ ])
195
+ .addFields([
196
+ {
182
197
  name: 'Error message:',
183
- value: (error.message || 'Not defined')
184
- }]);
198
+ value: error.message || 'Not defined',
199
+ },
200
+ ]);
185
201
  if (error.possibleSolutions !== undefined) {
186
202
  error.possibleSolutions.forEach((solution) => {
187
- embed.addFields([{
203
+ embed.addFields([
204
+ {
188
205
  name: 'Posible solution:',
189
- value: solution
190
- }]);
206
+ value: solution,
207
+ },
208
+ ]);
191
209
  });
192
210
  }
193
- let stackFrames = ErrorStackParser.parse(error).filter(e => !e.fileName.includes('node_modules') && !e.fileName.includes('node:internal'));
211
+ const stackFrames = ErrorStackParser.parse(error).filter((e) => !e.fileName.includes('node_modules') &&
212
+ !e.fileName.includes('node:internal'));
194
213
  let stack = '';
195
214
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
196
- let path1 = path.resolve('./');
197
- let path2 = path1.replaceAll('\\', '/');
215
+ const path1 = path.resolve('./');
216
+ const path2 = path1.replaceAll('\\', '/');
198
217
  stackFrames.forEach((frame) => {
199
- stack += `[${frame.fileName.replace(path1, '').replace(path2, '').replace('file://', '')}:${frame.lineNumber}](https://zumito.ga/redirect?url=vscode://file/${frame.fileName.replace('file://', '')}:${frame.lineNumber}) ${frame.functionName}()\n`;
218
+ stack += `[${frame.fileName
219
+ .replace(path1, '')
220
+ .replace(path2, '')
221
+ .replace('file://', '')}:${frame.lineNumber}](https://zumito.ga/redirect?url=vscode://file/${frame.fileName.replace('file://', '')}:${frame.lineNumber}) ${frame.functionName}()\n`;
200
222
  });
201
223
  if (error.stack !== undefined) {
202
- embed.addFields([{
224
+ embed.addFields([
225
+ {
203
226
  name: 'Call stack:',
204
- value: stack || error.stack || error.stack.toString()
205
- }]);
227
+ value: stack || error.stack || error.stack.toString(),
228
+ },
229
+ ]);
206
230
  }
207
231
  if (error.details !== undefined) {
208
232
  error.details.forEach((detail) => {
209
- embed.addFields([{
233
+ embed.addFields([
234
+ {
210
235
  name: 'Detail:',
211
- value: detail
212
- }]);
236
+ value: detail,
237
+ },
238
+ ]);
213
239
  });
214
240
  }
215
241
  const body = `\n\n\n---\nComand:\`\`\`${error.command.name || 'not defined'}\`\`\`\nArguments:\`\`\`${error.args.toString() || 'none'}\`\`\`\nError:\`\`\`${error.name || 'not defined'}\`\`\`\nError message:\`\`\`${error.message || 'not defined'}\`\`\`\n`;
216
- const requestUrl = `https://github.com/fernandomema/Zumito/issues/new?body=${encodeURIComponent(body)}`;
217
- const row = new ActionRowBuilder()
218
- .addComponents(new ButtonBuilder()
242
+ const requestUrl = `https://github.com/ZumitoTeam/Zumito/issues/new?body=${encodeURIComponent(body)}`;
243
+ const row = new ActionRowBuilder().addComponents(new ButtonBuilder()
219
244
  .setStyle(ButtonStyle.Link)
220
245
  .setLabel('Report error')
221
246
  .setEmoji('975645505302437978')
@@ -224,17 +249,19 @@ export class MessageCreate extends FrameworkEvent {
224
249
  embeds: [embed],
225
250
  components: [row],
226
251
  allowedMentions: {
227
- repliedUser: false
228
- }
252
+ repliedUser: false,
253
+ },
229
254
  };
230
255
  }
231
256
  parseError(error) {
232
257
  error.possibleSolutions = [];
233
258
  if (/(?:^|(?<= ))(EmbedBuilder|Discord|ActionRowBuilder|ButtonBuilder|MessageSelectMenu)(?:(?= )|$) is not defined/gm.test(error.message)) {
234
- error.possibleSolutions.push('const { ' + error.message.split(" ")[0] + ' } = require(\'discord.js\');');
259
+ error.possibleSolutions.push('const { ' +
260
+ error.message.split(' ')[0] +
261
+ " } = require('discord.js');");
235
262
  }
236
263
  else if (error.message.includes('A custom id and url cannot both be specified')) {
237
- error.possibleSolutions.push("Remove .setCustomId(...) or .setURL(...)");
264
+ error.possibleSolutions.push('Remove .setCustomId(...) or .setURL(...)');
238
265
  }
239
266
  return error;
240
267
  }
@@ -1,5 +1,5 @@
1
- import { Module } from "../types/Module.js";
2
- import { ZumitoFramework } from "../ZumitoFramework.js";
1
+ import { Module } from '../types/Module.js';
2
+ import { ZumitoFramework } from '../ZumitoFramework.js';
3
3
  export declare class baseModule extends Module {
4
4
  constructor(modulePath: string, framework: ZumitoFramework);
5
5
  registerEvents(): Promise<any>;
@@ -1,6 +1,6 @@
1
- import { Module } from "../types/Module.js";
2
- import { InteractionCreate } from "./events/discord/interactionCreate.js";
3
- import { MessageCreate } from "./events/discord/messageCreate.js";
1
+ import { Module } from '../types/Module.js';
2
+ import { InteractionCreate } from './events/discord/interactionCreate.js';
3
+ import { MessageCreate } from './events/discord/messageCreate.js';
4
4
  export class baseModule extends Module {
5
5
  constructor(modulePath, framework) {
6
6
  super(modulePath, framework);
@@ -8,7 +8,7 @@ export class baseModule extends Module {
8
8
  async registerEvents() {
9
9
  this.events.set('interactionCreate', new InteractionCreate());
10
10
  this.events.set('messageCreate', new MessageCreate());
11
- this.events.forEach(event => {
11
+ this.events.forEach((event) => {
12
12
  this.registerDiscordEvent(event);
13
13
  });
14
14
  }
@@ -1,16 +1,14 @@
1
1
  export class ApiResponse {
2
2
  static notFoundResponse(res, msg) {
3
- let data = {
3
+ const data = {
4
4
  message: msg,
5
5
  };
6
6
  return res.status(404).json(data);
7
7
  }
8
- ;
9
8
  static unauthorizedResponse(res, msg) {
10
- let data = {
9
+ const data = {
11
10
  message: msg,
12
11
  };
13
12
  return res.status(401).json(data);
14
13
  }
15
- ;
16
14
  }
package/dist/index.d.ts CHANGED
@@ -16,4 +16,4 @@ import { ZumitoFramework } from './ZumitoFramework.js';
16
16
  import { EmojiFallback } from './utils/EmojiFallback.js';
17
17
  import { ButtonPressed } from './types/Commands/ButtonPressed.js';
18
18
  import { ButtonPressedParams } from './types/Commands/ButtonPressedParams.js';
19
- export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, ButtonPressed, ButtonPressedParams, TextFormatter, EmojiFallback };
19
+ export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, ButtonPressed, ButtonPressedParams, TextFormatter, EmojiFallback, };
package/dist/index.js CHANGED
@@ -10,4 +10,4 @@ import { TranslationManager } from './TranslationManager.js';
10
10
  import { ZumitoFramework } from './ZumitoFramework.js';
11
11
  import { EmojiFallback } from './utils/EmojiFallback.js';
12
12
  import { ButtonPressed } from './types/Commands/ButtonPressed.js';
13
- export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback };
13
+ export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback, };
@@ -1,4 +1,4 @@
1
- import { Client } from "discord.js";
1
+ import { Client } from 'discord.js';
2
2
  export declare class EmojiManager {
3
3
  /**
4
4
  * @param {Client} client - The client client instance.
@@ -1,6 +1,6 @@
1
- import { CommandArgDefinition } from "./CommandArgDefinition.js";
2
- import { CommandParameters } from "./CommandParameters.js";
3
- import { SelectMenuParameters } from "./SelectMenuParameters.js";
1
+ import { CommandArgDefinition } from './CommandArgDefinition.js';
2
+ import { CommandParameters } from './CommandParameters.js';
3
+ import { SelectMenuParameters } from './SelectMenuParameters.js';
4
4
  export declare abstract class Command {
5
5
  name: string;
6
6
  categories: string[];
@@ -17,8 +17,8 @@ export declare abstract class Command {
17
17
  args: CommandArgDefinition[];
18
18
  type: string;
19
19
  constructor();
20
- abstract execute({ message, interaction, args, client, framework }: CommandParameters): void;
21
- executePrefixCommand({ message, interaction, args, client, framework, trans }: CommandParameters): void;
22
- executeSlashCommand({ message, interaction, args, client, framework, trans }: CommandParameters): void;
23
- abstract selectMenu({ path, interaction, client, framework, trans }: SelectMenuParameters): void;
20
+ abstract execute({ message, interaction, args, client, framework, }: CommandParameters): void;
21
+ executePrefixCommand({ message, interaction, args, client, framework, trans, }: CommandParameters): void;
22
+ executeSlashCommand({ message, interaction, args, client, framework, trans, }: CommandParameters): void;
23
+ abstract selectMenu({ path, interaction, client, framework, trans, }: SelectMenuParameters): void;
24
24
  }
@@ -1,4 +1,4 @@
1
- import { CommandType } from "./CommandType.js";
1
+ import { CommandType } from './CommandType.js';
2
2
  export class Command {
3
3
  name = this.constructor.name.toLowerCase();
4
4
  categories = [];
@@ -14,12 +14,11 @@ export class Command {
14
14
  dm = false;
15
15
  args = [];
16
16
  type = CommandType.prefix;
17
- constructor() {
18
- }
19
- executePrefixCommand({ message, interaction, args, client, framework, trans }) {
17
+ constructor() { }
18
+ executePrefixCommand({ message, interaction, args, client, framework, trans, }) {
20
19
  this.execute({ message, interaction, args, client, framework, trans });
21
20
  }
22
- executeSlashCommand({ message, interaction, args, client, framework, trans }) {
21
+ executeSlashCommand({ message, interaction, args, client, framework, trans, }) {
23
22
  this.execute({ message, interaction, args, client, framework, trans });
24
23
  }
25
24
  }
@@ -1,4 +1,4 @@
1
- import { CommandInteraction } from "discord.js";
1
+ import { CommandInteraction } from 'discord.js';
2
2
  export declare class CommandArguments {
3
3
  args: any;
4
4
  constructor(args?: {});
@@ -1,5 +1,5 @@
1
- import { Client, CommandInteraction, Message } from "discord.js";
2
- import { ZumitoFramework } from "../ZumitoFramework.js";
1
+ import { Client, CommandInteraction, Message } from 'discord.js';
2
+ import { ZumitoFramework } from '../ZumitoFramework.js';
3
3
  /**
4
4
  * @class CommandParameters
5
5
  * @classdesc Parameters passed to a command execution.
@@ -11,7 +11,7 @@ import { ZumitoFramework } from "../ZumitoFramework.js";
11
11
  export interface CommandParameters {
12
12
  message?: Message;
13
13
  interaction?: CommandInteraction;
14
- args: Map<String, any>;
14
+ args: Map<string, any>;
15
15
  client: Client;
16
16
  framework: ZumitoFramework;
17
17
  guildSettings?: any;
@@ -1,4 +1,4 @@
1
- import { ButtonPressedParams } from "./ButtonPressedParams";
1
+ import { ButtonPressedParams } from './ButtonPressedParams';
2
2
  export declare abstract class ButtonPressed {
3
3
  abstract buttonPressed({}: ButtonPressedParams): void;
4
4
  }
@@ -1,5 +1,5 @@
1
- import { ButtonInteraction, Client } from "discord.js";
2
- import { ZumitoFramework } from "../../ZumitoFramework";
1
+ import { ButtonInteraction, Client } from 'discord.js';
2
+ import { ZumitoFramework } from '../../ZumitoFramework';
3
3
  export interface ButtonPressedParams {
4
4
  path: string[];
5
5
  interaction: ButtonInteraction;
@@ -1,5 +1,5 @@
1
- import { Client, Interaction, Message } from "discord.js";
2
- import { ZumitoFramework } from "../ZumitoFramework.js";
1
+ import { Client, Interaction, Message } from 'discord.js';
2
+ import { ZumitoFramework } from '../ZumitoFramework.js';
3
3
  export interface EventParameters {
4
4
  message?: Message;
5
5
  interaction?: Interaction;
@@ -1,6 +1,6 @@
1
- import { ZumitoFramework } from "../ZumitoFramework.js";
2
- import { Command } from "./Command.js";
3
- import { FrameworkEvent } from "./FrameworkEvent.js";
1
+ import { ZumitoFramework } from '../ZumitoFramework.js';
2
+ import { Command } from './Command.js';
3
+ import { FrameworkEvent } from './FrameworkEvent.js';
4
4
  export declare abstract class Module {
5
5
  protected path: string;
6
6
  protected framework: ZumitoFramework;