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,14 +259,8 @@ const USER_FLAGS = [
"CERTIFIED_MODERATOR", "CERTIFIED_MODERATOR",
]; ];
const flagdump = new Command("flagdump"); function flagFromInt(int) {
flagdump.category = CATEGORY; const bits = int.toString(2);
flagdump.helpText = "Dumps Discord user flags.";
flagdump.usage = "[flags]";
flagdump.callback = function (msg, line) {
const num = parseInt(line);
if (!isNaN(num)) {
const bits = num.toString(2);
const splitBits = bits.split("").reverse(); const splitBits = bits.split("").reverse();
const reassignedBits = {}; const reassignedBits = {};
@ -279,18 +273,45 @@ flagdump.callback = function (msg, line) {
(bit) => reassignedBits[bit] == 1 (bit) => reassignedBits[bit] == 1
); );
let out = "```\n"; let out = "";
for (const flag of flags) { for (const flag of flags) {
out += out +=
(USER_FLAGS[flag] || "<Undocumented Flag>") + (USER_FLAGS[flag] || "<Undocumented Flag>") +
` (1 << ${flag}, ${1n << BigInt(flag)})\n`; ` (1 << ${flag}, ${1n << BigInt(flag)})\n`;
} }
out += "```";
return out; return out;
}
const flagdump = new Command("flagdump");
flagdump.category = CATEGORY;
flagdump.helpText = "Dumps Discord user flags.";
flagdump.usage = "[flags or user mention]";
flagdump.callback = async function (msg, line) {
const num = parseInt(line);
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 { } else {
return "Argument provided is not a number."; user = user[0].user;
}
if (!user) {
return "User not cached.";
} else {
return `\`${user.username}#${
user.discriminator
}\`'s public flags:\n\`\`\`${flagFromInt(user.publicFlags)}\`\`\``;
}
} else if (!isNaN(num)) {
return `\`\`\`\n${flagFromInt(num)}\`\`\``;
} else {
return `\`${msg.author.username}#${
msg.author.discriminator
}\`'s public flags:\n\`\`\`${flagFromInt(msg.author.publicFlags)}\`\`\``;
} }
}; };
hf.registerCommand(flagdump); hf.registerCommand(flagdump);