mirror of
https://github.com/JonnyBro/JaBa.git
synced 2025-02-01 07:04:11 +05:00
refactor: move commands and events so we can start properly
This commit is contained in:
parent
30a83aa273
commit
d0b4a13a2e
98 changed files with 157 additions and 156 deletions
|
@ -1,5 +1,6 @@
|
|||
import mongoose from "mongoose";
|
||||
import IDatabaseAdapter from "./IDatabaseAdapter.js";
|
||||
import logger from "../../helpers/logger.js";
|
||||
|
||||
export default class MongooseAdapter extends IDatabaseAdapter {
|
||||
/**
|
||||
|
@ -21,11 +22,11 @@ export default class MongooseAdapter extends IDatabaseAdapter {
|
|||
|
||||
async connect() {
|
||||
await mongoose.connect(this.uri, this.options);
|
||||
console.log("Database connected.");
|
||||
logger.log("Database connected.");
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
await mongoose.disconnect();
|
||||
console.log("Database disconnected.");
|
||||
console.warn("Database disconnected.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,72 +1,8 @@
|
|||
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
|
||||
const BaseCommand = require("../../base/BaseCommand");
|
||||
export const data = {
|
||||
name: "8ball",
|
||||
description: "8ball",
|
||||
};
|
||||
|
||||
class Eightball extends BaseCommand {
|
||||
/**
|
||||
*
|
||||
* @param {import("../base/Client")} client
|
||||
*/
|
||||
constructor(client) {
|
||||
super({
|
||||
command: new SlashCommandBuilder()
|
||||
.setName("8ball")
|
||||
.setDescription(client.translate("fun/8ball:DESCRIPTION"))
|
||||
.setDescriptionLocalizations({
|
||||
uk: client.translate("fun/8ball:DESCRIPTION", null, "uk-UA"),
|
||||
ru: client.translate("fun/8ball:DESCRIPTION", null, "ru-RU"),
|
||||
})
|
||||
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
|
||||
.setContexts([InteractionContextType.BotDM, InteractionContextType.PrivateChannel, InteractionContextType.Guild])
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName("question")
|
||||
.setDescription(client.translate("fun/8ball:QUESTION"))
|
||||
.setDescriptionLocalizations({
|
||||
uk: client.translate("fun/8ball:QUESTION", null, "uk-UA"),
|
||||
ru: client.translate("fun/8ball:QUESTION", null, "ru-RU"),
|
||||
})
|
||||
.setRequired(true),
|
||||
)
|
||||
.addBooleanOption(option =>
|
||||
option
|
||||
.setName("ephemeral")
|
||||
.setDescription(client.translate("misc:EPHEMERAL_RESPONSE"))
|
||||
.setDescriptionLocalizations({
|
||||
uk: client.translate("misc:EPHEMERAL_RESPONSE", null, "uk-UA"),
|
||||
ru: client.translate("misc:EPHEMERAL_RESPONSE", null, "ru-RU"),
|
||||
}),
|
||||
),
|
||||
dirname: __dirname,
|
||||
ownerOnly: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("../../base/Client")} client
|
||||
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
||||
*/
|
||||
async execute(client, interaction) {
|
||||
await interaction.deferReply({ ephemeral: interaction.options.getBoolean("ephemeral") || false });
|
||||
|
||||
const question = interaction.options.getString("question");
|
||||
const embed = client.embed({
|
||||
fields: [
|
||||
{
|
||||
name: interaction.translate("fun/8ball:QUESTION"),
|
||||
value: question,
|
||||
},
|
||||
{
|
||||
name: interaction.translate("fun/8ball:ANSWER"),
|
||||
value: interaction.translate(`fun/8ball:RESPONSE_${client.functions.randomNum(1, 20)}`),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await client.wait(5000);
|
||||
|
||||
interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Eightball;
|
||||
export const run = () => {
|
||||
console.log("8ball");
|
||||
};
|
||||
|
|
72
src/commands_OLD/Fun/8ball.js
Normal file
72
src/commands_OLD/Fun/8ball.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
|
||||
const BaseCommand = require("../../base/BaseCommand");
|
||||
|
||||
class Eightball extends BaseCommand {
|
||||
/**
|
||||
*
|
||||
* @param {import("../base/Client")} client
|
||||
*/
|
||||
constructor(client) {
|
||||
super({
|
||||
command: new SlashCommandBuilder()
|
||||
.setName("8ball")
|
||||
.setDescription(client.translate("fun/8ball:DESCRIPTION"))
|
||||
.setDescriptionLocalizations({
|
||||
uk: client.translate("fun/8ball:DESCRIPTION", null, "uk-UA"),
|
||||
ru: client.translate("fun/8ball:DESCRIPTION", null, "ru-RU"),
|
||||
})
|
||||
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
|
||||
.setContexts([InteractionContextType.BotDM, InteractionContextType.PrivateChannel, InteractionContextType.Guild])
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName("question")
|
||||
.setDescription(client.translate("fun/8ball:QUESTION"))
|
||||
.setDescriptionLocalizations({
|
||||
uk: client.translate("fun/8ball:QUESTION", null, "uk-UA"),
|
||||
ru: client.translate("fun/8ball:QUESTION", null, "ru-RU"),
|
||||
})
|
||||
.setRequired(true),
|
||||
)
|
||||
.addBooleanOption(option =>
|
||||
option
|
||||
.setName("ephemeral")
|
||||
.setDescription(client.translate("misc:EPHEMERAL_RESPONSE"))
|
||||
.setDescriptionLocalizations({
|
||||
uk: client.translate("misc:EPHEMERAL_RESPONSE", null, "uk-UA"),
|
||||
ru: client.translate("misc:EPHEMERAL_RESPONSE", null, "ru-RU"),
|
||||
}),
|
||||
),
|
||||
dirname: __dirname,
|
||||
ownerOnly: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("../../base/Client")} client
|
||||
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
||||
*/
|
||||
async execute(client, interaction) {
|
||||
await interaction.deferReply({ ephemeral: interaction.options.getBoolean("ephemeral") || false });
|
||||
|
||||
const question = interaction.options.getString("question");
|
||||
const embed = client.embed({
|
||||
fields: [
|
||||
{
|
||||
name: interaction.translate("fun/8ball:QUESTION"),
|
||||
value: question,
|
||||
},
|
||||
{
|
||||
name: interaction.translate("fun/8ball:ANSWER"),
|
||||
value: interaction.translate(`fun/8ball:RESPONSE_${client.functions.randomNum(1, 20)}`),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await client.wait(5000);
|
||||
|
||||
interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Eightball;
|
|
@ -1,64 +1,14 @@
|
|||
import { ActivityType } from "discord.js";
|
||||
import BaseEvent from "../base/BaseEvent";
|
||||
import logger from "../helpers/logger.js";
|
||||
|
||||
class Ready extends BaseEvent {
|
||||
constructor() {
|
||||
super({
|
||||
name: "ready",
|
||||
once: false,
|
||||
});
|
||||
}
|
||||
export const data = {
|
||||
name: "ready",
|
||||
once: true,
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("../base/Client")} client
|
||||
*/
|
||||
async execute(client) {
|
||||
const commands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()];
|
||||
let servers = client.guilds.cache.size;
|
||||
let users = 0;
|
||||
|
||||
client.guilds.cache.forEach(g => {
|
||||
users += g.memberCount;
|
||||
});
|
||||
|
||||
const birthdays = require("../helpers/birthdays");
|
||||
birthdays.init(client);
|
||||
|
||||
const checkReminds = require("../helpers/checkReminds");
|
||||
checkReminds.init(client);
|
||||
|
||||
client.logger.ready(`Loaded a total of ${commands.length} command(s).`);
|
||||
client.logger.ready(`${client.user.getUsername()}, ready to serve ${users} members in ${servers} servers.`);
|
||||
console.timeEnd("botReady");
|
||||
|
||||
const version = require("../package.json").version;
|
||||
const status = [
|
||||
`${commands.length} ${client.functions.getNoun(commands.length, client.translate("misc:NOUNS:COMMANDS:1"), client.translate("misc:NOUNS:COMMANDS:2"), client.translate("misc:NOUNS:COMMANDS:5"))} available!`,
|
||||
`I'm in ${servers} ${client.functions.getNoun(servers, client.translate("misc:NOUNS:SERVER:1"), client.translate("misc:NOUNS:SERVER:2"), client.translate("misc:NOUNS:SERVER:5"))}!`,
|
||||
`Cached ${users} ${client.functions.getNoun(users, client.translate("misc:NOUNS:USERS:1"), client.translate("misc:NOUNS:USERS:2"), client.translate("misc:NOUNS:USERS:5"))}.`,
|
||||
"Use /help for commands list!",
|
||||
"Did you know that I have a brother called JaBa IT? Yeah! Ask Jonny about him.",
|
||||
];
|
||||
|
||||
let i = 0;
|
||||
setInterval(async () => {
|
||||
servers = (await client.guilds.fetch()).size;
|
||||
users = 0;
|
||||
|
||||
client.guilds.cache.forEach(g => {
|
||||
users += g.memberCount;
|
||||
});
|
||||
|
||||
client.user.setActivity({
|
||||
type: ActivityType.Custom,
|
||||
name: "custom",
|
||||
state: `${status[i]} | v${version}`,
|
||||
});
|
||||
|
||||
i = (i + 1) % status.length; // Wrap around to the start when reaching the end
|
||||
}, 30 * 1000); // Every 30 seconds
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {import("../structures/client.js").ExtendedClient} client
|
||||
*/
|
||||
export async function run(client) {
|
||||
logger.ready(client.user.tag + " is online!");
|
||||
}
|
||||
|
||||
export default Ready;
|
||||
|
|
64
src/events_OLD/Ready.js
Normal file
64
src/events_OLD/Ready.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { ActivityType } from "discord.js";
|
||||
import BaseEvent from "../base/BaseEvent";
|
||||
|
||||
class Ready extends BaseEvent {
|
||||
constructor() {
|
||||
super({
|
||||
name: "ready",
|
||||
once: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("../base/Client")} client
|
||||
*/
|
||||
async execute(client) {
|
||||
const commands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()];
|
||||
let servers = client.guilds.cache.size;
|
||||
let users = 0;
|
||||
|
||||
client.guilds.cache.forEach(g => {
|
||||
users += g.memberCount;
|
||||
});
|
||||
|
||||
const birthdays = require("../helpers/birthdays");
|
||||
birthdays.init(client);
|
||||
|
||||
const checkReminds = require("../helpers/checkReminds");
|
||||
checkReminds.init(client);
|
||||
|
||||
client.logger.ready(`Loaded a total of ${commands.length} command(s).`);
|
||||
client.logger.ready(`${client.user.getUsername()}, ready to serve ${users} members in ${servers} servers.`);
|
||||
console.timeEnd("botReady");
|
||||
|
||||
const version = require("../package.json").version;
|
||||
const status = [
|
||||
`${commands.length} ${client.functions.getNoun(commands.length, client.translate("misc:NOUNS:COMMANDS:1"), client.translate("misc:NOUNS:COMMANDS:2"), client.translate("misc:NOUNS:COMMANDS:5"))} available!`,
|
||||
`I'm in ${servers} ${client.functions.getNoun(servers, client.translate("misc:NOUNS:SERVER:1"), client.translate("misc:NOUNS:SERVER:2"), client.translate("misc:NOUNS:SERVER:5"))}!`,
|
||||
`Cached ${users} ${client.functions.getNoun(users, client.translate("misc:NOUNS:USERS:1"), client.translate("misc:NOUNS:USERS:2"), client.translate("misc:NOUNS:USERS:5"))}.`,
|
||||
"Use /help for commands list!",
|
||||
"Did you know that I have a brother called JaBa IT? Yeah! Ask Jonny about him.",
|
||||
];
|
||||
|
||||
let i = 0;
|
||||
setInterval(async () => {
|
||||
servers = (await client.guilds.fetch()).size;
|
||||
users = 0;
|
||||
|
||||
client.guilds.cache.forEach(g => {
|
||||
users += g.memberCount;
|
||||
});
|
||||
|
||||
client.user.setActivity({
|
||||
type: ActivityType.Custom,
|
||||
name: "custom",
|
||||
state: `${status[i]} | v${version}`,
|
||||
});
|
||||
|
||||
i = (i + 1) % status.length; // Wrap around to the start when reaching the end
|
||||
}, 30 * 1000); // Every 30 seconds
|
||||
}
|
||||
}
|
||||
|
||||
export default Ready;
|
|
@ -1,8 +0,0 @@
|
|||
export const data = {
|
||||
name: "8ball",
|
||||
description: "8ball",
|
||||
};
|
||||
|
||||
export const run = () => {
|
||||
console.log("8ball");
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
import logger from "../helpers/logger.js";
|
||||
|
||||
export const data = {
|
||||
name: "ready",
|
||||
once: true,
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("../base/Client.JaBaClient")} client
|
||||
*/
|
||||
export async function run(client) {
|
||||
logger.log(client.user.tag + " is online!");
|
||||
}
|
Loading…
Reference in a new issue