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

View file

@ -1,19 +1,20 @@
require("module-alias/register");
const {Client, Collection, Channel, Permission} = require("@projectdysnomia/dysnomia");
const fs = require("node:fs");
const {resolve} = require("node:path");
const sqlite3 = require("sqlite3");
const {instead, before} = require("spitroast");
const config = require("../config.json");
const apikeys = require("../apikeys.json");
const config = require("@/config.json");
const apikeys = require("@/apikeys.json");
const logger = require("./lib/logger.js");
const events = require("./lib/events.js");
const timer = require("./lib/timer.js");
const Command = require("./lib/command.js");
const InteractionCommand = require("./lib/interactionCommand.js");
const logger = require("@lib/logger.js");
const events = require("@lib/events.js");
const timer = require("@lib/timer.js");
const Command = require("@lib/command.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, {
defaultImageFormat: "png",
@ -55,14 +56,14 @@ global.hf = {
database,
};
const {formatUsername} = require("./util/misc.js");
const CommandDispatcher = require("./lib/commandDispatcher.js");
const {InteractionDispatcher} = require("./lib/interactionDispatcher.js");
const {hasFlag} = require("./lib/guildSettings.js");
const {formatUsername} = require("@util/misc.js");
const CommandDispatcher = require("@lib/commandDispatcher.js");
const {InteractionDispatcher} = require("@lib/interactionDispatcher.js");
const {hasFlag} = require("@lib/guildSettings.js");
for (const file of fs.readdirSync(resolve(__dirname, "modules"))) {
try {
require(resolve(__dirname, "modules", file));
require(`@modules/${file}`);
logger.info("hf:modules", `Loaded module: "${file}"`);
} catch (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.");
});
const commands = [];
for (const command of interactionCommands.values()) {
const options = [];
for (const option of Object.values(command.options)) {
const newOption = Object.assign({}, option);
delete newOption.default;
options.push(newOption);
if (!config.no_commands) {
const commands = [];
for (const command of interactionCommands.values()) {
const options = [];
for (const option of Object.values(command.options)) {
const newOption = Object.assign({}, option);
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
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);
}
await bot.requestHandler.request("PUT", APIEndpoints.COMMANDS(bot.application.id), true, commands);
});
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 logger = require("../lib/logger.js");
const child_process = require("child_process");
const {inspect} = require("util");
const {resolve} = require("path");
const logger = require("@lib/logger.js");
const guildSettings = require("@lib/guildSettings.js");
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) {
const shell = process.env.SHELL || (process.platform == "win32" ? "pwsh" : "sh");
@ -46,7 +46,7 @@ reload.category = CATEGORY;
reload.helpText = "Reloads a module.";
reload.callback = function (msg, line) {
try {
require.resolve(`./${line}.js`);
require.resolve(`@modules/${line}.js`);
} catch (err) {
if (err.code == "MODULE_NOT_FOUND") {
return "Module not found.";
@ -58,8 +58,8 @@ reload.callback = function (msg, line) {
try {
logger.info("hf:modules", `Reloading module: "${line}"`);
delete require.cache[require.resolve(`./${line}.js`)];
require(`./${line}.js`);
delete require.cache[require.resolve(`@modules/${line}.js`)];
require(`@modules/${line}.js`);
return {reaction: "\uD83D\uDC4C"};
} catch (err) {
logger.info("hf:modules", `Failed to reload "${line}": ${err}`);

View file

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

View file

@ -1,16 +1,16 @@
const {Message} = require("@projectdysnomia/dysnomia");
const {MessageFlags, ApplicationCommandOptionTypes, Permissions} = require("../util/dconstants.js");
const fs = require("node:fs");
const path = require("node:path");
const httpSignature = require("@peertube/http-signature");
const events = require("../lib/events.js");
const logger = require("../lib/logger.js");
const {hasFlag} = require("../lib/guildSettings.js");
const InteractionCommand = require("../lib/interactionCommand.js");
const events = require("@lib/events.js");
const logger = require("@lib/logger.js");
const {hasFlag} = require("@lib/guildSettings.js");
const InteractionCommand = require("@lib/interactionCommand.js");
const {getUploadLimit} = require("../util/misc.js");
const {htmlToMarkdown} = require("../util/html.js");
const {MessageFlags, ApplicationCommandOptionTypes, Permissions} = require("@util/dconstants.js");
const {getUploadLimit} = require("@util/misc.js");
const {htmlToMarkdown} = require("@util/html.js");
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 privKey = fs.readFileSync(path.resolve(__dirname, "../../priv/private.pem"));
const privKey = fs.readFileSync(require.resolve("@/priv/private.pem"));
async function signedFetch(url, options) {
const urlObj = new URL(url);

View file

@ -1,15 +1,15 @@
const Command = require("../lib/command.js");
const events = require("../lib/events.js");
const Command = require("@lib/command.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 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
function rot(s, i) {
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 {snowflakeToTimestamp} = require("../util/time.js");
const {snowflakeToTimestamp} = require("@util/time.js");
const help = new Command("help");
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 {getImage} = require("../util/image.js");
const {getImage} = require("@util/image.js");
//const dumpyConvert = require("dumpy").convert;
const Jimp = require("jimp");

View file

@ -1,11 +1,11 @@
const fs = require("node:fs");
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"))) {
try {
require(resolve(__dirname, "misc", file));
require(`@modules/misc/${file}`);
} catch (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 anonradio = new Command("anonradio");

View file

@ -1,15 +1,14 @@
const Command = require("../../lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js");
const {ApplicationCommandOptionTypes} = require("../../util/dconstants.js");
const Command = require("@lib/command.js");
const InteractionCommand = require("@lib/interactionCommand.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 sharp = require("sharp");
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");
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 {formatTime} = require("../../util/time.js");
const {safeString} = require("@util/misc.js");
const {formatTime} = require("@util/time.js");
const GENERATE_HEADERS = {
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");

View file

@ -1,5 +1,5 @@
const Command = require("../../lib/command.js");
const logger = require("../../lib/logger.js");
const Command = require("@lib/command.js");
const logger = require("@lib/logger.js");
const net = require("node:net");
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");
poll.category = "misc";

View file

@ -1,10 +1,10 @@
const Command = require("../../lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js");
const Command = require("@lib/command.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 {parseHtmlEntities} = require("../../util/html.js");
const {safeString} = require("@util/misc.js");
const {parseHtmlEntities} = require("@util/html.js");
const search = new Command("search");
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}$/;

View file

@ -1,9 +1,9 @@
const Command = require("../../lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js");
const Command = require("@lib/command.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.";

View file

@ -1,10 +1,10 @@
const Command = require("../../lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js");
const Command = require("@lib/command.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 {parseHtmlEntities} = require("../../util/html.js");
const {safeString} = require("@util/misc.js");
const {parseHtmlEntities} = require("@util/html.js");
const yt = new Command("youtube");
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 {formatUsername} = require("../util/misc.js");
const {lookupUser} = require("../util/selection.js");
const {formatUsername} = require("@util/misc.js");
const {lookupUser} = require("@util/selection.js");
const tidy = new Command("tidy");
tidy.addAlias("prune");

View file

@ -3,12 +3,12 @@ const {Collection} = require("@projectdysnomia/dysnomia");
const {Readable} = require("node:stream");
const ffprobe = require("node-ffprobe");
const Command = require("../lib/command.js");
const Command = require("@lib/command.js");
const {formatUsername} = require("../util/misc.js");
const {formatTime} = require("../util/time.js");
const {parseHtmlEntities} = require("../util/html.js");
const {selectionMessage} = require("../util/selection.js");
const {formatUsername} = require("@util/misc.js");
const {formatTime} = require("@util/time.js");
const {parseHtmlEntities} = require("@util/html.js");
const {selectionMessage} = require("@util/selection.js");
const REGEX_YOUTUBE = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/;
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 {resolve} = require("path");
const timer = require("../lib/timer");
const logger = require("../lib/logger");
if (!fs.existsSync(resolve(__dirname, "..", "..", "private_reminders.json"))) return;
const timer = require("@lib/timer");
const logger = require("@lib/logger");
const tzFormatterCache = {};
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(
"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(
"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 {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"))) {
try {
require(resolve(__dirname, "utility", file));
require(`@modules/utility/${file}`);
} catch (err) {
logger.error("hf:modules:utility", `Failed to load "${file}": ${err}`);
}

View file

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

View file

@ -1,8 +1,8 @@
const Command = require("../../lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js");
const Command = require("@lib/command.js");
const InteractionCommand = require("@lib/interactionCommand.js");
const {ApplicationCommandOptionTypes} = require("../../util/dconstants.js");
const {getNamesFromString} = require("../../util/unicode.js");
const {ApplicationCommandOptionTypes} = require("@util/dconstants.js");
const {getNamesFromString} = require("@util/unicode.js");
const charinfo = new Command("charinfo");
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 {lookupUser} = require("../../util/selection.js");
const {formatUsername} = require("@util/misc.js");
const {lookupUser} = require("@util/selection.js");
const decoration = new Command("decoration");
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 {
RegExp: {Snowflake: SNOWFLAKE_REGEX},
} = require("../../util/constants.js");
const {flagsFromInt, formatUsername} = require("../../util/misc.js");
} = require("@util/constants.js");
const {flagsFromInt, formatUsername} = require("@util/misc.js");
const _UserFlags = Object.entries(UserFlags).filter(([name]) => name != "NONE");
for (const set of _UserFlags) {

View file

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

View file

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

View file

@ -1,16 +1,16 @@
const Command = require("../../lib/command.js");
const InteractionCommand = require("../../lib/interactionCommand.js");
const Command = require("@lib/command.js");
const InteractionCommand = require("@lib/interactionCommand.js");
const {
APIEndpoints,
ApplicationCommandOptionTypes,
CDNEndpoints,
DEFAULT_GROUP_DM_AVATARS,
} = require("../../util/dconstants.js");
const {Icons} = require("../../util/constants.js");
} = require("@util/dconstants.js");
const {Icons} = require("@util/constants.js");
const {formatUsername, safeString, formatGuildFeatures} = require("../../util/misc.js");
const {snowflakeToTimestamp} = require("../../util/time.js");
const {formatUsername, safeString, formatGuildFeatures} = require("@util/misc.js");
const {snowflakeToTimestamp} = require("@util/time.js");
const lookupinvite = new Command("lookupinvite");
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 {
RegExp: {Pomelo: POMELO_REGEX},
} = require("../../util/constants.js");
} = require("@util/constants.js");
const pomelo = new Command("pomelo");
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 {
ActivityTypeNames,
CDNEndpoints,
Games,
HangStatusStrings,
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 {ActivityTypeNames, CDNEndpoints, Games, HangStatusStrings, 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 = {};
(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");
snowflake.category = "utility";

View file

@ -505,7 +505,7 @@ EMOJI_SETS.twitter = EMOJI_SETS.twemoji;
//EMOJI_SETS.fb = EMOJI_SETS.facebook;
module.exports.EmojiSets = EMOJI_SETS;
const EmojiData = require("../../data/emoji.json");
const EmojiData = require("@/data/emoji.json");
const EMOJI_NAMES = [];
for (const emoji of EmojiData) {
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.Games = require("../../data/games.json");
module.exports.Games = require("@/data/games.json");
module.exports.HANG_STATUS_ICONS = Object.fromEntries(
Object.entries({

View file

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

View file

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

View file

@ -2,7 +2,7 @@ const murmurhash = require("murmurhash").v3;
const {tinycolor} = require("@ctrl/tinycolor");
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) {
const hue = murmurhash(id) % 360;

View file

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

View file

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

View file

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

View file

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