feat: new structure, and fixes paths on handlers
|
@ -1,19 +0,0 @@
|
|||
import { Client } from "discord.js";
|
||||
import { config } from "../config.js";
|
||||
import { init as initCommands } from "../handlers/command-handler/index.js";
|
||||
import { init as initEvents } from "../handlers/event-handler/index.js";
|
||||
|
||||
export class ExtendedClient extends Client {
|
||||
/**
|
||||
* @param {import("discord.js").ClientOptions} options
|
||||
*/
|
||||
constructor(options) {
|
||||
super(options);
|
||||
}
|
||||
|
||||
async init() {
|
||||
return this.login(config.token)
|
||||
.then(async () => await Promise.all([initCommands(), initEvents()]))
|
||||
.catch(console.error);
|
||||
}
|
||||
}
|
|
@ -2,10 +2,10 @@
|
|||
"name": "jaba",
|
||||
"version": "4.6.7",
|
||||
"description": "My Discord Bot",
|
||||
"main": "index.js",
|
||||
"main": "src/index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node ."
|
||||
"start": "node src/index.js"
|
||||
},
|
||||
"author": "https://github.com/JonnyBro",
|
||||
"dependencies": {
|
||||
|
|
9
src/adapters/database/IDatabaseAdapter.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
export default class IDatabaseAdapter {
|
||||
async connect() {
|
||||
throw new Error("Method `connect` not implemented.");
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
throw new Error("Method `disconnect` not implemented.");
|
||||
}
|
||||
}
|
31
src/adapters/database/MongooseAdapter.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import mongoose from "mongoose";
|
||||
import IDatabaseAdapter from "./IDatabaseAdapter.js";
|
||||
|
||||
export default class MongooseAdapter extends IDatabaseAdapter {
|
||||
/**
|
||||
*
|
||||
* @param {string} uri - database url connect
|
||||
* @param {mongoose.ConnectOptions} options - database connect options
|
||||
*/
|
||||
constructor(uri, options = {}) {
|
||||
super();
|
||||
|
||||
if (!uri) {
|
||||
throw new Error("MongooseAdapter: URI is required.");
|
||||
}
|
||||
|
||||
this.uri = uri;
|
||||
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
async connect() {
|
||||
await mongoose.connect(this.uri, this.options);
|
||||
console.log("Database connected.");
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
await mongoose.disconnect();
|
||||
console.log("Database disconnected.");
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
|
@ -10,8 +10,8 @@ import { promises as fs } from "fs";
|
|||
import { setTimeout } from "timers/promises";
|
||||
import mongoose from "mongoose";
|
||||
|
||||
import config from "../config.js";
|
||||
import * as emojis from "../emojis.json";
|
||||
import config from "../../config.js";
|
||||
import * as emojis from "../../emojis.json";
|
||||
import langs from "../languages/language-meta.js";
|
||||
import logger from "../helpers/logger.js";
|
||||
import * as funcs from "../helpers/functions.js";
|
||||
|
@ -327,7 +327,7 @@ class JaBaClient extends Client {
|
|||
/**
|
||||
* Returns a User data from the database.
|
||||
* @param {string} userID - The ID of the user to find or create.
|
||||
* @returns {Promise<import("./User")>} The user data object, either retrieved from the database or newly created.
|
||||
* @returns {Promise<import("./User.js")>} The user data object, either retrieved from the database or newly created.
|
||||
*/
|
||||
async getUserData(userID) {
|
||||
let userData = await this.usersData.findOne({ id: userID });
|
||||
|
@ -346,7 +346,7 @@ class JaBaClient extends Client {
|
|||
* Returns a Member data from the database.
|
||||
* @param {string} memberId - The ID of the member to find or create.
|
||||
* @param {string} guildId - The ID of the guild the member belongs to.
|
||||
* @returns {Promise<import("./Member")>} The member data object, either retrieved from the database or newly created.
|
||||
* @returns {Promise<import("./Member.js")>} The member data object, either retrieved from the database or newly created.
|
||||
*/
|
||||
async getMemberData(memberId, guildId) {
|
||||
let memberData = await this.membersData.findOne({ guildID: guildId, id: memberId });
|
||||
|
@ -370,7 +370,7 @@ class JaBaClient extends Client {
|
|||
/**
|
||||
* Returns a Guild data from the database.
|
||||
* @param {string} guildId - The ID of the guild to find or create.
|
||||
* @returns {Promise<import("./Guild")>} The guild data object, either retrieved from the database or newly created.
|
||||
* @returns {Promise<import("./Guild.js")>} The guild data object, either retrieved from the database or newly created.
|
||||
*/
|
||||
async getGuildData(guildId) {
|
||||
let guildData = await this.guildsData.findOne({ id: guildId }).populate("members");
|