utility.flagdump: add mention lookup

This commit is contained in:
Cynthia Foxwell 2021-06-21 22:35:04 -06:00
parent 7b0e6fbc31
commit 575c2a3047

View file

@ -259,38 +259,59 @@ const USER_FLAGS = [
"CERTIFIED_MODERATOR", "CERTIFIED_MODERATOR",
]; ];
function flagFromInt(int) {
const bits = int.toString(2);
const splitBits = bits.split("").reverse();
const reassignedBits = {};
for (const shift in splitBits) {
reassignedBits[shift] = splitBits[shift];
}
const flags = Object.keys(reassignedBits).filter(
(bit) => reassignedBits[bit] == 1
);
let out = "";
for (const flag of flags) {
out +=
(USER_FLAGS[flag] || "<Undocumented Flag>") +
` (1 << ${flag}, ${1n << BigInt(flag)})\n`;
}
return out;
}
const flagdump = new Command("flagdump"); const flagdump = new Command("flagdump");
flagdump.category = CATEGORY; flagdump.category = CATEGORY;
flagdump.helpText = "Dumps Discord user flags."; flagdump.helpText = "Dumps Discord user flags.";
flagdump.usage = "[flags]"; flagdump.usage = "[flags or user mention]";
flagdump.callback = function (msg, line) { flagdump.callback = async function (msg, line) {
const num = parseInt(line); const num = parseInt(line);
if (!isNaN(num)) { if (/<@!?([0-9]*)>/.test(line)) {
const bits = num.toString(2); const id = line.match(/<@?!([0-9]*)>/)[1];
const splitBits = bits.split("").reverse(); let user = await msg.channel.guild.fetchMembers({userIDs: [id]});
if (!user[0]) {
const reassignedBits = {}; user = hf.bot.users.get(id);
} else {
for (const shift in splitBits) { user = user[0].user;
reassignedBits[shift] = splitBits[shift];
} }
const flags = Object.keys(reassignedBits).filter( if (!user) {
(bit) => reassignedBits[bit] == 1 return "User not cached.";
); } else {
return `\`${user.username}#${
let out = "```\n"; user.discriminator
}\`'s public flags:\n\`\`\`${flagFromInt(user.publicFlags)}\`\`\``;
for (const flag of flags) {
out +=
(USER_FLAGS[flag] || "<Undocumented Flag>") +
` (1 << ${flag}, ${1n << BigInt(flag)})\n`;
} }
out += "```"; } else if (!isNaN(num)) {
return `\`\`\`\n${flagFromInt(num)}\`\`\``;
return out;
} else { } else {
return "Argument provided is not a number."; return `\`${msg.author.username}#${
msg.author.discriminator
}\`'s public flags:\n\`\`\`${flagFromInt(msg.author.publicFlags)}\`\`\``;
} }
}; };
hf.registerCommand(flagdump); hf.registerCommand(flagdump);