diff --git a/src/commands/roll.ts b/src/commands/roll.ts index 62ccaec..9b3ae27 100644 --- a/src/commands/roll.ts +++ b/src/commands/roll.ts @@ -40,7 +40,7 @@ export const roll = async (message: DiscordenoMessage, args: string[], command: // Rest of this command is in a try-catch to protect all sends/edits from erroring out try { - const originalCommand = `${config.prefix}${command} ${args.join(' ')}`; + const originalCommand = `${config.prefix}${command}${command.length === 0 ? args.join('').trim() : args.join('')}`; const m = await message.reply(rollingEmbed); @@ -60,14 +60,14 @@ export const roll = async (message: DiscordenoMessage, args: string[], command: return; } - let rollCmd = message.content.startsWith(`${config.prefix}r`) ? remainingArgs.join(' ') : `${config.prefix}${command} ${remainingArgs.join(' ')}`; + let rollCmd = message.content.startsWith(`${config.prefix}r`) ? remainingArgs.join('') : `${config.prefix}${command}${remainingArgs.join('')}`; // Try to ensure the roll is wrapped - if (!rollCmd.includes(config.prefix)) { - rollCmd = `${config.prefix}${rollCmd}`; - } if (!rollCmd.includes(config.postfix)) { - rollCmd = `${rollCmd}${config.postfix}`; + rollCmd = `${rollCmd.trim()}${config.postfix}`; + } + if (!rollCmd.includes(config.prefix) || rollCmd.indexOf(config.prefix) > rollCmd.indexOf(config.postfix)) { + rollCmd = `${config.prefix}${rollCmd.trim()}`; } sendRollRequest({ diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index e748600..f7e6b8b 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -32,7 +32,12 @@ export const messageCreateHandler = (message: DiscordenoMessage) => { .slice(config.prefix.length) .trim() .split(/[ \n]+/g); + const argSpaces = message.content + .slice(config.prefix.length) + .trim() + .split(new RegExp(/([ \n]+)/, 'g')); const command = args.shift()?.toLowerCase(); + argSpaces.shift(); // All commands below here @@ -128,7 +133,7 @@ export const messageCreateHandler = (message: DiscordenoMessage) => { case 'r': // [[roll or [[r // Dice rolling commence! - commands.roll(message, args, args.join('')); + commands.roll(message, argSpaces, ''); break; default: // Non-standard commands @@ -139,7 +144,7 @@ export const messageCreateHandler = (message: DiscordenoMessage) => { } else if (command && `${command}${args.join('')}`.includes(config.postfix)) { // [[roll]] // Dice rolling commence! - commands.roll(message, args, command); + commands.roll(message, argSpaces, command); } else if (command) { // [[emoji or [[emoji-alias // Check if the unhandled command is an emoji request