diff --git a/src/dice.ts b/src/dice.ts index 54357d13..f54236de 100644 --- a/src/dice.ts +++ b/src/dice.ts @@ -11,7 +11,8 @@ import { evaluate } from "mathjs"; export function parseResult( output: Resultat, ul: Translation, - critical?: { failure?: number; success?: number } + critical?: { failure?: number; success?: number }, + interaction?: boolean ) { //result is in the form of "d% //comment: [dice] = result" //parse into @@ -64,7 +65,9 @@ export function parseResult( } const comment = output.comment ? `*${output.comment.replaceAll(/(\\\*|#|\*\/|\/\*)/g, "").trim()}*\n` - : ""; + : interaction + ? "\n" + : ""; return `${comment}${msgSuccess}`; } diff --git a/src/events/message_create.ts b/src/events/message_create.ts index 6e68d481..b0c74b10 100644 --- a/src/events/message_create.ts +++ b/src/events/message_create.ts @@ -27,11 +27,11 @@ export default (client: EClient): void => { let content = message.content; //detect roll between bracket const detectRoll = content.match(/\[(.*)\]/)?.[1]; - const rollWithMessage = content.match(DETECT_DICE_MESSAGE)?.[3]; - if (rollWithMessage && !detectRoll) { + const comments = content.match(DETECT_DICE_MESSAGE)?.[3]; + if (comments && !detectRoll) { const diceValue = content.match(/^\S*#?d\S+|\{.*\}/); if (!diceValue) return; - content = content.replace(DETECT_DICE_MESSAGE, "$1 /* $3 */"); + content = content.replace(DETECT_DICE_MESSAGE, "$1"); } let deleteInput = true; let result: Resultat | undefined; @@ -43,19 +43,24 @@ export default (client: EClient): void => { if (detectRoll) { deleteInput = false; } + //is a valid roll as we are in the function so we can work as always const userLang = message.guild.preferredLocale ?? Locale.EnglishUS; const ul = ln(userLang); const channel = message.channel; if (!result) return; + if (comments && !detectRoll && result) { + result.dice = `${result.dice} /* ${comments} */`; + result.comment = comments; + } const parser = parseResult(result, ul); if ( channel.name.startsWith("🎲") || client.settings.get(message.guild.id, "disableThread") === true || client.settings.get(message.guild.id, "rollChannel") === channel.id ) { - await message.reply({ content: parser, allowedMentions: { repliedUser: false } }); + await message.reply({ content: parser, allowedMentions: { repliedUser: true } }); return; } let linkToOriginal = ""; diff --git a/src/utils/roll.ts b/src/utils/roll.ts index 70862bdc..6abe6990 100644 --- a/src/utils/roll.ts +++ b/src/utils/roll.ts @@ -63,10 +63,10 @@ export async function rollWithInteraction( } if (comments) { rollDice.comment = comments; - rollDice.dice = `${dice} /* ${comments} `; + rollDice.dice = `${dice} /* ${comments} */`; } - const parser = parseResult(rollDice, ul, critical); + const parser = parseResult(rollDice, ul, critical, !!infoRoll); const userId = user?.id ?? interaction.user.id; let mentionUser: string = userMention(userId); const titleCharName = `__**${title(charName)}**__`;