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 { AbstractUserDatabase } = require("../interfaces/");
|
||||
const { User } = require("../structures");
|
||||
|
||||
@ -10,7 +12,7 @@ class UserDatabase extends AbstractUserDatabase {
|
||||
this.db = db;
|
||||
this.collectionName = userColl;
|
||||
this.logger = server.createLogger(this);
|
||||
this.cache = new Map();
|
||||
this.cache = new Collection();
|
||||
this.collection = null;
|
||||
|
||||
}
|
||||
@ -62,10 +64,13 @@ class UserDatabase extends AbstractUserDatabase {
|
||||
* @memberof UserDatabase
|
||||
*/
|
||||
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})`);
|
||||
user = this._createUser({ type: 'user', name: profile.username });
|
||||
user.addExternalProfile('discord', profile);
|
||||
|
Loading…
Reference in New Issue
Block a user