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