path aliases

This commit is contained in:
Cynthia Foxwell 2024-08-13 13:34:31 -06:00
parent eedfc2e5bb
commit c7b3f34b4e
46 changed files with 253 additions and 286 deletions

View file

@ -24,6 +24,7 @@
"dumpy": "github:Cynosphere/dumpy.js", "dumpy": "github:Cynosphere/dumpy.js",
"google-images": "^2.1.0", "google-images": "^2.1.0",
"jimp": "^0.22.7", "jimp": "^0.22.7",
"module-alias": "^2.2.3",
"murmurhash": "^2.0.1", "murmurhash": "^2.0.1",
"node-ffprobe": "^3.0.0", "node-ffprobe": "^3.0.0",
"sharp": "^0.32.0", "sharp": "^0.32.0",
@ -34,5 +35,11 @@
"eslint": "^8.39.0", "eslint": "^8.39.0",
"husky": "^8.0.3", "husky": "^8.0.3",
"prettier": "^2.8.8" "prettier": "^2.8.8"
},
"_moduleAliases": {
"@": ".",
"@lib": "src/lib",
"@util": "src/util",
"@modules": "src/modules"
} }
} }

View file

@ -16,7 +16,7 @@ importers:
version: 1.7.0 version: 1.7.0
'@projectdysnomia/dysnomia': '@projectdysnomia/dysnomia':
specifier: github:projectdysnomia/dysnomia#dev specifier: github:projectdysnomia/dysnomia#dev
version: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/8e50eed921acbbcfde7bbdab7a03cd6c62e788c2 version: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/909d67a5f5c9ec38abf04ade5bfb8f3d77988388
dumpy: dumpy:
specifier: github:Cynosphere/dumpy.js specifier: github:Cynosphere/dumpy.js
version: https://codeload.github.com/Cynosphere/dumpy.js/tar.gz/5fc22353cdcb97084bab572266390e780d9f7a7b(encoding@0.1.13) version: https://codeload.github.com/Cynosphere/dumpy.js/tar.gz/5fc22353cdcb97084bab572266390e780d9f7a7b(encoding@0.1.13)
@ -26,6 +26,9 @@ importers:
jimp: jimp:
specifier: ^0.22.7 specifier: ^0.22.7
version: 0.22.7(encoding@0.1.13) version: 0.22.7(encoding@0.1.13)
module-alias:
specifier: ^2.2.3
version: 2.2.3
murmurhash: murmurhash:
specifier: ^2.0.1 specifier: ^2.0.1
version: 2.0.1 version: 2.0.1
@ -452,17 +455,17 @@ packages:
resolution: {integrity: sha512-aGQIwo6/sWtyyqhVK4e1MtxYz4N1X8CNt6SOtCc+Wnczs5S5ONaLHDDR8LYaGn0MgOwvGgXyuZ5sJIfd7iyoUw==} resolution: {integrity: sha512-aGQIwo6/sWtyyqhVK4e1MtxYz4N1X8CNt6SOtCc+Wnczs5S5ONaLHDDR8LYaGn0MgOwvGgXyuZ5sJIfd7iyoUw==}
engines: {node: '>=0.10'} engines: {node: '>=0.10'}
'@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/8e50eed921acbbcfde7bbdab7a03cd6c62e788c2': '@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/909d67a5f5c9ec38abf04ade5bfb8f3d77988388':
resolution: {tarball: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/8e50eed921acbbcfde7bbdab7a03cd6c62e788c2} resolution: {tarball: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/909d67a5f5c9ec38abf04ade5bfb8f3d77988388}
version: 0.2.0-dev version: 0.2.0-dev
engines: {node: '>=18.0.0'} engines: {node: '>=18.0.0'}
peerDependencies: peerDependencies:
'@discordjs/opus': ^0.9.0 '@discordjs/opus': ^0.9.0
erlpack: github:discord/erlpack || github:abalabahaha/erlpack erlpack: github:discord/erlpack || github:abalabahaha/erlpack
eventemitter3: ^5.0.0 eventemitter3: ^5.0.1
pako: ^2.1.0 pako: ^2.1.0
sodium-native: ^4.0.1 sodium-native: ^4.1.1
zlib-sync: ^0.1.8 zlib-sync: ^0.1.9
peerDependenciesMeta: peerDependenciesMeta:
'@discordjs/opus': '@discordjs/opus':
optional: true optional: true
@ -1097,6 +1100,9 @@ packages:
engines: {node: '>=10'} engines: {node: '>=10'}
hasBin: true hasBin: true
module-alias@2.2.3:
resolution: {integrity: sha512-23g5BFj4zdQL/b6tor7Ji+QY4pEfNH784BMslY9Qb0UnJWRAt+lQGLYmRaM0KDBwIG23ffEBELhZDP2rhi9f/Q==}
ms@2.1.2: ms@2.1.2:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
@ -1170,8 +1176,8 @@ packages:
resolution: {integrity: sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==} resolution: {integrity: sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==}
engines: {node: '>= 0.8.0'} engines: {node: '>= 0.8.0'}
opusscript@0.0.8: opusscript@0.1.1:
resolution: {integrity: sha512-VSTi1aWFuCkRCVq+tx/BQ5q9fMnQ9pVZ3JU4UHKqTkf0ED3fKEPdr+gKAAl3IA2hj9rrP6iyq3hlcJq3HELtNQ==} resolution: {integrity: sha512-mL0fZZOUnXdZ78woRXp18lApwpp0lF5tozJOD1Wut0dgrA9WuQTgSels/CSmFleaAZrJi/nci5KOVtbuxeWoQA==}
p-limit@3.1.0: p-limit@3.1.0:
resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==} resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==}
@ -1514,8 +1520,8 @@ packages:
wrappy@1.0.2: wrappy@1.0.2:
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
ws@8.13.0: ws@8.18.0:
resolution: {integrity: sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==} resolution: {integrity: sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==}
engines: {node: '>=10.0.0'} engines: {node: '>=10.0.0'}
peerDependencies: peerDependencies:
bufferutil: ^4.0.1 bufferutil: ^4.0.1
@ -2096,11 +2102,11 @@ snapshots:
jsprim: 1.4.2 jsprim: 1.4.2
sshpk: 1.17.0 sshpk: 1.17.0
'@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/8e50eed921acbbcfde7bbdab7a03cd6c62e788c2': '@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/909d67a5f5c9ec38abf04ade5bfb8f3d77988388':
dependencies: dependencies:
ws: 8.13.0 ws: 8.18.0
optionalDependencies: optionalDependencies:
opusscript: 0.0.8 opusscript: 0.1.1
tweetnacl: 1.0.3 tweetnacl: 1.0.3
transitivePeerDependencies: transitivePeerDependencies:
- bufferutil - bufferutil
@ -2824,6 +2830,8 @@ snapshots:
mkdirp@2.1.6: {} mkdirp@2.1.6: {}
module-alias@2.2.3: {}
ms@2.1.2: {} ms@2.1.2: {}
ms@2.1.3: ms@2.1.3:
@ -2907,7 +2915,7 @@ snapshots:
type-check: 0.4.0 type-check: 0.4.0
word-wrap: 1.2.3 word-wrap: 1.2.3
opusscript@0.0.8: opusscript@0.1.1:
optional: true optional: true
p-limit@3.1.0: p-limit@3.1.0:
@ -3265,7 +3273,7 @@ snapshots:
wrappy@1.0.2: {} wrappy@1.0.2: {}
ws@8.13.0: {} ws@8.18.0: {}
xhr@2.6.0: xhr@2.6.0:
dependencies: dependencies:

