start conversion tro esm modules

This commit is contained in:
Jonny_Bro (Nikita) 2024-12-05 19:16:01 +05:00
parent 5a30a64230
commit 04552202df
8 changed files with 747 additions and 129 deletions

View file

@ -8,4 +8,4 @@
"trailingComma": "all",
"useTabs": true,
"parser": "babel"
}
}

View file

@ -1,5 +1,5 @@
/* eslint-disable no-unused-vars */
const path = require("path");
import { sep } from "path";
class BaseCommand {
constructor(options, client) {
@ -15,8 +15,8 @@ class BaseCommand {
/**
* @type {String}
*/
this.category = this.dirname ? this.dirname.split(path.sep)[parseInt(this.dirname.split(path.sep).length - 1, 10)] : "Other";
this.category = this.dirname ? this.dirname.split(sep)[parseInt(this.dirname.split(sep).length - 1, 10)] : "Other";
}
}
module.exports = BaseCommand;
export default BaseCommand;

View file

@ -7,7 +7,7 @@ const { Client, Collection, SlashCommandBuilder, ContextMenuCommandBuilder, Embe
{ Routes } = require("discord-api-types/v10");
const BaseEvent = require("./BaseEvent.js"),
BaseCommand = require("./BaseCommand.js"),
BaseCommand = require("./BaseCommand.js").default,
path = require("path"),
fs = require("fs").promises,
mongoose = require("mongoose");
@ -63,10 +63,14 @@ class JaBaClient extends Client {
this.player.events.on("playerStart", async (queue, track) => {
const m = (
await queue.metadata.channel.send({
content: this.translate("music/play:NOW_PLAYING", {
songName: `${track.title} - ${track.author}`,
songURL: track.url,
}, queue.metadata.data.guild.language),
content: this.translate(
"music/play:NOW_PLAYING",
{
songName: `${track.title} - ${track.author}`,
songURL: track.url,
},
queue.metadata.data.guild.language,
),
})
).id;
@ -77,11 +81,14 @@ class JaBaClient extends Client {
if (message && message.deletable) message.delete();
}, track.durationMS);
else
setTimeout(() => {
const message = queue.metadata.channel.messages.cache.get(m);
setTimeout(
() => {
const message = queue.metadata.channel.messages.cache.get(m);
if (message && message.deletable) message.delete();
}, 5 * 60 * 1000);
if (message && message.deletable) message.delete();
},
5 * 60 * 1000,
);
});
this.player.events.on("emptyQueue", queue => queue.metadata.channel.send(this.translate("music/play:QUEUE_ENDED", null, queue.metadata.data.guild.language)));
this.player.events.on("emptyChannel", queue => queue.metadata.channel.send(this.translate("music/play:STOP_EMPTY", null, queue.metadata.data.guild.language)));
@ -291,7 +298,7 @@ class JaBaClient extends Client {
.setColor(data.color ?? this.config.embed.color)
.setFooter(typeof data.footer === "object" ? data.footer : data.footer ? { text: data.footer } : this.config.embed.footer)
.setTimestamp(data.timestamp ?? null)
.setAuthor(typeof data.author === "string" ? { name: data.author, iconURL: this.user.avatarURL() } : data.author ?? null);
.setAuthor(typeof data.author === "string" ? { name: data.author, iconURL: this.user.avatarURL() } : (data.author ?? null));
return embed;
}

View file

@ -1,4 +1,4 @@
module.exports = {
export const config = {
/* The token of your Discord Bot */
token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
/* UserID of your Discord Bot */
@ -42,7 +42,5 @@ module.exports = {
id: "123456789098765432", // The ID of the bot's owner
},
/* Add your own API keys here */
apiKeys: {
shlink: "12345678-1234-1234-1234-123456789098" /* Shlink.io REST API key */,
},
apiKeys: {},
};

50
eslint.config.js Normal file
View file

@ -0,0 +1,50 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import stylisticJs from "@stylistic/eslint-plugin-js";
/** @type {import("eslint").Linter.Config[]} */
export default [
pluginJs.configs.recommended,
{
languageOptions: {
globals: globals.node,
ecmaVersion: "latest",
sourceType: "module",
},
ignores: ["node_modules", "dashboard"],
plugins: {
"@stylistic/js": stylisticJs,
},
rules: {
"arrow-body-style": ["error", "as-needed"],
camelcase: "error",
curly: "error",
eqeqeq: ["error", "always"],
"no-console": "off",
"no-var": "error",
"prefer-const": "error",
yoda: "error",
"@stylistic/js/arrow-spacing": ["error", { before: true, after: true }],
"@stylistic/js/comma-dangle": ["error", "always-multiline"],
"@stylistic/js/comma-spacing": ["error", { before: false, after: true }],
"@stylistic/js/comma-style": ["error", "last"],
"@stylistic/js/dot-location": ["error", "property"],
"@stylistic/js/keyword-spacing": ["error", { before: true, after: true }],
"@stylistic/js/no-multi-spaces": "error",
"@stylistic/js/no-multiple-empty-lines": [
"error",
{
max: 2,
maxEOF: 1,
maxBOF: 0,
},
],
"@stylistic/js/no-trailing-spaces": ["error"],
"@stylistic/js/object-curly-spacing": ["error", "always"],
"@stylistic/js/quotes": ["error", "double"],
"@stylistic/js/indent": ["error", "tab"],
"@stylistic/js/semi": ["error", "always"],
"@stylistic/js/space-infix-ops": "error",
},
},
];

View file

@ -1,10 +1,26 @@
require("./helpers/extenders");
import "./helpers/extenders.js";
const { GatewayIntentBits } = require("discord.js"),
Client = require("./base/Client");
import { GatewayIntentBits } from "discord.js";
import Client from "./base/Client.js";
const client = new Client({
intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildEmojisAndStickers, GatewayIntentBits.GuildIntegrations, GatewayIntentBits.GuildInvites, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMessageTyping, GatewayIntentBits.MessageContent, GatewayIntentBits.DirectMessageTyping, GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessageReactions ],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
],
allowedMentions: { parse: ["everyone", "roles", "users"] },
});
@ -24,6 +40,4 @@ client
.on("warn", console.log)
.on("error", console.log);
process
.on("unhandledRejection", e => console.log(e))
.on("uncaughtException", e => console.log(e));
process.on("unhandledRejection", e => console.log(e)).on("uncaughtException", e => console.log(e));

View file

@ -3,6 +3,7 @@
"version": "4.6.7",
"description": "My Discord Bot",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node ."
},
@ -30,93 +31,11 @@
"node-fetch": "^2.7.0"
},
"devDependencies": {
"eslint": "^8.57.1"
},
"eslintConfig": {
"extends": "eslint:recommended",
"env": {
"commonjs": true,
"es6": true,
"es2020": true,
"node": true
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {
"arrow-spacing": [
"warn",
{
"before": true,
"after": true
}
],
"comma-dangle": [
"error",
"always-multiline"
],
"comma-spacing": "error",
"comma-style": "error",
"dot-location": [
"error",
"property"
],
"handle-callback-err": "off",
"indent": [
"error",
"tab",
{
"SwitchCase": 1
}
],
"keyword-spacing": "error",
"max-nested-callbacks": [
"error",
{
"max": 4
}
],
"max-statements-per-line": [
"error",
{
"max": 2
}
],
"no-console": "off",
"no-multi-spaces": "error",
"no-multiple-empty-lines": [
"error",
{
"max": 2,
"maxEOF": 1,
"maxBOF": 0
}
],
"no-trailing-spaces": [
"error"
],
"no-var": "error",
"object-curly-spacing": [
"error",
"always"
],
"prefer-const": "error",
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"yoda": "error"
}
"@eslint/js": "^9.16.0",
"@stylistic/eslint-plugin-js": "^2.11.0",
"eslint": "^9.16.0",
"globals": "^15.13.0",
"prettier": "^3.4.2",
"prettier-eslint": "^16.3.0"
}
}

File diff suppressed because it is too large Load diff