zumito-framework 1.1.55 → 1.1.57

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,16 @@ 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) {
119
+ return; // TODO: test if this works
120
+ // false = settings.deleteCommands
112
121
  try {
113
122
  message.delete().catch(function () {
114
- console.error('can\'t delete user command');
123
+ console.error("can't delete user command");
115
124
  });
116
- const metadata = await fetch('https://tulipo.ga/api/last_command/' + command).then(res => res.json());
125
+ const metadata = await fetch('https://tulipo.ga/api/last_command/' + command).then((res) => res.json());
117
126
  }
118
127
  catch (err) {
119
128
  console.error(err.name, err.message);
@@ -121,7 +130,7 @@ export class MessageCreate extends FrameworkEvent {
121
130
  }
122
131
  }
123
132
  catch (error) {
124
- let content = await this.getErrorEmbed({
133
+ const content = await this.getErrorEmbed({
125
134
  name: error.name,
126
135
  message: error.message,
127
136
  command: commandInstance,
@@ -138,9 +147,9 @@ export class MessageCreate extends FrameworkEvent {
138
147
  }
139
148
  }
140
149
  autocorrect(str, words) {
141
- var distance, bestWord, i, word, min;
142
- var dictionary = words || [];
143
- var len = dictionary.length;
150
+ let distance, bestWord, i, word, min;
151
+ const dictionary = words || [];
152
+ const len = dictionary.length;
144
153
  for (i = 0; i < len; i++) {
145
154
  word = dictionary[i];
146
155
  distance = leven(str, word);
@@ -162,60 +171,77 @@ export class MessageCreate extends FrameworkEvent {
162
171
  else {
163
172
  parsedError = error;
164
173
  }
165
- let embed = new EmbedBuilder()
174
+ const embed = new EmbedBuilder()
166
175
  .setTitle('Error')
167
176
  .setDescription('An error has occured while executing this command.')
168
177
  .setTimestamp()
169
- .addFields([{
178
+ .addFields([
179
+ {
170
180
  name: 'Command:',
171
- value: (error.command.name || 'Not defined')
172
- }])
173
- .addFields([{
181
+ value: error.command.name || 'Not defined',
182
+ },
183
+ ])
184
+ .addFields([
185
+ {
174
186
  name: 'Arguments:',
175
- value: (error.args.toString() || 'None')
176
- }])
177
- .addFields([{
187
+ value: error.args.toString() || 'None',
188
+ },
189
+ ])
190
+ .addFields([
191
+ {
178
192
  name: 'Error name:',
179
- value: (error.name || 'Not defined')
180
- }])
181
- .addFields([{
193
+ value: error.name || 'Not defined',
194
+ },
195
+ ])
196
+ .addFields([
197
+ {
182
198
  name: 'Error message:',
183
- value: (error.message || 'Not defined')
184
- }]);
199
+ value: error.message || 'Not defined',
200
+ },
201
+ ]);
185
202
  if (error.possibleSolutions !== undefined) {
186
203
  error.possibleSolutions.forEach((solution) => {
187
- embed.addFields([{
204
+ embed.addFields([
205
+ {
188
206
  name: 'Posible solution:',
189
- value: solution
190
- }]);
207
+ value: solution,
208
+ },
209
+ ]);
191
210
  });
192
211
  }
193
- let stackFrames = ErrorStackParser.parse(error).filter(e => !e.fileName.includes('node_modules') && !e.fileName.includes('node:internal'));
212
+ const stackFrames = ErrorStackParser.parse(error).filter((e) => !e.fileName.includes('node_modules') &&
213
+ !e.fileName.includes('node:internal'));
194
214
  let stack = '';
195
215
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
196
- let path1 = path.resolve('./');
197
- let path2 = path1.replaceAll('\\', '/');
216
+ const path1 = path.resolve('./');
217
+ const path2 = path1.replaceAll('\\', '/');
198
218
  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`;
219
+ stack += `[${frame.fileName
220
+ .replace(path1, '')
221
+ .replace(path2, '')
222
+ .replace('file://', '')}:${frame.lineNumber}](https://zumito.ga/redirect?url=vscode://file/${frame.fileName.replace('file://', '')}:${frame.lineNumber}) ${frame.functionName}()\n`;
200
223
  });
201
224
  if (error.stack !== undefined) {
202
- embed.addFields([{
225
+ embed.addFields([
226
+ {
203
227
  name: 'Call stack:',
204
- value: stack || error.stack || error.stack.toString()
205
- }]);
228
+ value: stack || error.stack || error.stack.toString(),
229
+ },
230
+ ]);
206
231
  }
207
232
  if (error.details !== undefined) {
208
233
  error.details.forEach((detail) => {
209
- embed.addFields([{
234
+ embed.addFields([
235
+ {
210
236
  name: 'Detail:',
211
- value: detail
212
- }]);
237
+ value: detail,
238
+ },
239
+ ]);
213
240
  });
214
241
  }
215
242
  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
243
  const requestUrl = `https://github.com/ZumitoTeam/Zumito/issues/new?body=${encodeURIComponent(body)}`;
217
- const row = new ActionRowBuilder()
218
- .addComponents(new ButtonBuilder()
244
+ const row = new ActionRowBuilder().addComponents(new ButtonBuilder()
219
245
  .setStyle(ButtonStyle.Link)
220
246
  .setLabel('Report error')
221
247
  .setEmoji('975645505302437978')
@@ -224,17 +250,19 @@ export class MessageCreate extends FrameworkEvent {
224
250
  embeds: [embed],
225
251
  components: [row],
226
252
  allowedMentions: {
227
- repliedUser: false
228
- }
253
+ repliedUser: false,
254
+ },
229
255
  };
230
256
  }
231
257
  parseError(error) {
232
258
  error.possibleSolutions = [];
233
259
  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\');');
260
+ error.possibleSolutions.push('const { ' +
261
+ error.message.split(' ')[0] +
262
+ " } = require('discord.js');");
235
263
  }
236
264
  else if (error.message.includes('A custom id and url cannot both be specified')) {
237
- error.possibleSolutions.push("Remove .setCustomId(...) or .setURL(...)");
265
+ error.possibleSolutions.push('Remove .setCustomId(...) or .setURL(...)');
238
266
  }
239
267
  return error;
240
268
  }
@@ -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;