View file

@ -1,19 +1,20 @@
require("module-alias/register");
const {Client, Collection, Channel, Permission} = require("@projectdysnomia/dysnomia"); const {Client, Collection, Channel, Permission} = require("@projectdysnomia/dysnomia");
const fs = require("node:fs"); const fs = require("node:fs");
const {resolve} = require("node:path"); const {resolve} = require("node:path");
const sqlite3 = require("sqlite3"); const sqlite3 = require("sqlite3");
const {instead, before} = require("spitroast"); const {instead, before} = require("spitroast");
const config = require("../config.json"); const config = require("@/config.json");
const apikeys = require("../apikeys.json"); const apikeys = require("@/apikeys.json");
const logger = require("./lib/logger.js"); const logger = require("@lib/logger.js");
const events = require("./lib/events.js"); const events = require("@lib/events.js");
const timer = require("./lib/timer.js"); const timer = require("@lib/timer.js");
const Command = require("./lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("./lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const {APIEndpoints, Intents, ApplicationCommandTypes, GatewayOPCodes} = require("./util/dconstants.js"); const {APIEndpoints, Intents, ApplicationCommandTypes, GatewayOPCodes} = require("@util/dconstants.js");
const bot = new Client(config.token, { const bot = new Client(config.token, {
defaultImageFormat: "png", defaultImageFormat: "png",
@ -55,14 +56,14 @@ global.hf = {
database, database,
}; };
const {formatUsername} = require("./util/misc.js"); const {formatUsername} = require("@util/misc.js");
const CommandDispatcher = require("./lib/commandDispatcher.js"); const CommandDispatcher = require("@lib/commandDispatcher.js");
const {InteractionDispatcher} = require("./lib/interactionDispatcher.js"); const {InteractionDispatcher} = require("@lib/interactionDispatcher.js");
const {hasFlag} = require("./lib/guildSettings.js"); const {hasFlag} = require("@lib/guildSettings.js");
for (const file of fs.readdirSync(resolve(__dirname, "modules"))) { for (const file of fs.readdirSync(resolve(__dirname, "modules"))) {
try { try {
require(resolve(__dirname, "modules", file)); require(`@modules/${file}`);
logger.info("hf:modules", `Loaded module: "${file}"`); logger.info("hf:modules", `Loaded module: "${file}"`);
} catch (err) { } catch (err) {
logger.error("hf:modules", `Failed to load "${file}": ${err}`); logger.error("hf:modules", `Failed to load "${file}": ${err}`);
@ -158,45 +159,47 @@ bot.once("ready", async () => {
logger.info("hf:main", "Reconnected to Discord."); logger.info("hf:main", "Reconnected to Discord.");
}); });
const commands = []; if (!config.no_commands) {
for (const command of interactionCommands.values()) { const commands = [];
const options = []; for (const command of interactionCommands.values()) {
for (const option of Object.values(command.options)) { const options = [];
const newOption = Object.assign({}, option); for (const option of Object.values(command.options)) {
delete newOption.default; const newOption = Object.assign({}, option);
options.push(newOption); delete newOption.default;
options.push(newOption);
}
// stupid hack
const send = options.shift();
options.push(send);
const formattedCommand = {
name: command.name,
type: command.type,
description: command.helpText,
options: options,
integration_types: [0],
contexts: [0],
};
if (!command.guildOnly) {
formattedCommand.integration_types.push(1);
formattedCommand.contexts.push(1, 2);
}
if (command.type === ApplicationCommandTypes.CHAT_INPUT)
formattedCommand.name = formattedCommand.name.toLowerCase();
if (command.permissions !== undefined) {
formattedCommand.default_member_permissions =
command.permissions instanceof Permission ? String(command.permissions.allow) : String(command.permissions);
}
commands.push(formattedCommand);
} }
// stupid hack await bot.requestHandler.request("PUT", APIEndpoints.COMMANDS(bot.application.id), true, commands);
const send = options.shift();
options.push(send);
const formattedCommand = {
name: command.name,
type: command.type,
description: command.helpText,
options: options,
integration_types: [0],
contexts: [0],
};
if (!command.guildOnly) {
formattedCommand.integration_types.push(1);
formattedCommand.contexts.push(1, 2);
}
if (command.type === ApplicationCommandTypes.CHAT_INPUT)
formattedCommand.name = formattedCommand.name.toLowerCase();
if (command.permissions !== undefined) {
formattedCommand.default_member_permissions =
command.permissions instanceof Permission ? String(command.permissions.allow) : String(command.permissions);
}
commands.push(formattedCommand);
} }
await bot.requestHandler.request("PUT", APIEndpoints.COMMANDS(bot.application.id), true, commands);
}); });
bot.on("error", (err) => { bot.on("error", (err) => {

View file

@ -1,12 +1,12 @@
const Command = require("../lib/command.js"); const Command = require("@lib/command.js");
const CATEGORY = "bot"; const CATEGORY = "bot";
const logger = require("../lib/logger.js"); const logger = require("@lib/logger.js");
const child_process = require("child_process"); const guildSettings = require("@lib/guildSettings.js");
const {inspect} = require("util");
const {resolve} = require("path");
const guildSettings = require("../lib/guildSettings.js"); const child_process = require("node:child_process");
const {inspect} = require("node:util");
const {resolve} = require("node:path");
function spawn(args) { function spawn(args) {
const shell = process.env.SHELL || (process.platform == "win32" ? "pwsh" : "sh"); const shell = process.env.SHELL || (process.platform == "win32" ? "pwsh" : "sh");
@ -46,7 +46,7 @@ reload.category = CATEGORY;
reload.helpText = "Reloads a module."; reload.helpText = "Reloads a module.";
reload.callback = function (msg, line) { reload.callback = function (msg, line) {
try { try {
require.resolve(`./${line}.js`); require.resolve(`@modules/${line}.js`);
} catch (err) { } catch (err) {
if (err.code == "MODULE_NOT_FOUND") { if (err.code == "MODULE_NOT_FOUND") {
return "Module not found."; return "Module not found.";
@ -58,8 +58,8 @@ reload.callback = function (msg, line) {
try { try {
logger.info("hf:modules", `Reloading module: "${line}"`); logger.info("hf:modules", `Reloading module: "${line}"`);
delete require.cache[require.resolve(`./${line}.js`)]; delete require.cache[require.resolve(`@modules/${line}.js`)];
require(`./${line}.js`); require(`@modules/${line}.js`);
return {reaction: "\uD83D\uDC4C"}; return {reaction: "\uD83D\uDC4C"};
} catch (err) { } catch (err) {
logger.info("hf:modules", `Failed to reload "${line}": ${err}`); logger.info("hf:modules", `Failed to reload "${line}": ${err}`);

View file

@ -1,8 +1,8 @@
const {ApplicationCommandOptionTypes, MessageFlags} = require("../util/dconstants.js"); const {ApplicationCommandOptionTypes, MessageFlags} = require("@util/dconstants.js");
const InteractionCommand = require("../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const events = require("../lib/events.js"); const events = require("@lib/events.js");
const {hasFlag} = require("../lib/guildSettings.js"); const {hasFlag} = require("@lib/guildSettings.js");
const REGEX_GITHUB = const REGEX_GITHUB =
/(?:\s|^)(\|\|\s*)?https?:\/\/(www\.)?github\.com\/[a-z0-9-]+\/[a-z0-9-._]+\/blob\/([a-z0-9-_.?&=#/%]*)(\s*\|\|)?/gi; /(?:\s|^)(\|\|\s*)?https?:\/\/(www\.)?github\.com\/[a-z0-9-]+\/[a-z0-9-._]+\/blob\/([a-z0-9-_.?&=#/%]*)(\s*\|\|)?/gi;
const REGEX_GITLAB = const REGEX_GITLAB =

View file

@ -1,16 +1,16 @@
const {Message} = require("@projectdysnomia/dysnomia"); const {Message} = require("@projectdysnomia/dysnomia");
const {MessageFlags, ApplicationCommandOptionTypes, Permissions} = require("../util/dconstants.js");
const fs = require("node:fs"); const fs = require("node:fs");
const path = require("node:path");
const httpSignature = require("@peertube/http-signature"); const httpSignature = require("@peertube/http-signature");
const events = require("../lib/events.js"); const events = require("@lib/events.js");
const logger = require("../lib/logger.js"); const logger = require("@lib/logger.js");
const {hasFlag} = require("../lib/guildSettings.js"); const {hasFlag} = require("@lib/guildSettings.js");
const InteractionCommand = require("../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const {getUploadLimit} = require("../util/misc.js"); const {MessageFlags, ApplicationCommandOptionTypes, Permissions} = require("@util/dconstants.js");
const {htmlToMarkdown} = require("../util/html.js"); const {getUploadLimit} = require("@util/misc.js");
const {htmlToMarkdown} = require("@util/html.js");
const FRIENDLY_USERAGENT = "HiddenPhox/fedimbed (https://gitdab.com/Cynosphere/HiddenPhox)"; const FRIENDLY_USERAGENT = "HiddenPhox/fedimbed (https://gitdab.com/Cynosphere/HiddenPhox)";
@ -83,7 +83,7 @@ async function resolvePlatform(url) {
} }
const keyId = "https://hf.c7.pm/actor#main-key"; const keyId = "https://hf.c7.pm/actor#main-key";
const privKey = fs.readFileSync(path.resolve(__dirname, "../../priv/private.pem")); const privKey = fs.readFileSync(require.resolve("@/priv/private.pem"));
async function signedFetch(url, options) { async function signedFetch(url, options) {
const urlObj = new URL(url); const urlObj = new URL(url);

View file

@ -1,15 +1,15 @@
const Command = require("../lib/command.js"); const Command = require("@lib/command.js");
const events = require("../lib/events.js"); const events = require("@lib/events.js");
const logger = require("@lib/logger.js");
const {tinycolor} = require("@ctrl/tinycolor");
const {pastelize} = require("@util/misc.js");
const {createBoardMessage} = require("@util/starboard.js");
const CATEGORY = "misc"; const CATEGORY = "misc";
const FOXWELLS_GUILD_ID = "300436792916836352"; const FOXWELLS_GUILD_ID = "300436792916836352";
const {tinycolor} = require("@ctrl/tinycolor");
const {pastelize} = require("../util/misc.js");
const {createBoardMessage} = require("../util/starboard.js");
const logger = require("../lib/logger.js");
// taken from rot13.com // taken from rot13.com
function rot(s, i) { function rot(s, i) {
return s.replace(/[a-zA-Z]/g, function (c) { return s.replace(/[a-zA-Z]/g, function (c) {

View file

@ -1,7 +1,7 @@
const Command = require("../lib/command.js"); const Command = require("@lib/command.js");
const CATEGORY = "general"; const CATEGORY = "general";
const {snowflakeToTimestamp} = require("../util/time.js"); const {snowflakeToTimestamp} = require("@util/time.js");
const help = new Command("help"); const help = new Command("help");
help.category = CATEGORY; help.category = CATEGORY;

View file

@ -1,7 +1,7 @@
const Command = require("../lib/command.js"); const Command = require("@lib/command.js");
const CATEGORY = "image"; const CATEGORY = "image";
const {getImage} = require("../util/image.js"); const {getImage} = require("@util/image.js");
//const dumpyConvert = require("dumpy").convert; //const dumpyConvert = require("dumpy").convert;
const Jimp = require("jimp"); const Jimp = require("jimp");

View file

@ -1,11 +1,11 @@
const fs = require("node:fs"); const fs = require("node:fs");
const {resolve} = require("node:path"); const {resolve} = require("node:path");
const logger = require("../lib/logger.js"); const logger = require("@lib/logger.js");
for (const file of fs.readdirSync(resolve(__dirname, "misc"))) { for (const file of fs.readdirSync(resolve(__dirname, "misc"))) {
try { try {
require(resolve(__dirname, "misc", file)); require(`@modules/misc/${file}`);
} catch (err) { } catch (err) {
logger.error("hf:modules:misc", `Failed to load "${file}": ${err}`); logger.error("hf:modules:misc", `Failed to load "${file}": ${err}`);
} }

View file

@ -1,6 +1,6 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {formatTime} = require("../../util/time.js"); const {formatTime} = require("@util/time.js");
const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const anonradio = new Command("anonradio"); const anonradio = new Command("anonradio");

View file

@ -1,15 +1,14 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const {ApplicationCommandOptionTypes} = require("../../util/dconstants.js"); const {ApplicationCommandOptionTypes} = require("@util/dconstants.js");
const {safeString} = require("../../util/misc.js"); const {safeString} = require("@util/misc.js");
const {tinycolor, random: randomColor} = require("@ctrl/tinycolor"); const {tinycolor, random: randomColor} = require("@ctrl/tinycolor");
const sharp = require("sharp"); const sharp = require("sharp");
const fs = require("node:fs"); const fs = require("node:fs");
const {resolve} = require("node:path");
const colornamesRaw = fs.readFileSync(resolve(__dirname, "../../../data/colornames.csv"), "utf8"); const colornamesRaw = fs.readFileSync(require.resolve("@/data/colornames.csv"), "utf8");
const color = new Command("color"); const color = new Command("color");
color.category = "misc"; color.category = "misc";

View file

@ -1,7 +1,7 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {safeString} = require("../../util/misc.js"); const {safeString} = require("@util/misc.js");
const {formatTime} = require("../../util/time.js"); const {formatTime} = require("@util/time.js");
const GENERATE_HEADERS = { const GENERATE_HEADERS = {
Accept: "application/json", Accept: "application/json",

View file

@ -1,4 +1,4 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const GoogleImages = require("google-images"); const GoogleImages = require("google-images");

View file

@ -1,5 +1,5 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const logger = require("../../lib/logger.js"); const logger = require("@lib/logger.js");
const net = require("node:net"); const net = require("node:net");
const {resolveCname, resolveSrv} = require("node:dns/promises"); const {resolveCname, resolveSrv} = require("node:dns/promises");

View file

@ -1,6 +1,6 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {formatUsername} = require("../../util/misc.js"); const {formatUsername} = require("@util/misc.js");
const poll = new Command("poll"); const poll = new Command("poll");
poll.category = "misc"; poll.category = "misc";

View file

@ -1,10 +1,10 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const {ApplicationCommandOptionTypes} = require("../../util/dconstants.js"); const {ApplicationCommandOptionTypes} = require("@util/dconstants.js");
const {safeString} = require("../../util/misc.js"); const {safeString} = require("@util/misc.js");
const {parseHtmlEntities} = require("../../util/html.js"); const {parseHtmlEntities} = require("@util/html.js");
const search = new Command("search"); const search = new Command("search");
search.category = "misc"; search.category = "misc";

View file

@ -1,4 +1,4 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const REGEX_IPV4 = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/; const REGEX_IPV4 = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/;

View file

@ -1,9 +1,9 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const {ApplicationCommandOptionTypes} = require("../../util/dconstants.js"); const {ApplicationCommandOptionTypes} = require("@util/dconstants.js");
const {safeString} = require("../../util/misc.js"); const {safeString} = require("@util/misc.js");
const WA_NO_ANSWER = "<:ms_cross:503341994974773250> No answer."; const WA_NO_ANSWER = "<:ms_cross:503341994974773250> No answer.";

View file

@ -1,10 +1,10 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const {ApplicationCommandOptionTypes} = require("../../util/dconstants.js"); const {ApplicationCommandOptionTypes} = require("@util/dconstants.js");
const {safeString} = require("../../util/misc.js"); const {safeString} = require("@util/misc.js");
const {parseHtmlEntities} = require("../../util/html.js"); const {parseHtmlEntities} = require("@util/html.js");
const yt = new Command("youtube"); const yt = new Command("youtube");
yt.addAlias("yt"); yt.addAlias("yt");

View file

@ -1,8 +1,8 @@
const Command = require("../lib/command.js"); const Command = require("@lib/command.js");
const CATEGORY = "moderation"; const CATEGORY = "moderation";
const {formatUsername} = require("../util/misc.js"); const {formatUsername} = require("@util/misc.js");
const {lookupUser} = require("../util/selection.js"); const {lookupUser} = require("@util/selection.js");
const tidy = new Command("tidy"); const tidy = new Command("tidy");
tidy.addAlias("prune"); tidy.addAlias("prune");

View file

@ -3,12 +3,12 @@ const {Collection} = require("@projectdysnomia/dysnomia");
const {Readable} = require("node:stream"); const {Readable} = require("node:stream");
const ffprobe = require("node-ffprobe"); const ffprobe = require("node-ffprobe");
const Command = require("../lib/command.js"); const Command = require("@lib/command.js");
const {formatUsername} = require("../util/misc.js"); const {formatUsername} = require("@util/misc.js");
const {formatTime} = require("../util/time.js"); const {formatTime} = require("@util/time.js");
const {parseHtmlEntities} = require("../util/html.js"); const {parseHtmlEntities} = require("@util/html.js");
const {selectionMessage} = require("../util/selection.js"); const {selectionMessage} = require("@util/selection.js");
const REGEX_YOUTUBE = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/; const REGEX_YOUTUBE = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/;
const REGEX_YOUTUBE_PLAYLIST = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/playlist\?list=(.+)$/; const REGEX_YOUTUBE_PLAYLIST = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/playlist\?list=(.+)$/;

View file

@ -10,18 +10,20 @@ private_reminders.json example:
] ]
*/ */
const fs = require("fs"); const timer = require("@lib/timer");
const {resolve} = require("path"); const logger = require("@lib/logger");
const timer = require("../lib/timer");
const logger = require("../lib/logger");
if (!fs.existsSync(resolve(__dirname, "..", "..", "private_reminders.json"))) return;
const tzFormatterCache = {}; const tzFormatterCache = {};
const dmCache = {}; const dmCache = {};
const reminderData = require(resolve(__dirname, "..", "..", "private_reminders.json")); let reminderData;
try {
reminderData = require("@/private_reminders.json");
} catch {
return;
}
if (!reminderData) return;
hf.database.run( hf.database.run(
"CREATE TABLE IF NOT EXISTS private_reminders (user TEXT NOT NULL PRIMARY KEY, last_run TEXT NOT NULL) WITHOUT ROWID" "CREATE TABLE IF NOT EXISTS private_reminders (user TEXT NOT NULL PRIMARY KEY, last_run TEXT NOT NULL) WITHOUT ROWID"

View file

@ -1,6 +1,6 @@
const Command = require("../lib/command.js"); const Command = require("@lib/command.js");
const {selectionMessage} = require("../util/selection.js"); const {selectionMessage} = require("@util/selection.js");
hf.database.run( hf.database.run(
"CREATE TABLE IF NOT EXISTS roleme (guild TEXT NOT NULL PRIMARY KEY, roles TEXT NOT NULL) WITHOUT ROWID" "CREATE TABLE IF NOT EXISTS roleme (guild TEXT NOT NULL PRIMARY KEY, roles TEXT NOT NULL) WITHOUT ROWID"

View file

@ -1,11 +1,11 @@
const fs = require("node:fs"); const fs = require("node:fs");
const {resolve} = require("node:path"); const {resolve} = require("node:path");
const logger = require("../lib/logger.js"); const logger = require("@lib/logger.js");
for (const file of fs.readdirSync(resolve(__dirname, "utility"))) { for (const file of fs.readdirSync(resolve(__dirname, "utility"))) {
try { try {
require(resolve(__dirname, "utility", file)); require(`@modules/utility/${file}`);
} catch (err) { } catch (err) {
logger.error("hf:modules:utility", `Failed to load "${file}": ${err}`); logger.error("hf:modules:utility", `Failed to load "${file}": ${err}`);
} }

View file

@ -1,5 +1,5 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const { const {
APIEndpoints, APIEndpoints,
@ -8,14 +8,14 @@ const {
ApplicationTypes, ApplicationTypes,
CDNEndpoints, CDNEndpoints,
Games, Games,
} = require("../../util/dconstants.js"); } = require("@util/dconstants.js");
const { const {
ApplicationFlagNames, ApplicationFlagNames,
Icons, Icons,
RegExp: {Snowflake: SNOWFLAKE_REGEX}, RegExp: {Snowflake: SNOWFLAKE_REGEX},
} = require("../../util/constants.js"); } = require("@util/constants.js");
const {snowflakeToTimestamp} = require("../../util/time.js"); const {snowflakeToTimestamp} = require("@util/time.js");
const {getGuild, safeString, formatUsername, flagsFromInt} = require("../../util/misc.js"); const {getGuild, safeString, formatUsername, flagsFromInt} = require("@util/misc.js");
const appinfo = new Command("appinfo"); const appinfo = new Command("appinfo");
appinfo.category = "utility"; appinfo.category = "utility";

View file

@ -1,9 +1,9 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {CDNEndpoints} = require("../../util/dconstants.js"); const {CDNEndpoints} = require("@util/dconstants.js");
const {formatUsername, getDefaultAvatar} = require("../../util/misc.js"); const {formatUsername, getDefaultAvatar} = require("@util/misc.js");
const {lookupUser} = require("../../util/selection.js"); const {lookupUser} = require("@util/selection.js");
const avatar = new Command("avatar"); const avatar = new Command("avatar");
avatar.category = "utility"; avatar.category = "utility";

View file

@ -1,9 +1,9 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {APIEndpoints, CDNEndpoints} = require("../../util/dconstants.js"); const {APIEndpoints, CDNEndpoints} = require("@util/dconstants.js");
const {formatUsername} = require("../../util/misc.js"); const {formatUsername} = require("@util/misc.js");
const {lookupUser} = require("../../util/selection.js"); const {lookupUser} = require("@util/selection.js");
const banner = new Command("banner"); const banner = new Command("banner");
banner.category = "utility"; banner.category = "utility";

View file

@ -1,8 +1,8 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const {ApplicationCommandOptionTypes} = require("../../util/dconstants.js"); const {ApplicationCommandOptionTypes} = require("@util/dconstants.js");
const {getNamesFromString} = require("../../util/unicode.js"); const {getNamesFromString} = require("@util/unicode.js");
const charinfo = new Command("charinfo"); const charinfo = new Command("charinfo");
charinfo.category = "utility"; charinfo.category = "utility";

View file

@ -1,9 +1,9 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {APIEndpoints, CDNEndpoints} = require("../../util/dconstants.js"); const {APIEndpoints, CDNEndpoints} = require("@util/dconstants.js");
const {formatUsername} = require("../../util/misc.js"); const {formatUsername} = require("@util/misc.js");
const {lookupUser} = require("../../util/selection.js"); const {lookupUser} = require("@util/selection.js");
const decoration = new Command("decoration"); const decoration = new Command("decoration");
decoration.category = "utility"; decoration.category = "utility";

View file

@ -1,10 +1,10 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {APIEndpoints, UserFlags} = require("../../util/dconstants.js"); const {APIEndpoints, UserFlags} = require("@util/dconstants.js");
const { const {
RegExp: {Snowflake: SNOWFLAKE_REGEX}, RegExp: {Snowflake: SNOWFLAKE_REGEX},
} = require("../../util/constants.js"); } = require("@util/constants.js");
const {flagsFromInt, formatUsername} = require("../../util/misc.js"); const {flagsFromInt, formatUsername} = require("@util/misc.js");
const _UserFlags = Object.entries(UserFlags).filter(([name]) => name != "NONE"); const _UserFlags = Object.entries(UserFlags).filter(([name]) => name != "NONE");
for (const set of _UserFlags) { for (const set of _UserFlags) {

View file

@ -1,5 +1,5 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const {VoiceChannel} = require("@projectdysnomia/dysnomia"); const {VoiceChannel} = require("@projectdysnomia/dysnomia");
@ -12,14 +12,14 @@ const {
Games, Games,
Permissions, Permissions,
VerificationLevelStrings, VerificationLevelStrings,
} = require("../../util/dconstants.js"); } = require("@util/dconstants.js");
const { const {
RegExp: {Snowflake: SNOWFLAKE_REGEX}, RegExp: {Snowflake: SNOWFLAKE_REGEX},
Icons, Icons,
ChannelTypeNames, ChannelTypeNames,
} = require("../../util/constants.js"); } = require("@util/constants.js");
const {snowflakeToTimestamp} = require("../../util/time.js"); const {snowflakeToTimestamp} = require("@util/time.js");
const {getGuild, tryGetGuild, formatGuildFeatures} = require("../../util/misc.js"); const {getGuild, tryGetGuild, formatGuildFeatures} = require("@util/misc.js");
const guildinfo = new Command("guildinfo"); const guildinfo = new Command("guildinfo");
guildinfo.category = "utility"; guildinfo.category = "utility";

View file

@ -1,5 +1,5 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const sharp = require("sharp"); const sharp = require("sharp");
@ -7,9 +7,9 @@ const {
RegExp: {Emote: CUSTOM_EMOTE_REGEX}, RegExp: {Emote: CUSTOM_EMOTE_REGEX},
EmojiSets, EmojiSets,
EmojiNames, EmojiNames,
} = require("../../util/constants.js"); } = require("@util/constants.js");
const {ApplicationCommandOptionTypes, CDNEndpoints} = require("../../util/dconstants.js"); const {ApplicationCommandOptionTypes, CDNEndpoints} = require("@util/dconstants.js");
const {getNamesFromString} = require("../../util/unicode.js"); const {getNamesFromString} = require("@util/unicode.js");
const jumbo = new Command("jumbo"); const jumbo = new Command("jumbo");
jumbo.category = "utility"; jumbo.category = "utility";

View file

@ -1,16 +1,16 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js"); const InteractionCommand = require("@lib/interactionCommand.js");
const { const {
APIEndpoints, APIEndpoints,
ApplicationCommandOptionTypes, ApplicationCommandOptionTypes,
CDNEndpoints, CDNEndpoints,
DEFAULT_GROUP_DM_AVATARS, DEFAULT_GROUP_DM_AVATARS,
} = require("../../util/dconstants.js"); } = require("@util/dconstants.js");
const {Icons} = require("../../util/constants.js"); const {Icons} = require("@util/constants.js");
const {formatUsername, safeString, formatGuildFeatures} = require("../../util/misc.js"); const {formatUsername, safeString, formatGuildFeatures} = require("@util/misc.js");
const {snowflakeToTimestamp} = require("../../util/time.js"); const {snowflakeToTimestamp} = require("@util/time.js");
const lookupinvite = new Command("lookupinvite"); const lookupinvite = new Command("lookupinvite");
lookupinvite.category = "utility"; lookupinvite.category = "utility";

View file

@ -1,9 +1,9 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {APIEndpoints} = require("../../util/dconstants.js"); const {APIEndpoints} = require("@util/dconstants.js");
const { const {
RegExp: {Pomelo: POMELO_REGEX}, RegExp: {Pomelo: POMELO_REGEX},
} = require("../../util/constants.js"); } = require("@util/constants.js");
const pomelo = new Command("pomelo"); const pomelo = new Command("pomelo");
pomelo.category = "utility"; pomelo.category = "utility";

View file

@ -1,18 +1,12 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const sharp = require("sharp"); const sharp = require("sharp");
const { const {ActivityTypeNames, CDNEndpoints, Games, HangStatusStrings, HANG_STATUS_ICONS} = require("@util/dconstants.js");
ActivityTypeNames, const {Icons} = require("@util/constants.js");
CDNEndpoints, const {formatUsername} = require("@util/misc.js");
Games, const {lookupUser} = require("@util/selection.js");
HangStatusStrings, const {formatTime} = require("@util/time.js");
HANG_STATUS_ICONS,
} = require("../../util/dconstants.js");
const {Icons} = require("../../util/constants.js");
const {formatUsername} = require("../../util/misc.js");
const {lookupUser} = require("../../util/selection.js");
const {formatTime} = require("../../util/time.js");
const HangStatusImages = {}; const HangStatusImages = {};
(async () => { (async () => {

View file

@ -1,6 +1,6 @@
const Command = require("../../lib/command.js"); const Command = require("@lib/command.js");
const {snowflakeToTimestamp} = require("../../util/time.js"); const {snowflakeToTimestamp} = require("@util/time.js");
const snowflake = new Command("snowflake"); const snowflake = new Command("snowflake");
snowflake.category = "utility"; snowflake.category = "utility";

View file

@ -505,7 +505,7 @@ EMOJI_SETS.twitter = EMOJI_SETS.twemoji;
//EMOJI_SETS.fb = EMOJI_SETS.facebook; //EMOJI_SETS.fb = EMOJI_SETS.facebook;
module.exports.EmojiSets = EMOJI_SETS; module.exports.EmojiSets = EMOJI_SETS;
const EmojiData = require("../../data/emoji.json"); const EmojiData = require("@/data/emoji.json");
const EMOJI_NAMES = []; const EMOJI_NAMES = [];
for (const emoji of EmojiData) { for (const emoji of EmojiData) {
EMOJI_NAMES[emoji.char] = emoji.name.replace(/ /g, "_"); EMOJI_NAMES[emoji.char] = emoji.name.replace(/ /g, "_");

View file

@ -104,7 +104,7 @@ module.exports.DEFAULT_GROUP_DM_AVATARS = [
module.exports.ExplicitContentFilterStrings = ["Disabled", "Members without roles", "All members"]; module.exports.ExplicitContentFilterStrings = ["Disabled", "Members without roles", "All members"];
module.exports.Games = require("../../data/games.json"); module.exports.Games = require("@/data/games.json");
module.exports.HANG_STATUS_ICONS = Object.fromEntries( module.exports.HANG_STATUS_ICONS = Object.fromEntries(
Object.entries({ Object.entries({

View file

@ -34,15 +34,10 @@ function htmlToMarkdown(str, images = true, embed = true) {
str = str.replaceAll("\\", "\\\\"); str = str.replaceAll("\\", "\\\\");
str = str.replaceAll("#", "\\#"); str = str.replaceAll("#", "\\#");
str = str.replace(/<style(\s+[^>]+)?>(.|\n)*?<\/style>/gi, ""); str = str.replace(/<style(\s+[^>]+)?>(.|\n)*?<\/style>/gi, "");
str = str.replace( str = str.replace(/<a (\s+[^>]+)?href="([^"]+?)"(\s+[^>]+)?>(.+?)<\/a>/gi, (_, __, url, ___, text) => {
/<a (\s+[^>]+)?href="([^"]+?)"(\s+[^>]+)?>(.+?)<\/a>/gi, url = url.replace(/^\/\//, "https://").replace("\\#", "#");
(_, __, url, ___, text) => { return url == text ? url : `[${text}](${embed ? "" : "&lt;"}${url}${embed ? "" : "&gt;"})`;
url = url.replace(/^\/\//, "https://").replace("\\#", "#"); });
return url == text
? url
: `[${text}](${embed ? "" : "&lt;"}${url}${embed ? "" : "&gt;"})`;
}
);
if (images) if (images)
str = str.replace( str = str.replace(
/<img (\s+[^>]+)?src="([^"]+?)"(\s+[^>]+)?(alt|title)="([^"]+?)"(\s+[^>]+)?\/>/gi, /<img (\s+[^>]+)?src="([^"]+?)"(\s+[^>]+)?(alt|title)="([^"]+?)"(\s+[^>]+)?\/>/gi,
@ -54,10 +49,7 @@ function htmlToMarkdown(str, images = true, embed = true) {
(_, quote) => "&gt; " + quote.split("\n").join("\n&gt; ") (_, quote) => "&gt; " + quote.split("\n").join("\n&gt; ")
); );
str = str.replace(/<\/?p>/gi, "\n"); str = str.replace(/<\/?p>/gi, "\n");
str = str.replace( str = str.replace(/<dd>((.|\n)*?)<\/dd>/gi, (_, inner) => "\u3000\u3000" + inner.split("\n").join("\n\u3000\u3000"));
/<dd>((.|\n)*?)<\/dd>/gi,
(_, inner) => "\u3000\u3000" + inner.split("\n").join("\n\u3000\u3000")
);
str = str.replace(/<ol(\s+[^>]+)?>((.|\n)*?)<\/ol>/gi, (_, __, inner) => { str = str.replace(/<ol(\s+[^>]+)?>((.|\n)*?)<\/ol>/gi, (_, __, inner) => {
let index = 0; let index = 0;
return inner return inner
@ -88,10 +80,7 @@ function htmlToMarkdown(str, images = true, embed = true) {
str = str.replace(/<h2(\s+[^>]+)?>/gi, "## "); str = str.replace(/<h2(\s+[^>]+)?>/gi, "## ");
str = str.replace(/<h3(\s+[^>]+)?>/gi, "### "); str = str.replace(/<h3(\s+[^>]+)?>/gi, "### ");
str = str.replace(/<\/?h4(\s+[^>]+)?>/gi, "**"); str = str.replace(/<\/?h4(\s+[^>]+)?>/gi, "**");
str = str.replace( str = str.replace(/<(math|noscript)(\s+[^>]+)?>((.|\n)*?)<\/(math|noscript)>/gi, "");
/<(math|noscript)(\s+[^>]+)?>((.|\n)*?)<\/(math|noscript)>/gi,
""
);
str = str.replace(/<[^>]+?>/gi, ""); str = str.replace(/<[^>]+?>/gi, "");
str = parseHtmlEntities(str); str = parseHtmlEntities(str);
// whyyyyyyyyyyyy // whyyyyyyyyyyyy

View file

@ -42,13 +42,8 @@ async function findSuitableImage(msg) {
out.video = true; out.video = true;
out.url = "attachment://thumb.jpg"; out.url = "attachment://thumb.jpg";
let thumbUrl = let thumbUrl = embed.video.proxyURL ?? embed.video.url.replace("cdn.discordapp.com", "media.discordapp.net");
embed.video.proxyURL ?? if (thumbUrl.includes("media.discordapp.net") && thumbUrl.includes("?")) {
embed.video.url.replace("cdn.discordapp.com", "media.discordapp.net");
if (
thumbUrl.includes("media.discordapp.net") &&
thumbUrl.includes("?")
) {
if (thumbUrl.endsWith("&")) { if (thumbUrl.endsWith("&")) {
thumbUrl = thumbUrl += "format=jpeg"; thumbUrl = thumbUrl += "format=jpeg";
} else { } else {
@ -59,9 +54,7 @@ async function findSuitableImage(msg) {
} }
if (embed.thumbnail?.url) thumbUrl = embed.thumbnail.url; if (embed.thumbnail?.url) thumbUrl = embed.thumbnail.url;
let valid = await fetch(thumbUrl, {method: "HEAD"}).then( let valid = await fetch(thumbUrl, {method: "HEAD"}).then((res) => res.ok);
(res) => res.ok
);
if (!valid && thumbUrl.includes("media.discordapp.net")) { if (!valid && thumbUrl.includes("media.discordapp.net")) {
thumbUrl = await hf.bot.requestHandler thumbUrl = await hf.bot.requestHandler
.request("POST", "/attachments/refresh-urls", true, { .request("POST", "/attachments/refresh-urls", true, {
@ -84,9 +77,7 @@ async function findSuitableImage(msg) {
} }
async function isGif(url) { async function isGif(url) {
const type = await fetch(url, {method: "HEAD"}).then((res) => const type = await fetch(url, {method: "HEAD"}).then((res) => res.headers.get("Content-Type"));
res.headers.get("Content-Type")
);
return type == "image/gif"; return type == "image/gif";
} }
@ -136,13 +127,8 @@ async function getImage(msg, str) {
return `https://cdn.discordapp.com/emojis/${id}.png?v=1`; return `https://cdn.discordapp.com/emojis/${id}.png?v=1`;
} else if (/<@!?([0-9]+)>/.test(refMsg.content)) { } else if (/<@!?([0-9]+)>/.test(refMsg.content)) {
const id = refMsg.content.match(/<@!?([0-9]+)>/)[1]; const id = refMsg.content.match(/<@!?([0-9]+)>/)[1];
const user = await hf.bot.requestHandler.request( const user = await hf.bot.requestHandler.request("GET", "/users/" + id, true);
"GET", if (user) return `https://cdn.discordapp.com/avatars/${id}/${user.avatar}.png?size=1024`;
"/users/" + id,
true
);
if (user)
return `https://cdn.discordapp.com/avatars/${id}/${user.avatar}.png?size=1024`;
} }
} }
@ -161,13 +147,8 @@ async function getImage(msg, str) {
return `https://cdn.discordapp.com/emojis/${id}.png?v=1`; return `https://cdn.discordapp.com/emojis/${id}.png?v=1`;
} else if (/<@!?([0-9]+)>/.test(str)) { } else if (/<@!?([0-9]+)>/.test(str)) {
const id = str.match(/<@!?([0-9]+)>/)[1]; const id = str.match(/<@!?([0-9]+)>/)[1];
const user = await hf.bot.requestHandler.request( const user = await hf.bot.requestHandler.request("GET", "/users/" + id, true);
"GET", if (user) return `https://cdn.discordapp.com/avatars/${id}/${user.avatar}.png?size=1024`;
"/users/" + id,
true
);
if (user)
return `https://cdn.discordapp.com/avatars/${id}/${user.avatar}.png?size=1024`;
} else if (img) { } else if (img) {
return img; return img;
} }

View file

@ -2,7 +2,7 @@ const murmurhash = require("murmurhash").v3;
const {tinycolor} = require("@ctrl/tinycolor"); const {tinycolor} = require("@ctrl/tinycolor");
const {APIEndpoints, CDNEndpoints, UPLOAD_LIMIT, UPLOAD_LIMIT_TIER_2, UPLOAD_LIMIT_TIER_3} = require("./dconstants.js"); const {APIEndpoints, CDNEndpoints, UPLOAD_LIMIT, UPLOAD_LIMIT_TIER_2, UPLOAD_LIMIT_TIER_3} = require("./dconstants.js");
const {GuildFeaturesFormatted, Icons} = require("./constants.js"); const {GuildFeaturesFormatted, Icons} = require("@util/constants.js");
function pastelize(id) { function pastelize(id) {
const hue = murmurhash(id) % 360; const hue = murmurhash(id) % 360;

View file

@ -1,11 +1,11 @@
const {Collection} = require("@projectdysnomia/dysnomia"); const {Collection} = require("@projectdysnomia/dysnomia");
const logger = require("../lib/logger.js"); const logger = require("@lib/logger.js");
const {formatUsername} = require("./misc.js"); const {formatUsername} = require("@util/misc.js");
const {APIEndpoints} = require("./dconstants.js"); const {APIEndpoints} = require("@util/dconstants.js");
const { const {
RegExp: {Snowflake: REGEX_SNOWFLAKE}, RegExp: {Snowflake: REGEX_SNOWFLAKE},
} = require("./constants.js"); } = require("@util/constants.js");
if (!hf.selectionMessages) hf.selectionMessages = new Collection(); if (!hf.selectionMessages) hf.selectionMessages = new Collection();
async function selectionMessage(msg, heading, options, timeout = 30000, maxItems = 1) { async function selectionMessage(msg, heading, options, timeout = 30000, maxItems = 1) {

View file

@ -1,12 +1,7 @@
const {pastelize} = require("./misc.js"); const {pastelize} = require("@util/misc.js");
const {findSuitableImage} = require("./image.js"); const {findSuitableImage} = require("@util/image.js");
async function createBoardMessage( async function createBoardMessage(msg, count, threadId = null, fetchAttachment = true) {
msg,
count,
threadId = null,
fetchAttachment = true
) {
const name = msg.member?.nick ?? msg.author.globalName ?? msg.author.username; const name = msg.member?.nick ?? msg.author.globalName ?? msg.author.username;
const embed = { const embed = {
title: `${count} \u2b50 - ${msg.jumpLink}`, title: `${count} \u2b50 - ${msg.jumpLink}`,
@ -20,9 +15,7 @@ async function createBoardMessage(
image = await findSuitableImage(msg); image = await findSuitableImage(msg);
if (image.url) { if (image.url) {
if (image.video) { if (image.video) {
embed.description += `\n(contains video ${ embed.description += `\n(contains video ${image.attachment ? "attachment" : "embed"})`;
image.attachment ? "attachment" : "embed"
})`;
} }
embed.image = { embed.image = {
url: image.url, url: image.url,
@ -35,9 +28,7 @@ async function createBoardMessage(
username: name, username: name,
threadID: threadId, threadID: threadId,
embeds: [embed], embeds: [embed],
attachments: image?.file attachments: image?.file ? [{file: image.file, filename: "thumb.jpg"}] : null,
? [{file: image.file, filename: "thumb.jpg"}]
: null,
wait: true, wait: true,
}; };
} }

View file

@ -10,9 +10,7 @@ function formatTime(number) {
return ( return (
(days !== 0 ? `${days.toString().padStart(2, "0")}:` : "") + (days !== 0 ? `${days.toString().padStart(2, "0")}:` : "") +
(hours !== 0 ? `${hours.toString().padStart(2, "0")}:` : "") + (hours !== 0 ? `${hours.toString().padStart(2, "0")}:` : "") +
`${minutes.toString().padStart(2, "0")}:${seconds `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`
.toString()
.padStart(2, "0")}`
); );
} }
@ -31,10 +29,7 @@ function readableTime(number) {
const TWITTER_EPOCH = 1288834974657; const TWITTER_EPOCH = 1288834974657;
const DISCORD_EPOCH = 1420070400000; const DISCORD_EPOCH = 1420070400000;
function snowflakeToTimestamp(snowflake, twitter = false) { function snowflakeToTimestamp(snowflake, twitter = false) {
return ( return Math.floor(Number(snowflake) / Math.pow(2, 22)) + (twitter == true ? TWITTER_EPOCH : DISCORD_EPOCH);
Math.floor(Number(snowflake) / Math.pow(2, 22)) +
(twitter == true ? TWITTER_EPOCH : DISCORD_EPOCH)
);
} }
module.exports = { module.exports = {

View file

@ -1,9 +1,7 @@
const mappings = {}; const mappings = {};
async function cacheList() { async function cacheList() {
const data = await fetch( const data = await fetch("https://www.unicode.org/Public/UNIDATA/UnicodeData.txt").then((res) => res.text());
"https://www.unicode.org/Public/UNIDATA/UnicodeData.txt"
).then((res) => res.text());
data data
.split("\n") .split("\n")