utility.flagdump: add mention lookup
This commit is contained in:
parent
7b0e6fbc31
commit
575c2a3047
1 changed files with 45 additions and 24 deletions
|
@ -259,14 +259,8 @@ const USER_FLAGS = [
|
|||
"CERTIFIED_MODERATOR",
|
||||
];
|
||||
|
||||
const flagdump = new Command("flagdump");
|
||||
flagdump.category = CATEGORY;
|
||||
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);
|
||||
function flagFromInt(int) {
|
||||
const bits = int.toString(2);
|
||||
const splitBits = bits.split("").reverse();
|
||||
|
||||
const reassignedBits = {};
|
||||
|
@ -279,18 +273,45 @@ flagdump.callback = function (msg, line) {
|
|||
(bit) => reassignedBits[bit] == 1
|
||||
);
|
||||
|
||||
let out = "```\n";
|
||||
let out = "";
|
||||
|
||||
for (const flag of flags) {
|
||||
out +=
|
||||
(USER_FLAGS[flag] || "<Undocumented Flag>") +
|
||||
` (1 << ${flag}, ${1n << BigInt(flag)})\n`;
|
||||
}
|
||||
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 {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue