utility.flagdump: add --list
This commit is contained in:
parent
682ba22b36
commit
f4f2015fb3
1 changed files with 98 additions and 109 deletions
|
@ -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,14 +174,13 @@ 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: [
|
||||
|
@ -251,9 +250,9 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
|
|||
(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),
|
||||
|
@ -296,9 +295,9 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
|
|||
(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,8 +321,7 @@ 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,8 +356,7 @@ 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.";
|
||||
}
|
||||
|
@ -451,13 +448,11 @@ lookupinvite.callback = async function (msg, line) {
|
|||
},
|
||||
invite.guild.welcome_screen && {
|
||||
name: "Welcome Screen",
|
||||
value: `"${
|
||||
invite.guild.welcome_screen.description
|
||||
value: `"${invite.guild.welcome_screen.description
|
||||
}"\n${invite.guild.welcome_screen.welcome_channels
|
||||
.map(
|
||||
(c) =>
|
||||
`${
|
||||
c.emoji_id
|
||||
`${c.emoji_id
|
||||
? `[:${c.emoji_name}:](${EMOTE_BASE}${c.emoji_id}.webp)`
|
||||
: c.emoji_name
|
||||
} ${c.description} \`(${c.channel_id})\``
|
||||
|
@ -484,8 +479,7 @@ lookupinvite.callback = async function (msg, line) {
|
|||
thumbnail: {
|
||||
url:
|
||||
invite.guild.icon &&
|
||||
`${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${
|
||||
invite.guild.icon.startsWith("a_")
|
||||
`${ICON_BASE}${invite.guild.id}/${invite.guild.icon}.${invite.guild.icon.startsWith("a_")
|
||||
? "gif?size=1024&_=.gif"
|
||||
: "png?size=1024"
|
||||
}`,
|
||||
|
@ -503,28 +497,20 @@ 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_")
|
||||
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
|
||||
? `${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_")
|
||||
}${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"
|
||||
})`
|
||||
|
@ -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,15 +605,13 @@ flagdump.callback = async function (msg, line, [numOrMention], {id}) {
|
|||
if (!user) {
|
||||
return "User not cached.";
|
||||
} else {
|
||||
return `\`${user.username}#${
|
||||
user.discriminator
|
||||
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
|
||||
return `\`${msg.author.username}#${msg.author.discriminator
|
||||
}\`'s public flags:\n\`\`\`${flagFromInt(msg.author.publicFlags)}\`\`\``;
|
||||
}
|
||||
};
|
||||
|
@ -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";
|
||||
|
@ -671,7 +662,7 @@ jumbo.callback = async function (msg, line) {
|
|||
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,8 +788,7 @@ 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,
|
||||
|
@ -995,8 +985,7 @@ presence.callback = async function (msg, line) {
|
|||
}
|
||||
|
||||
return {
|
||||
content: `Presence for **${target.username}#${
|
||||
target.discriminator
|
||||
content: `Presence for **${target.username}#${target.discriminator
|
||||
}**: ${icons.trim()}`,
|
||||
embeds,
|
||||
files,
|
||||
|
|
Loading…
Reference in a new issue