functions to fetch uncached users/guilds from REST

This commit is contained in:
Emily 2020-10-25 12:56:30 +11:00
parent 5db9385d97
commit cf793f5332

View file

@ -1,4 +1,4 @@
const { MessageCollector } = require('eris-collector');
// const { MessageCollector } = require('eris-collector');
const { inspect, promisify } = require('util');
class Helpers {
@ -28,20 +28,6 @@ class Helpers {
}
}
async getUser (userID) {
let user = this.client.users.get(userID);
if (!user) try {
console.log('Accessing REST API...');
user = await this.client.getRESTUser(userID);
this.client.users.add(user, this.client);
} catch (err) {
this.client.logger.error('REST_RETRIEVAL_ERROR', `Failed to retrieve a user from the REST API with the ID ${userID} (${err})`);
return;
}
return user;
}
highestRole (member) {
if (member.roles.length === 0) return member.guild.roles.find(r => r.name === '@everyone');
@ -106,6 +92,36 @@ class Helpers {
process.exit();
}
async getUser (id) {
if (this.client.users.has(id)) return this.client.users.get(id);
this.client.logger.debug('REST_FETCH_USER', 'Accessing rest API...');
const user = await this.client.getRESTUser(id).catch(err => {
this.client.logger.error('USER_FETCH_ERROR', err);
});
if (user) {
this.client.users.set(id, user);
return user;
}
return;
}
async getGuild (id) {
if (this.client.guilds.has(id)) return this.client.guilds.get(id);
this.client.logger.debug('REST_FETCH_GUILD', 'Accessing rest API...');
const guild = await this.client.getRESTGuild(id).catch(err => {
this.client.logger.error('GUILD_FETCH_ERROR', err);
});
if (guild) {
this.client.guilds.set(id, guild);
return guild;
}
return;
}
async clean (text) {
if (text && text.constructor.name === 'Promise') {
text = await text;