Lanbot_Music_V12/util/functions.js
2022-01-04 01:35:59 +00:00

34 lines
1.1 KiB
JavaScript

const mongoose = require("mongoose");
const { Guild, User, Ticket } = require("../models/index");
module.exports = client => {
client.createGuild = async guild => {
const merged = Object.assign({ _id: mongoose.Types.ObjectId() }, guild);
const createGuild = await new Guild(merged);
createGuild.save()
.then(g => console.log(`Nouveau serveur -> ${g.guildName}`));
};
client.getGuild = async guild => {
const data = await Guild.findOne({ guildID: guild.id });
if (data) return data;
return client.config.DEFAULTSETTINGS;
};
client.updateGuild = async (guild, settings) => {
let data = await client.getGuild(guild);
if (typeof data !== "object") data = {};
for (const key in settings) {
if (data[key] !== settings[key]) data[key] = settings[key];
}
return data.updateOne(settings);
};
client.deleteGuild = async guild => {
const guilde = await client.getGuild(guild)
await guilde.delete()
};
};