Skip to content

Commit

Permalink
fix: do not mention user in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Jun 16, 2024
1 parent 35cd169 commit 09a8279
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,7 +65,9 @@ export function parseResult(
}
const comment = output.comment
? `*${output.comment.replaceAll(/(\\\*|#|\*\/|\/\*)/g, "").trim()}*\n`
: "";
: interaction
? "\n"
: "";
return `${comment}${msgSuccess}`;
}

Expand Down
13 changes: 9 additions & 4 deletions src/events/message_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "";
Expand Down
4 changes: 2 additions & 2 deletions src/utils/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}**__`;
Expand Down

0 comments on commit 09a8279

Please sign in to comment.