utility.flagdump: big message check

This commit is contained in:
Cynthia Foxwell 2024-07-23 17:14:55 -06:00
parent 43354bcbca
commit ef5eb3608f

View file

@ -22,13 +22,14 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) {
if (!line || line == "") numOrMention = `<@${msg.author.id}>`; if (!line || line == "") numOrMention = `<@${msg.author.id}>`;
const num = BigInt(numOrMention); const num = BigInt(numOrMention);
let out = "";
if (list) { if (list) {
let allFlags = 0n; let allFlags = 0n;
for (const index in UserFlagsMapped) { for (const index in UserFlagsMapped) {
if (UserFlagsMapped[index] == undefined) continue; if (UserFlagsMapped[index] == undefined) continue;
allFlags += 1n << BigInt(index); 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)) { } else if (/<@!?(\d+)>/.test(numOrMention) || SNOWFLAKE_REGEX.test(id)) {
const targetId = id ?? numOrMention.match(/<@!?(\d+)>/)?.[1]; const targetId = id ?? numOrMention.match(/<@!?(\d+)>/)?.[1];
if (!targetId) return "Got null ID."; 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) user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(targetId), true).catch(() => {});
if (!user) { if (!user) {
return "Failed to get user."; out = "Failed to get user.";
} else { } else {
return `\`${formatUsername(user)}\`'s public flags:\n\`\`\`${flagsFromInt( out = `\`${formatUsername(user)}\`'s public flags:\n\`\`\`${flagsFromInt(
user.public_flags ?? user.publicFlags, user.public_flags ?? user.publicFlags,
UserFlagsMapped UserFlagsMapped
)}\`\`\``; )}\`\`\``;
} }
} else if (!Number.isNaN(num)) { } else if (!Number.isNaN(num)) {
return `\`\`\`\n${flagsFromInt(num, UserFlagsMapped)}\`\`\``; out = `\`\`\`\n${flagsFromInt(num, UserFlagsMapped)}\`\`\``;
} else { } else {
return `\`${formatUsername(msg.author)}\`'s public flags:\n\`\`\`${flagsFromInt( out = `\`${formatUsername(msg.author)}\`'s public flags:\n\`\`\`${flagsFromInt(
msg.author.publicFlags, msg.author.publicFlags,
UserFlagsMapped 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); hf.registerCommand(flagdump);