Skip to content

Commit

Permalink
Merge pull request AlexzanderFlores#182 from AlexzanderFlores/dev
Browse files Browse the repository at this point in the history
Fix another slash command bug
  • Loading branch information
AlexzanderFlores authored Oct 12, 2021
2 parents aa2480c + dce81db commit 7288596
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
42 changes: 24 additions & 18 deletions dist/commands/slash.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ module.exports = {
let allSlashCommands = [];
if (global.size) {
global.forEach((cmd) => {
const newString = `${cmd?.name}: ${cmd?.id}\n`;
if (!allSlashCommands[counter]) {
allSlashCommands[counter] = '';
}
if (allSlashCommands[counter].length + newString.length < 1024) {
allSlashCommands[counter] += newString;
}
else {
allSlashCommands[++counter] += newString;
if (cmd && cmd.name) {
const newString = `${cmd.name}: ${cmd.id}\n`;
if ((allSlashCommands[counter] || []).length + newString.length <
1024) {
allSlashCommands[counter] ??= '';
allSlashCommands[counter] += newString;
}
else {
++counter;
allSlashCommands[counter] ??= '';
allSlashCommands[counter] += newString;
}
}
});
}
Expand All @@ -60,15 +63,18 @@ module.exports = {
let guildOnlyCommands = [];
if (guildOnly.size) {
guildOnly.forEach((cmd) => {
const newString = `${cmd.name}: ${cmd.id}\n`;
if (!guildOnlyCommands[counter]) {
guildOnlyCommands[counter] = '';
}
if (guildOnlyCommands[counter].length + newString.length < 1024) {
guildOnlyCommands[counter] += newString;
}
else {
guildOnlyCommands[++counter] += newString;
if (cmd && cmd.name) {
const newString = `${cmd.name}: ${cmd.id}\n`;
if ((guildOnlyCommands[counter] || []).length + newString.length <
1024) {
guildOnlyCommands[counter] ??= '';
guildOnlyCommands[counter] += newString;
}
else {
++counter;
guildOnlyCommands[counter] ??= '';
guildOnlyCommands[counter] += newString;
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wokcommands",
"version": "1.5.2",
"version": "1.5.3",
"main": "dist/index.js",
"typings": "./typings.d.ts",
"scripts": {
Expand Down
46 changes: 27 additions & 19 deletions src/commands/slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@ export = {

if (global.size) {
global.forEach((cmd: ApplicationCommand) => {
const newString = `${cmd?.name}: ${cmd?.id}\n`

if (!allSlashCommands[counter]) {
allSlashCommands[counter] = ''
}
if (cmd && cmd.name) {
const newString = `${cmd.name}: ${cmd.id}\n`

if (allSlashCommands[counter].length + newString.length < 1024) {
allSlashCommands[counter] += newString
} else {
allSlashCommands[++counter] += newString
if (
(allSlashCommands[counter] || []).length + newString.length <
1024
) {
allSlashCommands[counter] ??= ''
allSlashCommands[counter] += newString
} else {
++counter
allSlashCommands[counter] ??= ''
allSlashCommands[counter] += newString
}
}
})
} else {
Expand All @@ -85,16 +89,20 @@ export = {

if (guildOnly.size) {
guildOnly.forEach((cmd: ApplicationCommand) => {
const newString = `${cmd.name}: ${cmd.id}\n`

if (!guildOnlyCommands[counter]) {
guildOnlyCommands[counter] = ''
}

if (guildOnlyCommands[counter].length + newString.length < 1024) {
guildOnlyCommands[counter] += newString
} else {
guildOnlyCommands[++counter] += newString
if (cmd && cmd.name) {
const newString = `${cmd.name}: ${cmd.id}\n`

if (
(guildOnlyCommands[counter] || []).length + newString.length <
1024
) {
guildOnlyCommands[counter] ??= ''
guildOnlyCommands[counter] += newString
} else {
++counter
guildOnlyCommands[counter] ??= ''
guildOnlyCommands[counter] += newString
}
}
})
} else {
Expand Down

0 comments on commit 7288596

Please sign in to comment.