utility.flagdump: add --list

This commit is contained in:
Cynthia Foxwell 2023-05-27 11:35:59 -06:00
parent 682ba22b36
commit f4f2015fb3

View file

@ -11,7 +11,7 @@ const {
formatTime,
safeString,
} = require("../lib/utils.js");
const {getNamesFromString} = require("../lib/unicode.js");
const { getNamesFromString } = require("../lib/unicode.js");
const GameData = require("../../data/games.json");
@ -174,15 +174,14 @@ const avatar = new Command("avatar");
avatar.category = CATEGORY;
avatar.helpText = "Get avatar of a user";
avatar.usage = "<user>";
avatar.callback = async function (msg, line, [user], {server, guild}) {
avatar.callback = async function(msg, line, [user], { server, guild }) {
if (server || guild) {
if (!msg.guildID) {
return "`--server/--guild` can only be used within guilds.";
} else {
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
const url = `${ICON_BASE}${guild.id}/${guild.icon}.${
guild.icon.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
const url = `${ICON_BASE}${guild.id}/${guild.icon}.${guild.icon.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
return {
embeds: [
{
@ -236,24 +235,24 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
const guildUrl =
guildAvatar &&
"https://cdn.discordapp.com/guilds/" +
guild.id +
"/users/" +
member.id +
"/avatars/" +
guildAvatar +
"." +
(guildAvatar.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024");
guild.id +
"/users/" +
member.id +
"/avatars/" +
guildAvatar +
"." +
(guildAvatar.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024");
baseEmbed.description =
`[Normal avatar](${normalUrl})` +
(guild && guildAvatar ? `\n[Guild avatar](${guildUrl})` : "");
baseEmbed.url = normalUrl;
const guildEmbed = {...baseEmbed};
baseEmbed.image = {url: normalUrl};
guildEmbed.image = {url: guildUrl};
const guildEmbed = { ...baseEmbed };
baseEmbed.image = { url: normalUrl };
guildEmbed.image = { url: guildUrl };
return {
embeds: [baseEmbed, guildAvatar && guildEmbed].filter((x) => x != null),
@ -281,24 +280,24 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
const guildUrl =
guildAvatar &&
"https://cdn.discordapp.com/guilds/" +
guild.id +
"/users/" +
msg.author.id +
"/avatars/" +
guildAvatar +
"." +
(guildAvatar.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024");
guild.id +
"/users/" +
msg.author.id +
"/avatars/" +
guildAvatar +
"." +
(guildAvatar.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024");
baseEmbed.description =
`[Normal avatar](${normalUrl})` +
(guild && guildAvatar ? `\n[Guild avatar](${guildUrl})` : "");
baseEmbed.url = normalUrl;
const guildEmbed = {...baseEmbed};
baseEmbed.image = {url: normalUrl};
guildEmbed.image = {url: guildUrl};
const guildEmbed = { ...baseEmbed };
baseEmbed.image = { url: normalUrl };
guildEmbed.image = { url: guildUrl };
return {
embeds: [baseEmbed, guildAvatar && guildEmbed].filter((x) => x != null),
@ -311,7 +310,7 @@ const banner = new Command("banner");
banner.category = CATEGORY;
banner.helpText = "Get banner of a user";
banner.usage = "<user>";
banner.callback = async function (msg, line, [user], {server, guild}) {
banner.callback = async function(msg, line, [user], { server, guild }) {
let id = msg.author.id;
if (server || guild) {
@ -322,9 +321,8 @@ banner.callback = async function (msg, line, [user], {server, guild}) {
if (!guild.banner) return "This guild does not have a banner.";
const url = `${BANNER_BASE}${guild.id}/${guild.banner}.${
guild.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
const url = `${BANNER_BASE}${guild.id}/${guild.banner}.${guild.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
return {
embeds: [
{
@ -358,9 +356,8 @@ banner.callback = async function (msg, line, [user], {server, guild}) {
if (!userObj.banner) return "This user does not have a banner.";
const url = `${BANNER_BASE}${userObj.id}/${userObj.banner}.${
userObj.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
const url = `${BANNER_BASE}${userObj.id}/${userObj.banner}.${userObj.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
return {
embeds: [
{
@ -380,7 +377,7 @@ lookupinvite.category = CATEGORY;
lookupinvite.helpText = "Lookup an invite";
lookupinvite.usage = "<invite code>";
lookupinvite.addAlias("linvite");
lookupinvite.callback = async function (msg, line) {
lookupinvite.callback = async function(msg, line) {
if (!line || line == "") {
return "No arguments passed.";
}
@ -445,24 +442,22 @@ lookupinvite.callback = async function (msg, line) {
invite.expires_at == null
? "Never"
: `<t:${Math.floor(
new Date(invite.expires_at).getTime() / 1000
)}>`,
new Date(invite.expires_at).getTime() / 1000
)}>`,
inline: true,
},
invite.guild.welcome_screen && {
name: "Welcome Screen",
value: `"${
invite.guild.welcome_screen.description
}"\n${invite.guild.welcome_screen.welcome_channels
.map(
(c) =>
`${
c.emoji_id
value: `"${invite.guild.welcome_screen.description
}"\n${invite.guild.welcome_screen.welcome_channels
.map(
(c) =>
`${c.emoji_id
? `[:${c.emoji_name}:](${EMOTE_BASE}${c.emoji_id}.webp)`
: c.emoji_name
} ${c.description} \`(${c.channel_id})\``
)
.join("\n")}`,
} ${c.description} \`(${c.channel_id})\``
)
.join("\n")}`,
inline: false,
},
{
@ -470,13 +465,13 @@ lookupinvite.callback = async function (msg, line) {
value:
invite.guild.features.length > 0
? invite.guild.features
.map((feature) =>
feature
.split("_")
.map((x) => x[0] + x.substring(1).toLowerCase())
.join(" ")
)
.join(", ")
.map((feature) =>
feature
.split("_")
.map((x) => x[0] + x.substring(1).toLowerCase())
.join(" ")
)
.join(", ")
: "None",
inline: false,
},
@ -484,10 +479,9 @@ lookupinvite.callback = async function (msg, line) {
thumbnail: {
url:
invite.guild.icon &&
`${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${
invite.guild.icon.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024"
`${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${invite.guild.icon.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024"
}`,
},
};
@ -503,33 +497,25 @@ lookupinvite.callback = async function (msg, line) {
if (invite.guild.icon || invite.guild.splash || invite.guild.banner) {
embed.fields.push({
name: "\u200b",
value: `${
invite.guild.icon
? `[Icon](${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${
invite.guild.icon.startsWith("a_")
? "gif?size=1024"
: "png?size=1024"
})`
value: `${invite.guild.icon
? `[Icon](${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${invite.guild.icon.startsWith("a_")
? "gif?size=1024"
: "png?size=1024"
})`
: ""
}${invite.guild.splash
? `${invite.guild.icon ? " | " : ""}[Splash](${SPLASH_BASE}${invite.guild.id
}/${invite.guild.splash}.png?size=2048)`
: ""
}${
invite.guild.splash
? `${invite.guild.icon ? " | " : ""}[Splash](${SPLASH_BASE}${
invite.guild.id
}/${invite.guild.splash}.png?size=2048)`
}${invite.guild.banner
? `${invite.guild.icon || invite.guild.splash ? " | " : ""
}[Banner](${BANNER_BASE}${invite.guild.id}/${invite.guild.banner
}.${invite.guild.banner.startsWith("a_")
? "gif?size=1024"
: "png?size=1024"
})`
: ""
}${
invite.guild.banner
? `${
invite.guild.icon || invite.guild.splash ? " | " : ""
}[Banner](${BANNER_BASE}${invite.guild.id}/${
invite.guild.banner
}.${
invite.guild.banner.startsWith("a_")
? "gif?size=1024"
: "png?size=1024"
})`
: ""
}`,
}`,
inline: false,
});
}
@ -540,7 +526,7 @@ lookupinvite.callback = async function (msg, line) {
};
}
return {embed};
return { embed };
}
};
hf.registerCommand(lookupinvite);
@ -549,7 +535,7 @@ const snowflake = new Command("snowflake");
snowflake.category = CATEGORY;
snowflake.helpText = "Converts a snowflake ID into readable time.";
snowflake.usage = "<--twitter> [snowflake]";
snowflake.callback = function (msg, line, [snowflake], {twitter}) {
snowflake.callback = function(msg, line, [snowflake], { twitter }) {
const num = parseInt(snowflake);
if (!isNaN(num)) {
let binary = num.toString(2);
@ -596,13 +582,20 @@ 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, [numOrMention], {id}) {
flagdump.callback = async function(msg, line, [numOrMention], { id, list }) {
const num = Number(numOrMention);
if (/<@!?(\d+)>/.test(numOrMention) || !isNaN(id)) {
if (list) {
let allFlags = 0n;
for (const index in USER_FLAGS) {
if (USER_FLAGS[index] == undefined) continue;
allFlags += 1n << BigInt(index);
}
return `All flags:\n\`\`\`${flagFromInt(allFlags)}\`\`\``;
} else if (/<@!?(\d+)>/.test(numOrMention) || !isNaN(id)) {
const targetId = id || numOrMention.match(/<@!?(\d+)>/)?.[1];
if (!targetId) return "Got null ID.";
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
let user = guild && (await guild.fetchMembers({userIDs: [targetId]}));
let user = guild && (await guild.fetchMembers({ userIDs: [targetId] }));
if (!user || !user[0]) {
user = hf.bot.users.get(id);
} else {
@ -612,16 +605,14 @@ flagdump.callback = async function (msg, line, [numOrMention], {id}) {
if (!user) {
return "User not cached.";
} else {
return `\`${user.username}#${
user.discriminator
}\`'s public flags:\n\`\`\`${flagFromInt(user.publicFlags)}\`\`\``;
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)}\`\`\``;
return `\`${msg.author.username}#${msg.author.discriminator
}\`'s public flags:\n\`\`\`${flagFromInt(msg.author.publicFlags)}\`\`\``;
}
};
hf.registerCommand(flagdump);
@ -633,7 +624,7 @@ jumbo.usage = "<emoji>";
jumbo.addAlias("e");
jumbo.addAlias("emote");
jumbo.addAlias("emoji");
jumbo.callback = async function (msg, line) {
jumbo.callback = async function(msg, line) {
if (CUSTOM_EMOTE_REGEX.test(line)) {
const [_, animatedFlag, name, id] = line.match(CUSTOM_EMOTE_REGEX);
const animated = animatedFlag === "a";
@ -668,10 +659,10 @@ jumbo.callback = async function (msg, line) {
const name = EMOJI_NAMES[line]
? `\\:${EMOJI_NAMES[line]}\\:`
: await getNamesFromString(line).then((name) =>
name.map((x) => x[1]).join(", ")
);
name.map((x) => x[1]).join(", ")
);
const emojiFound = await fetch(url, {method: "HEAD"}).then((res) => res.ok);
const emojiFound = await fetch(url, { method: "HEAD" }).then((res) => res.ok);
if (emojiFound) {
return "Emoji not found. The emoji set chosen might not have this emote as an image.";
@ -681,7 +672,7 @@ jumbo.callback = async function (msg, line) {
const svg = await fetch(url)
.then((res) => res.arrayBuffer())
.then((b) => Buffer.from(b));
const converted = await sharp(svg, {density: 2400})
const converted = await sharp(svg, { density: 2400 })
.resize(1024)
.toBuffer();
@ -722,7 +713,7 @@ charinfo.category = CATEGORY;
charinfo.helpText = "Get information about a set of characters.";
charinfo.usage = "[characters]";
charinfo.addAlias("char");
charinfo.callback = async function (msg, line) {
charinfo.callback = async function(msg, line) {
const names = await getNamesFromString(line);
const chars = [...line];
const lines = names
@ -745,7 +736,7 @@ presence.category = CATEGORY;
presence.helpText = "Get presences of a user.";
presence.usage = "<user>";
presence.addAlias("status");
presence.callback = async function (msg, line) {
presence.callback = async function(msg, line) {
if (!msg.guildID) return "Can only be used in guilds.";
let target;
@ -797,9 +788,8 @@ presence.callback = async function (msg, line) {
if (activity.emoji) {
if (activity.emoji.id) {
const url = `${EMOTE_BASE}${activity.emoji.id}.${
activity.emoji.animated ? "gif" : "png"
}`;
const url = `${EMOTE_BASE}${activity.emoji.id}.${activity.emoji.animated ? "gif" : "png"
}`;
embed.author = {
url,
icon_url: url,
@ -995,9 +985,8 @@ presence.callback = async function (msg, line) {
}
return {
content: `Presence for **${target.username}#${
target.discriminator
}**: ${icons.trim()}`,
content: `Presence for **${target.username}#${target.discriminator
}**: ${icons.trim()}`,
embeds,
files,
};