utility: reorganize things code-wise

This commit is contained in:
Cynthia Foxwell 2023-04-09 11:46:48 -06:00
parent 939effc40a
commit 063dd0c3f1
2 changed files with 119 additions and 117 deletions

1
data/emoji.json Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,12 +1,38 @@
const Command = require("../lib/command.js"); const Command = require("../lib/command.js");
const CATEGORY = "utility"; const CATEGORY = "utility";
// imports
const sharp = require("sharp");
const {
hastebin,
lookupUser,
formatTime,
safeString,
} = require("../lib/utils.js");
const {getNamesFromString} = require("../lib/unicode.js");
const GameData = require("../../data/games.json");
const EmojiData = require("../../data/emoji.json");
const EMOJI_NAMES = [];
for (const emoji of EmojiData) {
EMOJI_NAMES[emoji.char] = emoji.name.replace(/ /g, "_");
}
// constants
const ICON_BASE = "https://cdn.discordapp.com/icons/"; const ICON_BASE = "https://cdn.discordapp.com/icons/";
const AVATAR_BASE = "https://cdn.discordapp.com/avatars/"; const AVATAR_BASE = "https://cdn.discordapp.com/avatars/";
const SPLASH_BASE = "https://cdn.discordapp.com/splashes/"; const SPLASH_BASE = "https://cdn.discordapp.com/splashes/";
const BANNER_BASE = "https://cdn.discordapp.com/banners/"; const BANNER_BASE = "https://cdn.discordapp.com/banners/";
const EMOTE_BASE = "https://cdn.discordapp.com/emojis/"; const EMOTE_BASE = "https://cdn.discordapp.com/emojis/";
const CUSTOM_EMOTE_REGEX = /<(?:\u200b|&)?(a)?:(\w+):(\d+)>/;
const NOWPLAYING_BAR_LENGTH = 30;
const STATUS_ICONS = { const STATUS_ICONS = {
online: "<:online:493173082421461002>", online: "<:online:493173082421461002>",
idle: "<:idle:493173082006093836>", idle: "<:idle:493173082006093836>",
@ -14,6 +40,93 @@ const STATUS_ICONS = {
offline: "<:offline:493173082253426688>", offline: "<:offline:493173082253426688>",
}; };
const PRESENCE_ICONS = {
desktop: {
online: "<:desktop_online:1028887024670871552>",
idle: "<:desktop_idle:1028887022938624033>",
dnd: "<:desktop_dnd:1028887021848121364>",
},
mobile: {
online: "<:mobile_online:1028887017637036043>",
idle: "<:mobile_idle:1028887019226669116>",
dnd: "<:mobile_dnd:1028887020560449637>",
},
web: {
online: "<:web_online:1028887016353574962>",
idle: "<:web_idle:1028887014579392592>",
dnd: "<:web_dnd:1028887012855525486>",
},
embedded: {
online: "<:embedded_online:1028887010636726313>",
idle: "<:embedded_idle:1028887009147760681>",
dnd: "<:embedded_dnd:1028887008149516299>",
},
};
const PRESENCE_TYPES = [
"Playing",
"Streaming",
"Listening to",
"Watching",
"",
"Competing in",
];
const USER_FLAGS = [
"STAFF",
"PARTNER",
"HYPESQUAD",
"BUG_HUNTER_LEVEL_1",
"MFA_SMS",
"PREMIUM_PROMO_DISMISSED",
"HYPESQUAD_ONLINE_HOUSE_1",
"HYPESQUAD_ONLINE_HOUSE_2",
"HYPESQUAD_ONLINE_HOUSE_3",
"PREMIUM_EARLY_SUPPORTER",
"TEAM_PSEUDO_USER",
"<Internal Application (Partner, etc) Flag>", // leaked
"SYSTEM",
"HAS_UNREAD_URGENT_MESSAGES",
"BUG_HUNTER_LEVEL_2",
"UNDERAGE_DELETED",
"VERIFIED_BOT",
"VERIFIED_DEVELOPER",
"CERTIFIED_MODERATOR",
"BOT_HTTP_INTERACTIONS",
"SPAMMER",
"DISABLE_PREMIUM",
"ACTIVE_DEVELOPER",
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
"HIGH_GLOBAL_RATE_LIMIT", // start admin panel leak aug 2022
"DELETED",
"DISABLED_SUSPICIOUS_ACTIVITY",
"SELF_DELETED",
"PREMIUM_DISCRIMINATOR",
"USED_DESKTOP_CLIENT",
"USED_WEB_CLIENT",
"USED_MOBILE_CLIENT",
"DISABLED",
undefined,
"VERIFIED_EMAIL", // end admin panel leak aug 2022
"QUARANTINED",
undefined,
undefined,
undefined,
undefined,
undefined,
"COLLABORATOR",
"RESTRICTED_COLLABORATOR",
];
const EMOJI_SETS = { const EMOJI_SETS = {
blobs: { blobs: {
prefix: prefix:
@ -55,19 +168,7 @@ EMOJI_SETS.ms = EMOJI_SETS.mustd;
EMOJI_SETS.twitter = EMOJI_SETS.twemoji; EMOJI_SETS.twitter = EMOJI_SETS.twemoji;
EMOJI_SETS.fb = EMOJI_SETS.facebook; EMOJI_SETS.fb = EMOJI_SETS.facebook;
const CUSTOM_EMOTE_REGEX = /<(?:\u200b|&)?(a)?:(\w+):(\d+)>/; // commands
const sharp = require("sharp");
const {
hastebin,
lookupUser,
formatTime,
safeString,
} = require("../lib/utils.js");
const {getNamesFromString} = require("../lib/unicode.js");
const GameData = require("../../data/games.json");
const avatar = new Command("avatar"); const avatar = new Command("avatar");
avatar.category = CATEGORY; avatar.category = CATEGORY;
@ -466,61 +567,6 @@ snowflake.callback = function (msg, line, [snowflake], {twitter}) {
}; };
hf.registerCommand(snowflake); hf.registerCommand(snowflake);
const USER_FLAGS = [
"STAFF",
"PARTNER",
"HYPESQUAD",
"BUG_HUNTER_LEVEL_1",
"MFA_SMS",
"PREMIUM_PROMO_DISMISSED",
"HYPESQUAD_ONLINE_HOUSE_1",
"HYPESQUAD_ONLINE_HOUSE_2",
"HYPESQUAD_ONLINE_HOUSE_3",
"PREMIUM_EARLY_SUPPORTER",
"TEAM_PSEUDO_USER",
"<Internal Application (Partner, etc) Flag>", // leaked
"SYSTEM",
"HAS_UNREAD_URGENT_MESSAGES",
"BUG_HUNTER_LEVEL_2",
"UNDERAGE_DELETED",
"VERIFIED_BOT",
"VERIFIED_DEVELOPER",
"CERTIFIED_MODERATOR",
"BOT_HTTP_INTERACTIONS",
"SPAMMER",
"DISABLE_PREMIUM",
"ACTIVE_DEVELOPER",
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
"HIGH_GLOBAL_RATE_LIMIT", // start admin panel leak aug 2022
"DELETED",
"DISABLED_SUSPICIOUS_ACTIVITY",
"SELF_DELETED",
"PREMIUM_DISCRIMINATOR",
"USED_DESKTOP_CLIENT",
"USED_WEB_CLIENT",
"USED_MOBILE_CLIENT",
"DISABLED",
undefined,
"VERIFIED_EMAIL", // end admin panel leak aug 2022
"QUARANTINED",
undefined,
undefined,
undefined,
undefined,
undefined,
"COLLABORATOR",
"RESTRICTED_COLLABORATOR",
];
function flagFromInt(int) { function flagFromInt(int) {
const bits = int.toString(2); const bits = int.toString(2);
const splitBits = bits.split("").reverse(); const splitBits = bits.split("").reverse();
@ -580,15 +626,6 @@ flagdump.callback = async function (msg, line, [numOrMention], {id}) {
}; };
hf.registerCommand(flagdump); hf.registerCommand(flagdump);
const emojiNames = [];
fetch("https://unpkg.com/emoji.json/emoji.json")
.then((res) => res.json())
.then((body) =>
body.map(
(emoji) => (emojiNames[emoji.char] = emoji.name.replace(/ /g, "_"))
)
);
const jumbo = new Command("jumbo"); const jumbo = new Command("jumbo");
jumbo.category = CATEGORY; jumbo.category = CATEGORY;
jumbo.helpText = "Gets the raw image of an emoji."; jumbo.helpText = "Gets the raw image of an emoji.";
@ -628,17 +665,15 @@ jumbo.callback = async function (msg, line) {
.join(set.sep); .join(set.sep);
const url = set.prefix + emoji + set.suffix; const url = set.prefix + emoji + set.suffix;
const name = emojiNames[line] const name = EMOJI_NAMES[line]
? `\\:${emojiNames[line]}\\:` ? `\\:${EMOJI_NAMES[line]}\\:`
: await getNamesFromString(line).then((name) => : await getNamesFromString(line).then((name) =>
name.map((x) => x[1]).join(", ") name.map((x) => x[1]).join(", ")
); );
const statusCode = await fetch(url, {method: "HEAD"}).then( const emojiFound = await fetch(url, {method: "HEAD"}).then((res) => res.ok);
(res) => res.status
);
if (statusCode !== 200) { if (emojiFound) {
return "Emoji not found. The emoji set chosen might not have this emote as an image."; return "Emoji not found. The emoji set chosen might not have this emote as an image.";
} }
@ -705,40 +740,6 @@ charinfo.callback = async function (msg, line) {
}; };
hf.registerCommand(charinfo); hf.registerCommand(charinfo);
const PRESENCE_ICONS = {
desktop: {
online: "<:desktop_online:1028887024670871552>",
idle: "<:desktop_idle:1028887022938624033>",
dnd: "<:desktop_dnd:1028887021848121364>",
},
mobile: {
online: "<:mobile_online:1028887017637036043>",
idle: "<:mobile_idle:1028887019226669116>",
dnd: "<:mobile_dnd:1028887020560449637>",
},
web: {
online: "<:web_online:1028887016353574962>",
idle: "<:web_idle:1028887014579392592>",
dnd: "<:web_dnd:1028887012855525486>",
},
embedded: {
online: "<:embedded_online:1028887010636726313>",
idle: "<:embedded_idle:1028887009147760681>",
dnd: "<:embedded_dnd:1028887008149516299>",
},
};
const PRESENCE_TYPES = [
"Playing",
"Streaming",
"Listening to",
"Watching",
"",
"Competing in",
];
const NOWPLAYING_BAR_LENGTH = 30;
const presence = new Command("presence"); const presence = new Command("presence");
presence.category = CATEGORY; presence.category = CATEGORY;
presence.helpText = "Get presences of a user."; presence.helpText = "Get presences of a user.";