This commit is contained in:
Jonny_Bro (Nikita) 2023-10-15 15:05:10 +05:00
parent 19a58a9748
commit 92f64e4d94
10 changed files with 52 additions and 131 deletions

View file

@ -277,7 +277,7 @@ class JaBa extends Client {
memberData = new this.membersData({ id: memberID, guildID: guildId });
await memberData.save();
const guildData = await this.findOrCreateGuild({ id: guildId });
const guildData = await this.findOrCreateGuild(guildId);
if (guildData) {
guildData.members.push(memberData._id);
@ -297,7 +297,7 @@ class JaBa extends Client {
* @param {Array} param0 { id: Guild ID }
* @returns {import("./Guild")} Mongoose model or JSON of this guild
*/
async findOrCreateGuild({ id: guildId }) {
async findOrCreateGuild(guildId) {
let guildData = await this.guildsData.findOne({ id: guildId }).populate("members");
if (guildData) {

View file

@ -31,7 +31,7 @@ class CreateTicketEmbed extends BaseCommand {
client.on("interactionCreate", async interaction => {
if (!interaction.isButton()) return;
const guildData = await client.findOrCreateGuild({ id: interaction.guildId });
const guildData = await client.findOrCreateGuild(interaction.guildId);
const ticketsCategory = guildData.plugins.tickets.ticketsCategory,
ticketLogs = guildData.plugins.tickets.ticketLogs,

View file

@ -20,16 +20,12 @@ module.exports = client => [
Ukrainian: "uk-UA",
}),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.language;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.language = newData;
@ -50,16 +46,12 @@ module.exports = client => [
optionDescription: "Toggle welcome messages sending",
optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.welcome.enabled;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.welcome.enabled = newData;
@ -75,16 +67,12 @@ module.exports = client => [
optionDescription: "Toggle sending an image with welcome message",
optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.welcome.withImage;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.welcome.withImage = newData;
@ -100,16 +88,12 @@ module.exports = client => [
optionDescription: "Change welcome message (You can use {user}, {server} and {membercount} wildcards)",
optionType: DBD.formTypes.input("Welcome, {user}!", 2, 100, false, false),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.welcome.message;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.welcome.message = newData !== "" ? newData : null;
@ -125,16 +109,12 @@ module.exports = client => [
optionDescription: "Select a channel for welcome messages",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.welcome.channel;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.welcome.channel = newData !== "" ? newData : null;
@ -157,16 +137,12 @@ module.exports = client => [
optionDescription: "Toggle goodbye messages sending",
optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.goodbye.enabled;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.goodbye.enabled = newData;
@ -182,16 +158,12 @@ module.exports = client => [
optionDescription: "Toggle sending an image with goodbye message",
optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.goodbye.withImage;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.goodbye.withImage = newData;
@ -207,16 +179,12 @@ module.exports = client => [
optionDescription: "Change goodbye message (You can use {user}, {server} and {membercount} wildcards)",
optionType: DBD.formTypes.input("goodbye, {user}!", 2, 100, false, false),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.goodbye.message;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.goodbye.message = newData !== "" ? newData : null;
@ -232,16 +200,12 @@ module.exports = client => [
optionDescription: "Select a channel for goodbye messages",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.goodbye.channel;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.goodbye.channel = newData !== "" ? newData : null;
@ -264,16 +228,12 @@ module.exports = client => [
optionDescription: "Toggle auto role granting for new members",
optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.autorole.enabled;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.autorole.enabled = newData;
@ -289,16 +249,12 @@ module.exports = client => [
optionDescription: "Select a role for auto role. Select \"-\" to disable",
optionType: DBD.formTypes.rolesSelect(false, false, true),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.autorole.role;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.autorole.role = newData !== "" ? newData : null;
@ -321,16 +277,12 @@ module.exports = client => [
optionDescription: "Toggle auto mod. It will remove invite links from non-moderators",
optionType: DBD.formTypes.switch(),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.automod.enabled;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.automod.enabled = newData;
@ -346,16 +298,12 @@ module.exports = client => [
optionDescription: "Select a channels for auto mod to ignore",
optionType: DBD.formTypes.channelsMultiSelect(false, false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.automod.ignored;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.automod.ignored = newData;
@ -378,16 +326,12 @@ module.exports = client => [
optionDescription: "Select a channel for messages update logs to go to. Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins?.monitoring?.messageUpdate;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
if (guildData.plugins.monitoring === undefined) guildData.plugins.monitoring = {};
@ -405,16 +349,12 @@ module.exports = client => [
optionDescription: "Select a channel for messages deletion logs to go to. Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins?.monitoring?.messageDelete;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
if (guildData.plugins.monitoring === undefined) guildData.plugins.monitoring = {};
@ -439,16 +379,12 @@ module.exports = client => [
optionDescription: "Select a channel for suggestions to go to",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.suggestions;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.suggestions = newData !== "" ? newData : null;
@ -464,16 +400,12 @@ module.exports = client => [
optionDescription: "Select a channel for reports to go to. Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.reports;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.reports = newData !== "" ? newData : null;
@ -489,16 +421,12 @@ module.exports = client => [
optionDescription: "Select a channel for birthdays message to go to. Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.birthdays;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.birthdays = newData !== "" ? newData : null;
@ -514,16 +442,12 @@ module.exports = client => [
optionDescription: "Select a channel for moderation logs to go to (warns). Select \"-\" to disable",
optionType: DBD.formTypes.channelsSelect(false, [ChannelType.GuildText]),
getActualSet: async ({ guild }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
return guildData.plugins.modlogs;
},
setNew: async ({ guild, newData }) => {
const guildData = await client.findOrCreateGuild({
id: guild.id,
});
const guildData = await client.findOrCreateGuild(guild.id);
guildData.plugins.modlogs = newData !== "" ? newData : null;

View file

@ -22,7 +22,7 @@ class CommandHandler extends BaseEvent {
data.userData = userData;
if (interaction.inGuild()) {
const guildData = await client.findOrCreateGuild({ id: interaction.guildId });
const guildData = await client.findOrCreateGuild(interaction.guildId);
const memberData = await client.findOrCreateMember({ id: interaction.member.id, guildId: interaction.guildId });
interaction.guild.data = data.guildData = guildData;

View file

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

View file

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

View file

@ -29,7 +29,7 @@ class MessageCreate extends BaseEvent {
if (message.guild && !message.member) await message.guild.members.fetch(message.author.id);
if (message.guild) {
const guildData = await client.findOrCreateGuild({ id: message.guildId });
const guildData = await client.findOrCreateGuild(message.guildId);
const memberData = await client.findOrCreateMember({ id: message.author.id, guildId: message.guildId });
message.guild.data = data.guildData = guildData;

View file

@ -18,7 +18,7 @@ class messageDelete extends BaseEvent {
if (message.guild && message.guildId === "568120814776614924") return;
if (message.author.bot) return;
const guildData = await client.findOrCreateGuild({ id: message.guildId });
const guildData = await client.findOrCreateGuild(message.guildId);
if (guildData.plugins?.monitoring?.messageDelete) {
const embed = new EmbedBuilder()

View file

@ -21,7 +21,7 @@ class messageUpdate extends BaseEvent {
if (oldMessage.content === newMessage.content) return;
const guildData = await client.findOrCreateGuild({ id: oldMessage.guildId });
const guildData = await client.findOrCreateGuild(oldMessage.guildId);
if (guildData.plugins?.monitoring?.messageUpdate) {
const embed = new EmbedBuilder()

View file

@ -6,12 +6,12 @@ const { CronJob } = require("cron"),
* @param {import("../base/JaBa")} client
*/
module.exports.init = async function (client) {
new CronJob("0 5 * * *", async function () {
const cronjob = new CronJob("0 5 * * *", async function () {
client.guilds.cache.forEach(async guild => {
const guildData = await client.findOrCreateGuild({ id: guild.id });
const guildData = await client.findOrCreateGuild(guild.id);
if (guildData.plugins.birthdays) {
const channel = client.channels.cache.get(guildData.plugins.birthdays),
const channel = client.channels.cache.get(guildData.plugins.birthdays) || await client.channels.fetch(guildData.plugins.birthdays),
date = new Date(),
currentDay = date.getDate(),
currentMonth = date.getMonth(),
@ -60,6 +60,7 @@ module.exports.init = async function (client) {
},
null,
true,
"Europe/Moscow",
);
cronjob.start();
};