mirror of
https://github.com/JonnyBro/JaBa.git
synced 2025-02-06 01:24:10 +05:00
Compare commits
No commits in common. "fbf79936c0526c3897b1a830846c483493847309" and "6c7f892ae48b9cd0d52981c9139e3d28e028aa39" have entirely different histories.
fbf79936c0
...
6c7f892ae4
16 changed files with 82 additions and 239 deletions
|
@ -21,8 +21,14 @@ export default [
|
|||
"@stylistic/js": stylisticJs,
|
||||
},
|
||||
rules: {
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_" }],
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
argsIgnorePattern: "^_", // Игнорировать переменные, начинающиеся с _
|
||||
varsIgnorePattern: "^_", // Игнорировать переменные, начинающиеся с _
|
||||
ignoreRestSiblings: true, // Игнорировать неиспользуемые параметры в деструктуризации
|
||||
},
|
||||
],
|
||||
"arrow-body-style": ["error", "as-needed"],
|
||||
camelcase: "error",
|
||||
curly: ["error", "multi-line"],
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"scripts": {
|
||||
"start": "node dist/index.js",
|
||||
"dev": "tsx watch src/index.ts",
|
||||
"build": "tsc && tsc-alias"
|
||||
"build": "tsc"
|
||||
},
|
||||
"author": "https://github.com/JonnyBro",
|
||||
"dependencies": {
|
||||
|
@ -17,6 +17,7 @@
|
|||
"@napi-rs/canvas": "^0.1.63",
|
||||
"chalk": "^4.1.2",
|
||||
"cron": "^3.2.1",
|
||||
"discord-api-types": "^0.37.107",
|
||||
"discord-giveaways": "^6.0.1",
|
||||
"discord-player": "^6.7.1",
|
||||
"discord-player-youtubei": "1.3.5",
|
||||
|
@ -41,8 +42,7 @@
|
|||
"globals": "^15.13.0",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-eslint": "^16.3.0",
|
||||
"tsc-alias": "^1.8.10",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@ importers:
|
|||
cron:
|
||||
specifier: ^3.2.1
|
||||
version: 3.2.1
|
||||
discord-api-types:
|
||||
specifier: ^0.37.107
|
||||
version: 0.37.107
|
||||
discord-giveaways:
|
||||
specifier: ^6.0.1
|
||||
version: 6.0.1(discord.js@14.16.3)
|
||||
|
@ -93,9 +96,6 @@ importers:
|
|||
prettier-eslint:
|
||||
specifier: ^16.3.0
|
||||
version: 16.3.0
|
||||
tsc-alias:
|
||||
specifier: ^1.8.10
|
||||
version: 1.8.10
|
||||
tsx:
|
||||
specifier: ^4.19.2
|
||||
version: 4.19.2
|
||||
|
@ -663,10 +663,6 @@ packages:
|
|||
any-promise@1.3.0:
|
||||
resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==}
|
||||
|
||||
anymatch@3.1.3:
|
||||
resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
aproba@2.0.0:
|
||||
resolution: {integrity: sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==}
|
||||
|
||||
|
@ -688,10 +684,6 @@ packages:
|
|||
barse@0.4.3:
|
||||
resolution: {integrity: sha512-UEpvriJqAn8zuVinYICuKoPttZy3XxXEoqX/V2uYAL4zzJRuNzCK3+20nAu3YUIa2U7G53kf90wfBIp9/A+Odw==}
|
||||
|
||||
binary-extensions@2.3.0:
|
||||
resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
boolbase@1.0.0:
|
||||
resolution: {integrity: sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==}
|
||||
|
||||
|
@ -739,10 +731,6 @@ packages:
|
|||
resolution: {integrity: sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
chokidar@3.6.0:
|
||||
resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==}
|
||||
engines: {node: '>= 8.10.0'}
|
||||
|
||||
chownr@2.0.0:
|
||||
resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==}
|
||||
engines: {node: '>=10'}
|
||||
|
@ -762,10 +750,6 @@ packages:
|
|||
resolution: {integrity: sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
commander@9.5.0:
|
||||
resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==}
|
||||
engines: {node: ^12.20.0 || >=14}
|
||||
|
||||
common-tags@1.8.2:
|
||||
resolution: {integrity: sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==}
|
||||
engines: {node: '>=4.0.0'}
|
||||
|
@ -1177,10 +1161,6 @@ packages:
|
|||
resolution: {integrity: sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==}
|
||||
engines: {node: '>= 12'}
|
||||
|
||||
is-binary-path@2.1.0:
|
||||
resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
is-buffer@1.1.6:
|
||||
resolution: {integrity: sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==}
|
||||
|
||||
|
@ -1388,10 +1368,6 @@ packages:
|
|||
ms@2.1.3:
|
||||
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
|
||||
|
||||
mylas@2.1.13:
|
||||
resolution: {integrity: sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
||||
natural-compare@1.4.0:
|
||||
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
||||
|
||||
|
@ -1423,10 +1399,6 @@ packages:
|
|||
engines: {node: '>=6'}
|
||||
hasBin: true
|
||||
|
||||
normalize-path@3.0.0:
|
||||
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
normalize-url@8.0.1:
|
||||
resolution: {integrity: sha512-IO9QvjUMWxPQQhs60oOu10CRkWCiZzSUkzbXGGV9pviYl1fXYcvkzQ5jV9z8Y6un8ARoVRl4EtC6v6jNqbaJ/w==}
|
||||
engines: {node: '>=14.16'}
|
||||
|
@ -1495,10 +1467,6 @@ packages:
|
|||
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
|
||||
engines: {node: '>=8.6'}
|
||||
|
||||
plimit-lit@1.6.1:
|
||||
resolution: {integrity: sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
prelude-ls@1.2.1:
|
||||
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
|
||||
engines: {node: '>= 0.8.0'}
|
||||
|
@ -1548,10 +1516,6 @@ packages:
|
|||
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
queue-lit@1.5.2:
|
||||
resolution: {integrity: sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
queue-microtask@1.2.3:
|
||||
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
|
||||
|
||||
|
@ -1579,10 +1543,6 @@ packages:
|
|||
resolution: {integrity: sha512-ePeK6cc1EcKLEhJFt/AebMCLL+GgSKhuygrZ/GLaKZYEecIgIECf4UaUuaByiGtzckwR4ain9VzUh95T1exYGw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
readdirp@3.6.0:
|
||||
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
|
||||
engines: {node: '>=8.10.0'}
|
||||
|
||||
regenerator-runtime@0.14.1:
|
||||
resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==}
|
||||
|
||||
|
@ -1772,10 +1732,6 @@ packages:
|
|||
ts-mixer@6.0.4:
|
||||
resolution: {integrity: sha512-ufKpbmrugz5Aou4wcr5Wc1UUFWOLhq+Fm6qa6P0w0K5Qw2yhaUoiWszhCVuNQyNwrlGiscHOmqYoAox1PtvgjA==}
|
||||
|
||||
tsc-alias@1.8.10:
|
||||
resolution: {integrity: sha512-Ibv4KAWfFkFdKJxnWfVtdOmB0Zi1RJVxcbPGiCDsFpCQSsmpWyuzHG3rQyI5YkobWwxFPEyQfu1hdo4qLG2zPw==}
|
||||
hasBin: true
|
||||
|
||||
tslib@2.7.0:
|
||||
resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==}
|
||||
|
||||
|
@ -2443,11 +2399,6 @@ snapshots:
|
|||
|
||||
any-promise@1.3.0: {}
|
||||
|
||||
anymatch@3.1.3:
|
||||
dependencies:
|
||||
normalize-path: 3.0.0
|
||||
picomatch: 2.3.1
|
||||
|
||||
aproba@2.0.0: {}
|
||||
|
||||
are-we-there-yet@2.0.0:
|
||||
|
@ -2465,8 +2416,6 @@ snapshots:
|
|||
dependencies:
|
||||
readable-stream: 1.0.34
|
||||
|
||||
binary-extensions@2.3.0: {}
|
||||
|
||||
boolbase@1.0.0: {}
|
||||
|
||||
brace-expansion@1.1.11:
|
||||
|
@ -2532,18 +2481,6 @@ snapshots:
|
|||
parse5: 7.2.1
|
||||
parse5-htmlparser2-tree-adapter: 7.1.0
|
||||
|
||||
chokidar@3.6.0:
|
||||
dependencies:
|
||||
anymatch: 3.1.3
|
||||
braces: 3.0.3
|
||||
glob-parent: 5.1.2
|
||||
is-binary-path: 2.1.0
|
||||
is-glob: 4.0.3
|
||||
normalize-path: 3.0.0
|
||||
readdirp: 3.6.0
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.3
|
||||
|
||||
chownr@2.0.0: {}
|
||||
|
||||
color-convert@2.0.1:
|
||||
|
@ -2556,8 +2493,6 @@ snapshots:
|
|||
|
||||
commander@6.2.1: {}
|
||||
|
||||
commander@9.5.0: {}
|
||||
|
||||
common-tags@1.8.2: {}
|
||||
|
||||
concat-map@0.0.1: {}
|
||||
|
@ -3103,10 +3038,6 @@ snapshots:
|
|||
sprintf-js: 1.1.3
|
||||
optional: true
|
||||
|
||||
is-binary-path@2.1.0:
|
||||
dependencies:
|
||||
binary-extensions: 2.3.0
|
||||
|
||||
is-buffer@1.1.6: {}
|
||||
|
||||
is-extglob@2.1.1: {}
|
||||
|
@ -3283,8 +3214,6 @@ snapshots:
|
|||
|
||||
ms@2.1.3: {}
|
||||
|
||||
mylas@2.1.13: {}
|
||||
|
||||
natural-compare@1.4.0: {}
|
||||
|
||||
node-addon-api@5.1.0: {}
|
||||
|
@ -3310,8 +3239,6 @@ snapshots:
|
|||
dependencies:
|
||||
abbrev: 1.1.1
|
||||
|
||||
normalize-path@3.0.0: {}
|
||||
|
||||
normalize-url@8.0.1: {}
|
||||
|
||||
npmlog@5.0.1:
|
||||
|
@ -3375,10 +3302,6 @@ snapshots:
|
|||
|
||||
picomatch@2.3.1: {}
|
||||
|
||||
plimit-lit@1.6.1:
|
||||
dependencies:
|
||||
queue-lit: 1.5.2
|
||||
|
||||
prelude-ls@1.2.1: {}
|
||||
|
||||
prettier-eslint@16.3.0:
|
||||
|
@ -3414,8 +3337,6 @@ snapshots:
|
|||
|
||||
punycode@2.3.1: {}
|
||||
|
||||
queue-lit@1.5.2: {}
|
||||
|
||||
queue-microtask@1.2.3: {}
|
||||
|
||||
quick-lru@5.1.1: {}
|
||||
|
@ -3453,10 +3374,6 @@ snapshots:
|
|||
dependencies:
|
||||
readable-stream: 3.6.2
|
||||
|
||||
readdirp@3.6.0:
|
||||
dependencies:
|
||||
picomatch: 2.3.1
|
||||
|
||||
regenerator-runtime@0.14.1: {}
|
||||
|
||||
require-relative@0.8.7: {}
|
||||
|
@ -3628,15 +3545,6 @@ snapshots:
|
|||
|
||||
ts-mixer@6.0.4: {}
|
||||
|
||||
tsc-alias@1.8.10:
|
||||
dependencies:
|
||||
chokidar: 3.6.0
|
||||
commander: 9.5.0
|
||||
globby: 11.1.0
|
||||
mylas: 2.1.13
|
||||
normalize-path: 3.0.0
|
||||
plimit-lit: 1.6.1
|
||||
|
||||
tslib@2.7.0: {}
|
||||
|
||||
tsx@4.19.2:
|
||||
|
|
|
@ -37,7 +37,6 @@ const registerGlobalCommands = async (client: ExtendedClient, commands: CommandF
|
|||
logger.log(`Edited command globally: ${data.name}`);
|
||||
} else if (!targetCommand) {
|
||||
await appCommandsManager.create(data).catch(() => logger.error(`Failed to register command: ${data.name}`));
|
||||
logger.debug(`Command ${data.name} loaded globally`);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
@ -78,7 +77,6 @@ const registerDevCommands = async (client: ExtendedClient, commands: CommandFile
|
|||
logger.log(`Edited command globally: ${data.name}`);
|
||||
} else if (!targetCommand) {
|
||||
await guildCommands.create(data).catch(() => logger.error(`Failed to register command: ${data.name} in ${guildCommands.guild.name} server`));
|
||||
logger.debug(`Command ${data.name} loaded in dev`);
|
||||
}
|
||||
});
|
||||
}),
|
||||
|
|
|
@ -34,7 +34,7 @@ export class CommandHandler {
|
|||
const commandFilePaths = (await getFilePaths(cmdPath, true)).filter(path => path.endsWith(".js") || path.endsWith(".ts"));
|
||||
|
||||
for (const cmdFilePath of commandFilePaths) {
|
||||
const { data, run, options } = await import(toFileURL(cmdFilePath));
|
||||
const { data, run } = await import(toFileURL(cmdFilePath));
|
||||
|
||||
if (!data || !data.name) {
|
||||
logger.warn(`Command ${cmdFilePath} does not have a data object or name`);
|
||||
|
@ -46,7 +46,7 @@ export class CommandHandler {
|
|||
continue;
|
||||
}
|
||||
|
||||
this.commands.push({ data, run, options });
|
||||
this.commands.push({ data, run });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ export class CommandHandler {
|
|||
interaction,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error, "Command cannot be executed");
|
||||
logger.error(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
import { BuiltInValidationParams } from "@/types.js";
|
||||
|
||||
const cooldowns = new Map<string, Map<string, number>>();
|
||||
|
||||
export default function ({ targetCommand, interaction }: BuiltInValidationParams) {
|
||||
const { cooldown } = targetCommand.options || {};
|
||||
|
||||
if (!cooldown) return;
|
||||
|
||||
const now = Date.now();
|
||||
const userId = interaction.user.id;
|
||||
const commandName = targetCommand.data.name;
|
||||
|
||||
if (!cooldowns.has(commandName)) {
|
||||
cooldowns.set(commandName, new Map());
|
||||
}
|
||||
|
||||
const userCooldowns = cooldowns.get(commandName)!;
|
||||
|
||||
if (userCooldowns) {
|
||||
const expirationTime = userCooldowns.get(userId)! + cooldown * 1000;
|
||||
if (now < expirationTime) {
|
||||
const timeLeft = (expirationTime - now) / 1000;
|
||||
|
||||
if (!interaction.isRepliable()) return;
|
||||
|
||||
interaction.reply({
|
||||
content: `❌ You can use this command again in ${timeLeft.toFixed(1)} seconds.`,
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
userCooldowns.set(userId, now);
|
||||
return false;
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import { BuiltInValidationParams } from "@/types.js";
|
||||
import { ChannelType } from "discord.js";
|
||||
|
||||
export default function ({ interaction, targetCommand, client }: BuiltInValidationParams) {
|
||||
if (interaction.isAutocomplete()) return;
|
||||
|
@ -8,17 +7,6 @@ export default function ({ interaction, targetCommand, client }: BuiltInValidati
|
|||
|
||||
if (!targetCommand.options?.devOnly) return;
|
||||
|
||||
if (!interaction.isRepliable()) return;
|
||||
|
||||
if (interaction.channel?.type === ChannelType.DM) {
|
||||
interaction.reply({
|
||||
content: "❌ This command is only available in development servers.",
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (interaction.inGuild() && !devGuildsIds.includes(interaction.guildId)) {
|
||||
interaction.reply({
|
||||
content: "❌ This command is only available in development servers.",
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import devOnly from "./devOnly.js";
|
||||
import cooldown from "./cooldown.js";
|
||||
|
||||
export default [devOnly, cooldown];
|
||||
export default [devOnly];
|
||||
|
|
|
@ -6,14 +6,14 @@ import { GuildQueueEvents, useMainPlayer } from "discord-player";
|
|||
import { ExtendedClient } from "@/structures/client.js";
|
||||
import { ClientEvents } from "discord.js";
|
||||
|
||||
type EventHandlerEvents = {
|
||||
interface EventHandlerEvents {
|
||||
data: {
|
||||
name: keyof ClientEvents;
|
||||
once?: boolean;
|
||||
player?: boolean;
|
||||
};
|
||||
run: (...args: unknown[]) => void;
|
||||
};
|
||||
run: Function;
|
||||
}
|
||||
|
||||
export class EventHandler {
|
||||
events: EventHandlerEvents[] = [];
|
||||
|
@ -53,8 +53,6 @@ export class EventHandler {
|
|||
}
|
||||
|
||||
this.events.push({ data, run });
|
||||
|
||||
logger.debug(`Event ${eventFilePath} loaded`);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Error build events: ", error);
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
import { BaseInteraction, CacheType, Interaction, InteractionReplyOptions, Message, User } from "discord.js";
|
||||
import { BaseInteraction, User } from "discord.js";
|
||||
import useClient from "@/utils/use-client.js";
|
||||
|
||||
interface Options extends InteractionReplyOptions {
|
||||
prefixEmoji: string;
|
||||
locale?: string;
|
||||
edit?: boolean;
|
||||
mention?: boolean;
|
||||
}
|
||||
|
||||
export const getLocale = async (guildId: string) => {
|
||||
const client = useClient();
|
||||
const guild = await client.getGuildData(guildId);
|
||||
|
@ -17,18 +10,18 @@ export const getLocale = async (guildId: string) => {
|
|||
const getAppEmojis = () => {
|
||||
const client = useClient();
|
||||
|
||||
return client.application.emojis.cache;
|
||||
return client.application?.emojis.cache;
|
||||
};
|
||||
|
||||
const formatReply = (prefixEmoji: string, message: string) => {
|
||||
const emojis = getAppEmojis();
|
||||
const emoji = emojis.find(emoji => emoji.name === prefixEmoji);
|
||||
return prefixEmoji ? `${emoji?.toString()} ${message}` : `${message}`;
|
||||
const emojis = getAppEmojis()!;
|
||||
return prefixEmoji ? `${emojis.find(e => e.name === prefixEmoji).toString()} ${message}` : `${message}`;
|
||||
};
|
||||
|
||||
|
||||
export const getUsername = (user: User) => (user.discriminator === "0" ? user.username : user.tag);
|
||||
|
||||
export const replyTranslated = async <T extends CacheType = CacheType>(context: Interaction<T> | Message, key: string, args: unknown[], options: Options) => {
|
||||
export const replyTranslated = async (context, key, args, options = {}) => {
|
||||
const client = useClient();
|
||||
const locale = options.locale || client.configService.get("defaultLang");
|
||||
const translated = client.translate(key, {
|
||||
|
@ -38,39 +31,33 @@ export const replyTranslated = async <T extends CacheType = CacheType>(context:
|
|||
|
||||
const content = formatReply(options.prefixEmoji, translated);
|
||||
|
||||
if (context instanceof BaseInteraction) {
|
||||
if (!context.isRepliable()) return;
|
||||
|
||||
if (options.edit) {
|
||||
await context.editReply({ content });
|
||||
return;
|
||||
}
|
||||
await context.reply({
|
||||
content,
|
||||
ephemeral: options.ephemeral || false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const isInteraction = context instanceof BaseInteraction;
|
||||
|
||||
if (options.edit) {
|
||||
await context.edit({
|
||||
return isInteraction
|
||||
? await context.editReply({
|
||||
content,
|
||||
ephemeral: options.ephemeral || false,
|
||||
})
|
||||
: await context.edit({ content, allowedMentions: { repliedUser: options.mention || false } });
|
||||
}
|
||||
return isInteraction
|
||||
? await context.reply({
|
||||
content,
|
||||
ephemeral: options.ephemeral || false,
|
||||
})
|
||||
: await context.reply({
|
||||
content,
|
||||
allowedMentions: { repliedUser: options.mention || false },
|
||||
});
|
||||
return;
|
||||
}
|
||||
await context.reply({
|
||||
content,
|
||||
allowedMentions: { repliedUser: options.mention || false },
|
||||
});
|
||||
};
|
||||
|
||||
export const replySuccess = async <T extends CacheType = CacheType>(context: Interaction<T> | Message, key: string, args: unknown[], options: Options) => {
|
||||
export const replySuccess = async (context, key, args, options) => {
|
||||
options.prefixEmoji = "success";
|
||||
return await replyTranslated(context, key, args, options);
|
||||
};
|
||||
|
||||
export const replyError = async <T extends CacheType = CacheType>(context: Interaction<T> | Message, key: string, args: unknown[], options: Options) => {
|
||||
export const replyError = async (context, key, args, options) => {
|
||||
options.prefixEmoji = "error";
|
||||
return await replyTranslated(context, key, args, options);
|
||||
};
|
||||
|
|
|
@ -6,6 +6,14 @@ export async function asyncForEach<T>(collection: T[], callback: (_item: T) => P
|
|||
return await Promise.all(allPromises);
|
||||
}
|
||||
|
||||
export function sortByKey<T>(array: T[], key: string) {
|
||||
return array.sort(function (a, b) {
|
||||
const x = a[key];
|
||||
const y = b[key];
|
||||
return x < y ? 1 : x > y ? -1 : 0;
|
||||
});
|
||||
}
|
||||
|
||||
export function shuffle<T>(pArray: T[]) {
|
||||
const array: T[] = [];
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import useClient from "@/utils/use-client.js";
|
||||
import chalk from "chalk";
|
||||
|
||||
function format(tDate: Date | number) {
|
||||
|
@ -35,10 +34,6 @@ export default {
|
|||
},
|
||||
|
||||
debug(...content: unknown[]) {
|
||||
const client = useClient();
|
||||
const isProd = client.configService.get("production");
|
||||
console.log(isProd);
|
||||
if (isProd) return;
|
||||
return console.log(`[${format(Date.now())}]: ${logLevels.DEBUG} ${content.join(" ")}`);
|
||||
},
|
||||
|
||||
|
|
|
@ -8,18 +8,16 @@ export const data: CronTaskData = {
|
|||
task: async () => {
|
||||
const client = useClient();
|
||||
|
||||
const users = await client.adapter.find(UserModel, { reminds: { $gt: [] } });
|
||||
client.adapter.find(UserModel, { reminds: { $gt: [] } }).then(users => {
|
||||
for (const user of users) {
|
||||
if (!client.users.cache.has(user.id)) client.users.fetch(user.id);
|
||||
|
||||
for (const user of users) {
|
||||
if (!client.users.cache.has(user.id)) {
|
||||
client.users.fetch(user.id);
|
||||
client.cacheReminds.set(user.id, {
|
||||
id: user.id,
|
||||
reminds: user.reminds,
|
||||
});
|
||||
}
|
||||
|
||||
client.cacheReminds.set(user.id, {
|
||||
id: user.id,
|
||||
reminds: user.reminds,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
client.cacheReminds.forEach(async ({ id, reminds }) => {
|
||||
const cachedUser = client.users.cache.get(id);
|
||||
|
@ -30,7 +28,7 @@ export const data: CronTaskData = {
|
|||
|
||||
if (!mustSent.length) return;
|
||||
|
||||
mustSent.forEach(async r => {
|
||||
mustSent.forEach(r => {
|
||||
const embed = createEmbed({
|
||||
author: {
|
||||
name: client.translate("general/remindme:EMBED_TITLE"),
|
||||
|
@ -53,30 +51,28 @@ export const data: CronTaskData = {
|
|||
],
|
||||
});
|
||||
|
||||
await cachedUser.send({
|
||||
embeds: [embed],
|
||||
});
|
||||
|
||||
await client.adapter.updateOne(
|
||||
UserModel,
|
||||
{ id },
|
||||
{
|
||||
$pull: {
|
||||
reminds: {
|
||||
sendAt: r.sendAt,
|
||||
cachedUser
|
||||
.send({
|
||||
embeds: [embed],
|
||||
})
|
||||
.then(() => {
|
||||
client.adapter.updateOne(
|
||||
UserModel,
|
||||
{ id },
|
||||
{
|
||||
$pull: {
|
||||
reminds: {
|
||||
sendAt: r.sendAt,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const updatedReminds = reminds.filter(r => r.sendAt >= Math.floor(Date.now() / 1000));
|
||||
reminds = reminds.filter(r => r.sendAt >= Math.floor(Date.now() / 1000));
|
||||
|
||||
if (!updatedReminds.length) {
|
||||
client.cacheReminds.delete(id);
|
||||
} else {
|
||||
client.cacheReminds.set(id, { id, reminds: updatedReminds });
|
||||
}
|
||||
if (!reminds.length) client.cacheReminds.delete(id);
|
||||
});
|
||||
},
|
||||
schedule: "* * * * * *",
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { ExtendedClient } from "./structures/client.js";
|
||||
import logger from "./helpers/logger.js";
|
||||
import { CLIENT_INTENTS, CLIENT_ALLOWED_MENTIONS } from "./constants/index.js";
|
||||
import { Partials } from "discord.js";
|
||||
|
||||
const client = new ExtendedClient({
|
||||
intents: CLIENT_INTENTS,
|
||||
partials: [Partials.Channel],
|
||||
allowedMentions: CLIENT_ALLOWED_MENTIONS,
|
||||
});
|
||||
|
||||
|
@ -14,7 +12,7 @@ client.init();
|
|||
client
|
||||
.on("disconnect", () => logger.warn("Bot disconnected."))
|
||||
.on("reconnecting", () => logger.warn("Bot reconnecting..."))
|
||||
.on("warn", logger.warn)
|
||||
.on("error", logger.error);
|
||||
.on("warn", logger.log)
|
||||
.on("error", logger.log);
|
||||
|
||||
process.on("unhandledRejection", logger.error).on("uncaughtException", logger.error);
|
||||
process.on("unhandledRejection", logger.log).on("uncaughtException", logger.log);
|
||||
|
|
|
@ -3,7 +3,7 @@ import { CONFIG_PATH } from "@/constants/index.js";
|
|||
import logger from "@/helpers/logger.js";
|
||||
|
||||
class ConfigService {
|
||||
private config = this.loadConfig();
|
||||
config = this.loadConfig();
|
||||
|
||||
get<T>(key: string): T {
|
||||
const keys = key.split(".");
|
||||
|
|
1
src/types.d.ts
vendored
1
src/types.d.ts
vendored
|
@ -49,7 +49,6 @@ export interface CommandContext<_T extends Interaction, _Cached extends CacheTyp
|
|||
|
||||
export interface CommandOptions {
|
||||
devOnly?: boolean;
|
||||
cooldown?: number;
|
||||
}
|
||||
|
||||
export interface CommandFileObject {
|
||||
|
|
Loading…
Reference in a new issue