mirror of
https://github.com/danbulant/Shasha
synced 2026-07-07 12:01:22 +00:00
Improvement: load when present
This commit is contained in:
parent
986ac3e8d6
commit
4281c713cb
1 changed files with 40 additions and 16 deletions
|
|
@ -1,17 +1,24 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Structures, User } = require("discord.js"),
|
const { Structures } = require("discord.js"),
|
||||||
{ database } = require("../database/mongo");
|
{ database } = require("../database/mongo");
|
||||||
|
const { errLog } = require("./functions");
|
||||||
|
|
||||||
Structures.extend("Guild", g => {
|
Structures.extend("Guild", g => {
|
||||||
return class Guild extends g {
|
return class Guild extends g {
|
||||||
constructor(client, data) {
|
constructor(client, data) {
|
||||||
super(client, data);
|
super(client, data);
|
||||||
database.collection("Guild").findOne({document: this.id}).then(r => {
|
this.dbLoaded = false;
|
||||||
|
}
|
||||||
|
async dbLoad() {
|
||||||
|
const ret = await database.collection("Guild").findOne({document: this.id}).then((r, j) => {
|
||||||
|
if (j) return errLog(j, null, this.client);
|
||||||
this.infractions = r?.moderation?.infractions;
|
this.infractions = r?.moderation?.infractions;
|
||||||
this.moderation = r?.moderation?.settings;
|
this.moderation = r?.moderation?.settings;
|
||||||
this.defaultEmbed = r?.settings?.defaultEmbed;
|
this.defaultEmbed = r?.settings?.defaultEmbed;
|
||||||
}).catch(() => {});
|
return this.dbLoaded = true;
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get user infractions
|
* Get user infractions
|
||||||
|
|
@ -38,15 +45,21 @@ Structures.extend("Guild", g => {
|
||||||
}
|
}
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
}
|
}
|
||||||
async setDefaultEmbed(set) {
|
setDefaultEmbed(set) {
|
||||||
await database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e});
|
const ret = database.collection("Guild").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}, (e) => {
|
||||||
this.defaultEmbed = set;
|
if (e) return errLog(e, null, this.client);
|
||||||
return true;
|
this.defaultEmbed = set;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
async setModerationSettings(set) {
|
setModerationSettings(set) {
|
||||||
await database.collection("Guild").updateOne({document:this.id}, {$set:{"moderation.settings": set}}, {upsert: true}).catch(e => {throw e});
|
const ret = database.collection("Guild").updateOne({document:this.id}, {$set:{"moderation.settings": set}}, {upsert: true}, (e) => {
|
||||||
this.moderation = set;
|
if (e) return errLog(e, null, this.client);
|
||||||
return true;
|
this.moderation = set;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -55,12 +68,23 @@ Structures.extend("User", u => {
|
||||||
return class User extends u {
|
return class User extends u {
|
||||||
constructor(client, data) {
|
constructor(client, data) {
|
||||||
super(client, data);
|
super(client, data);
|
||||||
database.collection("User").findOne({document: this.id}).then(r => this.defaultEmbed = r?.settings?.defaultEmbed).catch(() => {});
|
this.dbLoaded = false;
|
||||||
}
|
}
|
||||||
async setDefaultEmbed(set) {
|
async dbLoad() {
|
||||||
await database.collection("User").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}).catch(e => {throw e});
|
const ret = await database.collection("User").findOne({document: this.id}).then((r, j) => {
|
||||||
this.defaultEmbed = set;
|
if (j) return errLog(j, null, this.client);
|
||||||
return true;
|
this.defaultEmbed = r?.settings?.defaultEmbed;
|
||||||
|
return this.dbLoaded = true;
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
setDefaultEmbed(set) {
|
||||||
|
const ret = database.collection("User").updateOne({document: this.id}, {$set:{"settings.defaultEmbed": set}}, {upsert: true}, (e) => {
|
||||||
|
if (e) return errLog(e, null, this.client);
|
||||||
|
this.defaultEmbed = set;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue