From ef5eb3608fef7833dc851a7cf1f9516b76cd1fc9 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 23 Jul 2024 17:14:55 -0600 Subject: [PATCH] utility.flagdump: big message check --- src/modules/utility/flagdump.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/modules/utility/flagdump.js b/src/modules/utility/flagdump.js index 27774b1..1dc1eca 100644 --- a/src/modules/utility/flagdump.js +++ b/src/modules/utility/flagdump.js @@ -22,13 +22,14 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) { if (!line || line == "") numOrMention = `<@${msg.author.id}>`; const num = BigInt(numOrMention); + let out = ""; if (list) { let allFlags = 0n; for (const index in UserFlagsMapped) { if (UserFlagsMapped[index] == undefined) continue; allFlags += 1n << BigInt(index); } - return `All flags:\n\`\`\`${flagsFromInt(allFlags, UserFlagsMapped)}\`\`\``; + out = `All flags:\n\`\`\`${flagsFromInt(allFlags, UserFlagsMapped)}\`\`\``; } else if (/<@!?(\d+)>/.test(numOrMention) || SNOWFLAKE_REGEX.test(id)) { const targetId = id ?? numOrMention.match(/<@!?(\d+)>/)?.[1]; if (!targetId) return "Got null ID."; @@ -37,20 +38,34 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) { if (!user) user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(targetId), true).catch(() => {}); if (!user) { - return "Failed to get user."; + out = "Failed to get user."; } else { - return `\`${formatUsername(user)}\`'s public flags:\n\`\`\`${flagsFromInt( + out = `\`${formatUsername(user)}\`'s public flags:\n\`\`\`${flagsFromInt( user.public_flags ?? user.publicFlags, UserFlagsMapped )}\`\`\``; } } else if (!Number.isNaN(num)) { - return `\`\`\`\n${flagsFromInt(num, UserFlagsMapped)}\`\`\``; + out = `\`\`\`\n${flagsFromInt(num, UserFlagsMapped)}\`\`\``; } else { - return `\`${formatUsername(msg.author)}\`'s public flags:\n\`\`\`${flagsFromInt( + out = `\`${formatUsername(msg.author)}\`'s public flags:\n\`\`\`${flagsFromInt( msg.author.publicFlags, UserFlagsMapped )}\`\`\``; } + + if (out.length > 2000) { + return { + content: `Output too long to send in a message:`, + attachments: [ + { + file: out, + filename: "message.txt", + }, + ], + }; + } else { + return out; + } }; hf.registerCommand(flagdump);