I'm dum
This commit is contained in:
parent
c7a06f2ca6
commit
3ff0483a84
@ -1,4 +1,6 @@
|
|||||||
|
const { Collection } = require("@discordjs/collection");
|
||||||
const { ObjectId } = require("mongodb");
|
const { ObjectId } = require("mongodb");
|
||||||
|
|
||||||
const { AbstractUserDatabase } = require("../interfaces/");
|
const { AbstractUserDatabase } = require("../interfaces/");
|
||||||
const { User } = require("../structures");
|
const { User } = require("../structures");
|
||||||
|
|
||||||
@ -10,7 +12,7 @@ class UserDatabase extends AbstractUserDatabase {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.collectionName = userColl;
|
this.collectionName = userColl;
|
||||||
this.logger = server.createLogger(this);
|
this.logger = server.createLogger(this);
|
||||||
this.cache = new Map();
|
this.cache = new Collection();
|
||||||
this.collection = null;
|
this.collection = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -62,10 +64,13 @@ class UserDatabase extends AbstractUserDatabase {
|
|||||||
* @memberof UserDatabase
|
* @memberof UserDatabase
|
||||||
*/
|
*/
|
||||||
async userFromDiscord (profile) {
|
async userFromDiscord (profile) {
|
||||||
const data = await this.collection.findOne({ 'discord.id': profile.id });
|
|
||||||
let user = this.cache.get(data._id);
|
|
||||||
|
|
||||||
if (!data) {
|
let user = this.cache.find((u) => u.externalProfiles.discord?.id === profile.id);
|
||||||
|
if (user) return Promise.resolve(user);
|
||||||
|
|
||||||
|
const data = await this.collection.findOne({ 'discord.id': profile.id });
|
||||||
|
if (data) user = this._createUser(data);
|
||||||
|
else {
|
||||||
this.logger.info(`Creating new user from Discord profile: ${profile.username} (${profile.id})`);
|
this.logger.info(`Creating new user from Discord profile: ${profile.username} (${profile.id})`);
|
||||||
user = this._createUser({ type: 'user', name: profile.username });
|
user = this._createUser({ type: 'user', name: profile.username });
|
||||||
user.addExternalProfile('discord', profile);
|
user.addExternalProfile('discord', profile);
|
||||||
|
Loading…
Reference in New Issue
Block a user