diff --git a/src/modules/utility.js b/src/modules/utility.js index 59a420f..df0b069 100644 --- a/src/modules/utility.js +++ b/src/modules/utility.js @@ -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] || "") + + ` (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] || "") + - ` (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);