rename findOrCreate*Something* functions to get*Something*Data

This commit is contained in:
Jonny_Bro (Nikita) 2024-05-24 23:11:03 +05:00
parent f296eca51a
commit 6e73e504a5
Signed by: jonny_bro
GPG key ID: 3F1ECC04147E9BD8
33 changed files with 89 additions and 89 deletions

View file

@ -304,11 +304,11 @@ class JaBaClient extends Client {
} }
/** /**
* Finds or creates a user in the database based on the provided user ID. * Returns a User data from the database.
* @param {string} userID - The ID of the user to find or create. * @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")>} The user data object, either retrieved from the database or newly created.
*/ */
async findOrCreateUser(userID) { async getUserData(userID) {
let userData = await this.usersData.findOne({ id: userID }); let userData = await this.usersData.findOne({ id: userID });
if (userData) { if (userData) {
@ -327,12 +327,12 @@ class JaBaClient extends Client {
} }
/** /**
* Finds or creates a member in the database based on the provided member ID and guild ID. * Returns a Member data from the database.
* @param {string} memberId - The ID of the member to find or create. * @param {string} memberId - The ID of the member to find or create.
* @param {string} guildId - The ID of the guild the member belongs to. * @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")>} The member data object, either retrieved from the database or newly created.
*/ */
async findOrCreateMember(memberId, guildId) { async getMemberData(memberId, guildId) {
let memberData = await this.membersData.findOne({ guildID: guildId, id: memberId }); let memberData = await this.membersData.findOne({ guildID: guildId, id: memberId });
if (memberData) { if (memberData) {
@ -344,7 +344,7 @@ class JaBaClient extends Client {
await memberData.save(); await memberData.save();
const guildData = await this.findOrCreateGuild(guildId); const guildData = await this.getGuildData(guildId);
if (guildData) { if (guildData) {
guildData.members.push(memberData._id); guildData.members.push(memberData._id);
@ -359,11 +359,11 @@ class JaBaClient extends Client {
} }
/** /**
* Finds or creates a guild in the database based on the provided guild ID. * Returns a Guild data from the database.
* @param {string} guildId - The ID of the guild to find or create. * @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")>} The guild data object, either retrieved from the database or newly created.
*/ */
async findOrCreateGuild(guildId) { async getGuildData(guildId) {
let guildData = await this.guildsData.findOne({ id: guildId }).populate("members"); let guildData = await this.guildsData.findOne({ id: guildId }).populate("members");
if (guildData) { if (guildData) {

View file

@ -33,7 +33,7 @@ class Memes extends BaseCommand {
if (interaction.customId === "memes_select") { if (interaction.customId === "memes_select") {
interaction.deferUpdate(); interaction.deferUpdate();
interaction.guild.data = await client.findOrCreateGuild(interaction.guildId); interaction.guild.data = await client.getGuildData(interaction.guildId);
const tag = interaction.values[0]; const tag = interaction.values[0];
const res = await fetch(`https://meme-api.com/gimme/${tag}`).then(response => response.json()); const res = await fetch(`https://meme-api.com/gimme/${tag}`).then(response => response.json());

View file

@ -90,7 +90,7 @@ class Selectroles extends BaseCommand {
if (interaction.customId === "auto_roles") { if (interaction.customId === "auto_roles") {
interaction.data = []; interaction.data = [];
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); interaction.data.guild = await client.getGuildData(interaction.guildId);
const removed = interaction.component.options.filter(option => { const removed = interaction.component.options.filter(option => {
return !interaction.values.includes(option.value); return !interaction.values.includes(option.value);

View file

@ -68,7 +68,7 @@ class Set extends BaseCommand {
member = interaction.options.getMember("user"); member = interaction.options.getMember("user");
if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true });
const memberData = await client.findOrCreateMember(member.id, interaction.guildId); const memberData = await client.getMemberData(member.id, interaction.guildId);
const int = interaction.options.getInteger("int"); const int = interaction.options.getInteger("int");
if (int < 0) return interaction.error("administration/set:INVALID_NUMBER", null, { ephemeral: true }); if (int < 0) return interaction.error("administration/set:INVALID_NUMBER", null, { ephemeral: true });

View file

@ -39,7 +39,7 @@ class Achievements extends BaseCommand {
const user = interaction.options.getUser("user") || interaction.member; const user = interaction.options.getUser("user") || interaction.member;
if (user.bot) return interaction.error("economy/profile:BOT_USER"); if (user.bot) return interaction.error("economy/profile:BOT_USER");
const userData = user.id === interaction.user.id ? interaction.data.user : await client.findOrCreateUser(user.id); const userData = user.id === interaction.user.id ? interaction.data.user : await client.getUserData(user.id);
const embed = client.embed({ const embed = client.embed({
author: { author: {

View file

@ -36,7 +36,7 @@ class Divorce extends BaseCommand {
await userData.save(); await userData.save();
const oldLover = await client.findOrCreateUser(user.id); const oldLover = await client.getUserData(user.id);
oldLover.lover = null; oldLover.lover = null;
await oldLover.save(); await oldLover.save();

View file

@ -46,7 +46,7 @@ class Marry extends BaseCommand {
if (member.user.bot) return interaction.error("economy/marry:BOT_USER"); if (member.user.bot) return interaction.error("economy/marry:BOT_USER");
if (member.id === interaction.member.id) return interaction.error("economy/marry:YOURSELF"); if (member.id === interaction.member.id) return interaction.error("economy/marry:YOURSELF");
const otherUserData = await client.findOrCreateUser(member.id); const otherUserData = await client.getUserData(member.id);
if (otherUserData.lover) return interaction.error("economy/marry:ALREADY_MARRIED_USER", { user: member.toString() }); if (otherUserData.lover) return interaction.error("economy/marry:ALREADY_MARRIED_USER", { user: member.toString() });
for (const requester in pendings) { for (const requester in pendings) {

View file

@ -41,13 +41,13 @@ class Money extends BaseCommand {
const member = interaction.options.getMember("user") || interaction.member; const member = interaction.options.getMember("user") || interaction.member;
if (member.user.bot) return interaction.error("economy/money:BOT_USER"); if (member.user.bot) return interaction.error("economy/money:BOT_USER");
const memberData = member.id === interaction.user.id ? interaction.data.member : await client.findOrCreateMember(member.id, interaction.guildId); const memberData = member.id === interaction.user.id ? interaction.data.member : await client.getMemberData(member.id, interaction.guildId);
const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id)); const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id));
let globalMoney = 0; let globalMoney = 0;
await client.functions.asyncForEach(guilds, async guild => { await client.functions.asyncForEach(guilds, async guild => {
const data = await client.findOrCreateMember(member.id, guild.id); const data = await client.getMemberData(member.id, guild.id);
globalMoney += data.money + data.bankSold; globalMoney += data.money + data.bankSold;
}); });

View file

@ -59,7 +59,7 @@ class Pay extends BaseCommand {
amount: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDITS:1"), interaction.translate("misc:NOUNS:CREDITS:2"), interaction.translate("misc:NOUNS:CREDITS:5"))}`, amount: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDITS:1"), interaction.translate("misc:NOUNS:CREDITS:2"), interaction.translate("misc:NOUNS:CREDITS:5"))}`,
}); });
const otherMemberData = await client.findOrCreateMember(otherMember.id, interaction.guildId); const otherMemberData = await client.getMemberData(otherMember.id, interaction.guildId);
memberData.money -= amount; memberData.money -= amount;
otherMemberData.money += amount; otherMemberData.money += amount;

View file

@ -41,14 +41,14 @@ class Profile extends BaseCommand {
const member = interaction.options.getMember("user") || interaction.member; const member = interaction.options.getMember("user") || interaction.member;
if (member.user.bot) return interaction.error("economy/profile:BOT_USER"); if (member.user.bot) return interaction.error("economy/profile:BOT_USER");
const memberData = member.id === interaction.user.id ? interaction.data.member : await client.findOrCreateMember(member.id, interaction.guildId); const memberData = member.id === interaction.user.id ? interaction.data.member : await client.getMemberData(member.id, interaction.guildId);
const userData = member.id === interaction.user.id ? interaction.data.user : await client.findOrCreateUser(member.id); const userData = member.id === interaction.user.id ? interaction.data.user : await client.getUserData(member.id);
if (userData.lover && !client.users.cache.find(u => u.id === userData.lover)) await client.users.fetch(userData.lover, true); if (userData.lover && !client.users.cache.find(u => u.id === userData.lover)) await client.users.fetch(userData.lover, true);
const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id)); const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id));
let globalMoney = 0; let globalMoney = 0;
await client.functions.asyncForEach(guilds, async guild => { await client.functions.asyncForEach(guilds, async guild => {
const data = await client.findOrCreateMember(member.id, guild.id); const data = await client.getMemberData(member.id, guild.id);
globalMoney += data.money + data.bankSold; globalMoney += data.money + data.bankSold;
}); });

View file

@ -56,7 +56,7 @@ class Rep extends BaseCommand {
userData.cooldowns.rep = toWait; userData.cooldowns.rep = toWait;
const otherUserData = await client.findOrCreateUser(user.id); const otherUserData = await client.getUserData(user.id);
otherUserData.rep++; otherUserData.rep++;

View file

@ -55,7 +55,7 @@ class Rob extends BaseCommand {
const amount = interaction.options.getInteger("amount"); const amount = interaction.options.getInteger("amount");
if (amount <= 0) return interaction.error("misc:MORE_THAN_ZERO"); if (amount <= 0) return interaction.error("misc:MORE_THAN_ZERO");
const otherMemberData = await client.findOrCreateMember(otherMember.id, interaction.guildId); const otherMemberData = await client.getMemberData(otherMember.id, interaction.guildId);
if (amount > otherMemberData.money) return interaction.error("economy/rob:NOT_ENOUGH_MEMBER", { user: otherMember.toString() }); if (amount > otherMemberData.money) return interaction.error("economy/rob:NOT_ENOUGH_MEMBER", { user: otherMember.toString() });
const isInCooldown = otherMemberData.cooldowns.rob || 0; const isInCooldown = otherMemberData.cooldowns.rob || 0;

View file

@ -80,7 +80,7 @@ class Number extends BaseCommand {
}), }),
}); });
const memberData = await client.findOrCreateMember(msg.author.id, interaction.guildId); const memberData = await client.getMemberData(msg.author.id, interaction.guildId);
memberData.money += won; memberData.money += won;

View file

@ -43,7 +43,7 @@ class TicTacToe extends BaseCommand {
embedColor: client.config.embed.color, embedColor: client.config.embed.color,
embedFoot: client.config.embed.footer, embedFoot: client.config.embed.footer,
}).then(async winner => { }).then(async winner => {
const memberData = await client.findOrCreateMember(winner.id, interaction.guildId); const memberData = await client.getMemberData(winner.id, interaction.guildId);
memberData.money += 100; memberData.money += 100;

View file

@ -31,7 +31,7 @@ class Boosters extends BaseCommand {
if (interaction.customId.startsWith("boosters_")) { if (interaction.customId.startsWith("boosters_")) {
interaction.data = []; interaction.data = [];
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); interaction.data.guild = await client.getGuildData(interaction.guildId);
const boosters = (await interaction.guild.members.fetch()).filter(m => m.premiumSince), const boosters = (await interaction.guild.members.fetch()).filter(m => m.premiumSince),
embeds = generateBoostersEmbeds(interaction, boosters); embeds = generateBoostersEmbeds(interaction, boosters);

View file

@ -43,7 +43,7 @@ class Help extends BaseCommand {
await interaction.deferUpdate(); await interaction.deferUpdate();
interaction.data = []; interaction.data = [];
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); interaction.data.guild = await client.getGuildData(interaction.guildId);
const arg = interaction?.values[0]; const arg = interaction?.values[0];
const categoryCommands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()] const categoryCommands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()]

View file

@ -31,8 +31,8 @@ class Reminds extends BaseCommand {
if (interaction.customId.startsWith("reminds_")) { if (interaction.customId.startsWith("reminds_")) {
interaction.data = []; interaction.data = [];
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); interaction.data.guild = await client.getGuildData(interaction.guildId);
interaction.data.user = await client.findOrCreateUser(interaction.user.id); interaction.data.user = await client.getUserData(interaction.user.id);
const reminds = interaction.data.user.reminds, const reminds = interaction.data.user.reminds,
embeds = generateRemindsEmbeds(interaction, reminds); embeds = generateRemindsEmbeds(interaction, reminds);

View file

@ -40,7 +40,7 @@ class Clearwarns extends BaseCommand {
async execute(client, interaction) { async execute(client, interaction) {
const member = interaction.options.getMember("user"); const member = interaction.options.getMember("user");
const memberData = await client.findOrCreateMember(member.id, interaction.guildId); const memberData = await client.getMemberData(member.id, interaction.guildId);
memberData.sanctions = []; memberData.sanctions = [];

View file

@ -32,7 +32,7 @@ class WarnContext extends BaseCommand {
if (member.id === interaction.member.id) return interaction.error("moderation/warn:YOURSELF", null, { ephemeral: true }); if (member.id === interaction.member.id) return interaction.error("moderation/warn:YOURSELF", null, { ephemeral: true });
if (interaction.guild.ownerId !== interaction.member.id && !(moderationPosition > memberPosition)) return interaction.error("moderation/warn:SUPERIOR", null, { ephemeral: true }); if (interaction.guild.ownerId !== interaction.member.id && !(moderationPosition > memberPosition)) return interaction.error("moderation/warn:SUPERIOR", null, { ephemeral: true });
const memberData = await client.findOrCreateMember(member.id, interaction.guildId); const memberData = await client.getMemberData(member.id, interaction.guildId);
const modal = new ModalBuilder() const modal = new ModalBuilder()
.setCustomId("warn_modal") .setCustomId("warn_modal")

View file

@ -41,7 +41,7 @@ class Warns extends BaseCommand {
const member = interaction.options.getMember("user"); const member = interaction.options.getMember("user");
if (member.user.bot) return interaction.error("misc:BOT_USER"); if (member.user.bot) return interaction.error("misc:BOT_USER");
const memberData = await client.findOrCreateMember(member.id, interaction.guildId); const memberData = await client.getMemberData(member.id, interaction.guildId);
const embed = client.embed({ const embed = client.embed({
author: { author: {

View file

@ -31,7 +31,7 @@ class Nowplaying extends BaseCommand {
if (!interaction.isButton()) return; if (!interaction.isButton()) return;
if (interaction.customId.startsWith("nowp_")) { if (interaction.customId.startsWith("nowp_")) {
const locale = (await client.findOrCreateGuild(interaction.guildId)).language; const locale = (await client.getGuildData(interaction.guildId)).language;
const voice = interaction.member.voice.channel; const voice = interaction.member.voice.channel;
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { locale }); if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { locale });

View file

@ -30,7 +30,7 @@ class Queue extends BaseCommand {
if (!interaction.isButton()) return; if (!interaction.isButton()) return;
if (interaction.customId.startsWith("queue_")) { if (interaction.customId.startsWith("queue_")) {
const locale = (await client.findOrCreateGuild(interaction.guildId)).language; const locale = (await client.getGuildData(interaction.guildId)).language;
const queue = client.player.nodes.get(interaction.guildId); const queue = client.player.nodes.get(interaction.guildId);
if (!queue) return interaction.error("music/play:NOT_PLAYING", null, locale); if (!queue) return interaction.error("music/play:NOT_PLAYING", null, locale);

View file

@ -34,7 +34,7 @@ class NSFW extends BaseCommand {
await interaction.deferUpdate(); await interaction.deferUpdate();
interaction.data = []; interaction.data = [];
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); interaction.data.guild = await client.getGuildData(interaction.guildId);
const tag = interaction?.values[0], const tag = interaction?.values[0],
splitted = tag.split("_"), splitted = tag.split("_"),

View file

@ -128,8 +128,8 @@ class Debug extends BaseCommand {
const member = interaction.options.getMember("user"); const member = interaction.options.getMember("user");
if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true });
const userData = await client.findOrCreateUser(member.id), const userData = await client.getUserData(member.id),
memberData = await client.findOrCreateMember(member.id, interaction.guildId); memberData = await client.getMemberData(member.id, interaction.guildId);
switch (type) { switch (type) {
case "level": { case "level": {
@ -194,8 +194,8 @@ class Debug extends BaseCommand {
const member = interaction.options.getMember("target"); const member = interaction.options.getMember("target");
if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true }); if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true });
const userData = await client.findOrCreateUser(member.id), const userData = await client.getUserData(member.id),
memberData = await client.findOrCreateMember(member.id, interaction.guildId); memberData = await client.getMemberData(member.id, interaction.guildId);
switch (type) { switch (type) {
case "level": { case "level": {

View file

@ -31,7 +31,7 @@ class CreateTicketEmbed extends BaseCommand {
if (!interaction.isButton()) return; if (!interaction.isButton()) return;
interaction.data = []; interaction.data = [];
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId); interaction.data.guild = await client.getGuildData(interaction.guildId);
const guildData = interaction.data.guild, const guildData = interaction.data.guild,
ticketsCategory = guildData.plugins?.tickets?.ticketsCategory, ticketsCategory = guildData.plugins?.tickets?.ticketsCategory,

View file

@ -20,12 +20,12 @@ module.exports = client => [
Ukrainian: "uk-UA", Ukrainian: "uk-UA",
}), }),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.language; return guildData.language;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.language = newData; guildData.language = newData;
@ -45,12 +45,12 @@ module.exports = client => [
optionDescription: "Toggle welcome messages sending", optionDescription: "Toggle welcome messages sending",
optionType: DBD.formTypes.switch(), optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.welcome.enabled; return guildData.plugins.welcome.enabled;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.welcome.enabled = newData; guildData.plugins.welcome.enabled = newData;
@ -65,12 +65,12 @@ module.exports = client => [
optionDescription: "Toggle sending an image with welcome message", optionDescription: "Toggle sending an image with welcome message",
optionType: DBD.formTypes.switch(), optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.welcome.withImage; return guildData.plugins.welcome.withImage;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.welcome.withImage = newData; guildData.plugins.welcome.withImage = newData;
@ -85,12 +85,12 @@ module.exports = client => [
optionDescription: "Change welcome message (You can use {user}, {server} and {membercount} wildcards)", optionDescription: "Change welcome message (You can use {user}, {server} and {membercount} wildcards)",
optionType: DBD.formTypes.input("Welcome, {user}!", 2, 100, false, false), optionType: DBD.formTypes.input("Welcome, {user}!", 2, 100, false, false),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.welcome.message; return guildData.plugins.welcome.message;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.welcome.message = newData !== "" ? newData : null; guildData.plugins.welcome.message = newData !== "" ? newData : null;
@ -105,12 +105,12 @@ module.exports = client => [
optionDescription: "Select a channel for welcome messages", optionDescription: "Select a channel for welcome messages",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.welcome.channel; return guildData.plugins.welcome.channel;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.welcome.channel = newData !== "" ? newData : null; guildData.plugins.welcome.channel = newData !== "" ? newData : null;
@ -132,12 +132,12 @@ module.exports = client => [
optionDescription: "Toggle goodbye messages sending", optionDescription: "Toggle goodbye messages sending",
optionType: DBD.formTypes.switch(), optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.goodbye.enabled; return guildData.plugins.goodbye.enabled;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.goodbye.enabled = newData; guildData.plugins.goodbye.enabled = newData;
@ -152,12 +152,12 @@ module.exports = client => [
optionDescription: "Toggle sending an image with goodbye message", optionDescription: "Toggle sending an image with goodbye message",
optionType: DBD.formTypes.switch(), optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.goodbye.withImage; return guildData.plugins.goodbye.withImage;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.goodbye.withImage = newData; guildData.plugins.goodbye.withImage = newData;
@ -172,12 +172,12 @@ module.exports = client => [
optionDescription: "Change goodbye message (You can use {user}, {server} and {membercount} wildcards)", optionDescription: "Change goodbye message (You can use {user}, {server} and {membercount} wildcards)",
optionType: DBD.formTypes.input("goodbye, {user}!", 2, 100, false, false), optionType: DBD.formTypes.input("goodbye, {user}!", 2, 100, false, false),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.goodbye.message; return guildData.plugins.goodbye.message;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.goodbye.message = newData !== "" ? newData : null; guildData.plugins.goodbye.message = newData !== "" ? newData : null;
@ -192,12 +192,12 @@ module.exports = client => [
optionDescription: "Select a channel for goodbye messages", optionDescription: "Select a channel for goodbye messages",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.goodbye.channel; return guildData.plugins.goodbye.channel;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.goodbye.channel = newData !== "" ? newData : null; guildData.plugins.goodbye.channel = newData !== "" ? newData : null;
@ -219,12 +219,12 @@ module.exports = client => [
optionDescription: "Toggle auto role granting for new members", optionDescription: "Toggle auto role granting for new members",
optionType: DBD.formTypes.switch(), optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.autorole.enabled; return guildData.plugins.autorole.enabled;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.autorole.enabled = newData; guildData.plugins.autorole.enabled = newData;
@ -239,12 +239,12 @@ module.exports = client => [
optionDescription: "Select a role for auto role. Select \"-\" to disable", optionDescription: "Select a role for auto role. Select \"-\" to disable",
optionType: DBD.formTypes.rolesSelect(false, false, true), optionType: DBD.formTypes.rolesSelect(false, false, true),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.autorole.role; return guildData.plugins.autorole.role;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.autorole.role = newData !== "" ? newData : null; guildData.plugins.autorole.role = newData !== "" ? newData : null;
@ -266,12 +266,12 @@ module.exports = client => [
optionDescription: "Toggle auto mod. It will remove invite links from non-moderators", optionDescription: "Toggle auto mod. It will remove invite links from non-moderators",
optionType: DBD.formTypes.switch(), optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.automod.enabled; return guildData.plugins.automod.enabled;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.automod.enabled = newData; guildData.plugins.automod.enabled = newData;
@ -286,12 +286,12 @@ module.exports = client => [
optionDescription: "Select a channels for auto mod to ignore", optionDescription: "Select a channels for auto mod to ignore",
optionType: DBD.formTypes.channelsMultiSelect(false, false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsMultiSelect(false, false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.automod.ignored; return guildData.plugins.automod.ignored;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.automod.ignored = newData; guildData.plugins.automod.ignored = newData;
@ -313,12 +313,12 @@ module.exports = client => [
optionDescription: "Select a channel for messages update logs to go to. Select \"-\" to disable", optionDescription: "Select a channel for messages update logs to go to. Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins?.monitoring?.messageUpdate; return guildData.plugins?.monitoring?.messageUpdate;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
if (guildData.plugins.monitoring === undefined) guildData.plugins.monitoring = {}; if (guildData.plugins.monitoring === undefined) guildData.plugins.monitoring = {};
@ -335,12 +335,12 @@ module.exports = client => [
optionDescription: "Select a channel for messages deletion logs to go to. Select \"-\" to disable", optionDescription: "Select a channel for messages deletion logs to go to. Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins?.monitoring?.messageDelete; return guildData.plugins?.monitoring?.messageDelete;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
if (guildData.plugins.monitoring === undefined) guildData.plugins.monitoring = {}; if (guildData.plugins.monitoring === undefined) guildData.plugins.monitoring = {};
@ -364,12 +364,12 @@ module.exports = client => [
optionDescription: "Select a channel for suggestions to go to", optionDescription: "Select a channel for suggestions to go to",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.suggestions; return guildData.plugins.suggestions;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.suggestions = newData !== "" ? newData : null; guildData.plugins.suggestions = newData !== "" ? newData : null;
@ -384,12 +384,12 @@ module.exports = client => [
optionDescription: "Select a channel for reports to go to. Select \"-\" to disable", optionDescription: "Select a channel for reports to go to. Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.reports; return guildData.plugins.reports;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.reports = newData !== "" ? newData : null; guildData.plugins.reports = newData !== "" ? newData : null;
@ -404,12 +404,12 @@ module.exports = client => [
optionDescription: "Select a channel for birthdays message to go to. Select \"-\" to disable", optionDescription: "Select a channel for birthdays message to go to. Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.birthdays; return guildData.plugins.birthdays;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.birthdays = newData !== "" ? newData : null; guildData.plugins.birthdays = newData !== "" ? newData : null;
@ -424,12 +424,12 @@ module.exports = client => [
optionDescription: "Select a channel for moderation logs to go to (warns). Select \"-\" to disable", optionDescription: "Select a channel for moderation logs to go to (warns). Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]), optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => { getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
return guildData.plugins.modlogs; return guildData.plugins.modlogs;
}, },
setNew: async ({ guild, newData }) => { setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
guildData.plugins.modlogs = newData !== "" ? newData : null; guildData.plugins.modlogs = newData !== "" ? newData : null;

View file

@ -19,11 +19,11 @@ class CommandHandler extends BaseEvent {
const data = []; const data = [];
data.user = await client.findOrCreateUser(interaction.user.id); data.user = await client.getUserData(interaction.user.id);
if (interaction.inGuild()) { if (interaction.inGuild()) {
data.guild = await client.findOrCreateGuild(interaction.guildId); data.guild = await client.getGuildData(interaction.guildId);
data.member = await client.findOrCreateMember(interaction.member.id, interaction.guildId); data.member = await client.getMemberData(interaction.member.id, interaction.guildId);
} }
interaction.data = data; interaction.data = data;

View file

@ -14,7 +14,7 @@ class GuildCreate extends BaseEvent {
* @param {import("discord.js").Guild} guild * @param {import("discord.js").Guild} guild
*/ */
async execute(client, guild) { async execute(client, guild) {
const userData = await client.findOrCreateUser(guild.ownerId); const userData = await client.getUserData(guild.ownerId);
if (!userData.achievements.invite.achieved) { if (!userData.achievements.invite.achieved) {
userData.achievements.invite.progress.now = 1; userData.achievements.invite.progress.now = 1;

View file

@ -32,7 +32,7 @@ class GuildMemberAdd extends BaseEvent {
await member.guild.members.fetch(); await member.guild.members.fetch();
const guildData = await client.findOrCreateGuild(member.guild.id); const guildData = await client.getGuildData(member.guild.id);
if (guildData.plugins.autorole.enabled) member.roles.add(guildData.plugins.autorole.role); if (guildData.plugins.autorole.enabled) member.roles.add(guildData.plugins.autorole.role);

View file

@ -32,7 +32,7 @@ class GuildMemberRemove extends BaseEvent {
await member.guild.members.fetch(); await member.guild.members.fetch();
const guildData = await client.findOrCreateGuild(member.guild.id); const guildData = await client.getGuildData(member.guild.id);
if (guildData.plugins.goodbye.enabled) { if (guildData.plugins.goodbye.enabled) {
const channel = member.guild.channels.cache.get(guildData.plugins.goodbye.channel); const channel = member.guild.channels.cache.get(guildData.plugins.goodbye.channel);

View file

@ -20,7 +20,7 @@ class GuildMemberUpdate extends BaseEvent {
if (oldMember.roles.cache.some(r => r.id === "940149470975365191")) return; if (oldMember.roles.cache.some(r => r.id === "940149470975365191")) return;
if (newMember?.roles.cache.some(r => r.id === "940149470975365191")) { if (newMember?.roles.cache.some(r => r.id === "940149470975365191")) {
const userData = await client.findOrCreateUser(newMember.id); const userData = await client.getUserData(newMember.id);
userData.achievements.tip.progress.now = 1; userData.achievements.tip.progress.now = 1;
userData.achievements.tip.achieved = true; userData.achievements.tip.achieved = true;

View file

@ -24,13 +24,13 @@ class MessageCreate extends BaseEvent {
if (message.author.bot) return; if (message.author.bot) return;
if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", null, { mention: true }); if (message.content.match(new RegExp(`^<@!?${client.user.id}>( |)$`))) return message.replyT("misc:HELLO_SERVER", null, { mention: true });
data.user = await client.findOrCreateUser(message.author.id); data.user = await client.getUserData(message.author.id);
if (message.guild) { if (message.guild) {
if (!message.member) await message.guild.members.fetch(message.author.id); if (!message.member) await message.guild.members.fetch(message.author.id);
data.guild = await client.findOrCreateGuild(message.guildId); data.guild = await client.getGuildData(message.guildId);
data.member = await client.findOrCreateMember(message.author.id, message.guildId); data.member = await client.getMemberData(message.author.id, message.guildId);
} }
message.data = data; message.data = data;
@ -106,7 +106,7 @@ class MessageCreate extends BaseEvent {
} }
message.mentions.users.forEach(async u => { message.mentions.users.forEach(async u => {
const userData = await client.findOrCreateUser(u.id); const userData = await client.getUserData(u.id);
if (userData.afk) message.replyT("general/afk:IS_AFK", { user: u.getUsername(), reason: userData.afk }, { ephemeral: true }); if (userData.afk) message.replyT("general/afk:IS_AFK", { user: u.getUsername(), reason: userData.afk }, { ephemeral: true });
}); });

View file

@ -7,7 +7,7 @@ const { CronJob } = require("cron");
module.exports.init = async client => { module.exports.init = async client => {
const cronjob = new CronJob("0 5 * * *", async function () { const cronjob = new CronJob("0 5 * * *", async function () {
client.guilds.cache.forEach(async guild => { client.guilds.cache.forEach(async guild => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
const channel = guildData.plugins.birthdays ? client.channels.cache.get(guildData.plugins.birthdays) || (await client.channels.fetch(guildData.plugins.birthdays)) : null; const channel = guildData.plugins.birthdays ? client.channels.cache.get(guildData.plugins.birthdays) || (await client.channels.fetch(guildData.plugins.birthdays)) : null;
if (guildData.plugins.birthdays && client.channels.cache.get(guildData.plugins.birthdays)) { if (guildData.plugins.birthdays && client.channels.cache.get(guildData.plugins.birthdays)) {
@ -69,7 +69,7 @@ module.exports.init = async client => {
*/ */
module.exports.run = async client => { module.exports.run = async client => {
client.guilds.cache.forEach(async guild => { client.guilds.cache.forEach(async guild => {
const guildData = await client.findOrCreateGuild(guild.id); const guildData = await client.getGuildData(guild.id);
const channel = guildData.plugins.birthdays ? client.channels.cache.get(guildData.plugins.birthdays) || (await client.channels.fetch(guildData.plugins.birthdays)) : null; const channel = guildData.plugins.birthdays ? client.channels.cache.get(guildData.plugins.birthdays) || (await client.channels.fetch(guildData.plugins.birthdays)) : null;
if (guildData.plugins.birthdays) { if (guildData.plugins.birthdays) {