flagdump: hopefully fix --id

This commit is contained in:
Cynthia Foxwell 2024-08-18 15:07:26 -06:00
parent ff6a382591
commit 042f42e02e

View file

@ -14,6 +14,8 @@ for (const set of _UserFlags) {
} }
const UserFlagsMapped = Object.fromEntries(_UserFlags.map((x) => x.reverse())); const UserFlagsMapped = Object.fromEntries(_UserFlags.map((x) => x.reverse()));
const REGEX_MENTION = /<@!?(\d+)>/;
const flagdump = new Command("flagdump"); const flagdump = new Command("flagdump");
flagdump.category = "utility"; flagdump.category = "utility";
flagdump.helpText = "Dumps Discord user flags."; flagdump.helpText = "Dumps Discord user flags.";
@ -34,26 +36,29 @@ flagdump.callback = async function (msg, line, [numOrMention], {id, list}) {
if (UserFlagsMapped[index] == undefined) continue; if (UserFlagsMapped[index] == undefined) continue;
allFlags += 1n << BigInt(index); allFlags += 1n << BigInt(index);
} }
out = `All flags:\n\`\`\`${flagsFromInt(allFlags, UserFlagsMapped)}\`\`\``; out = `All flags:\n\`\`\`\n${flagsFromInt(allFlags, UserFlagsMapped)}\`\`\``;
} else if (/<@!?(\d+)>/.test(numOrMention) || SNOWFLAKE_REGEX.test(id)) { } else if (REGEX_MENTION.test(numOrMention) || SNOWFLAKE_REGEX.test(id)) {
const targetId = id ?? numOrMention.match(/<@!?(\d+)>/)?.[1]; const targetId = id ?? numOrMention.match(REGEX_MENTION)?.[1];
if (!targetId) return "Got null ID."; if (!targetId) return "Got null ID.";
let user = hf.bot.users.get(targetId); let user;
try {
if (!user) user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(targetId), true).catch(() => {}); user = await hf.bot.requestHandler.request("GET", APIEndpoints.USER(targetId), true);
} catch (err) {
if (err.code == 10013) return "Unknown user";
}
if (!user) { if (!user) {
out = "Failed to get user."; out = "Failed to get user.";
} else { } else {
out = `\`${formatUsername(user)}\`'s public flags:\n\`\`\`${flagsFromInt( out = `\`${formatUsername(user)}\`'s public flags:\n\`\`\`\n${flagsFromInt(
user.public_flags ?? user.publicFlags, user.public_flags,
UserFlagsMapped UserFlagsMapped
)}\`\`\``; )}\`\`\``;
} }
} else if (!Number.isNaN(num)) { } else if (!Number.isNaN(num)) {
out = `\`\`\`\n${flagsFromInt(num, UserFlagsMapped)}\`\`\``; out = `\`\`\`\n${flagsFromInt(num, UserFlagsMapped)}\`\`\``;
} else { } else {
out = `\`${formatUsername(msg.author)}\`'s public flags:\n\`\`\`${flagsFromInt( out = `\`${formatUsername(msg.author)}\`'s public flags:\n\`\`\`\n${flagsFromInt(
msg.author.publicFlags, msg.author.publicFlags,
UserFlagsMapped UserFlagsMapped
)}\`\`\``; )}\`\`\``;