Re-fetch member info from the API if we can't find a user on a main guild

master
Dragory 2019-03-28 04:29:40 +02:00
parent 846f33bdf1
commit 3cc566e6b0
2 changed files with 27 additions and 18 deletions

View File

@ -3,6 +3,7 @@ const config = require('./config');
const bot = new Eris.CommandClient(config.token, { const bot = new Eris.CommandClient(config.token, {
getAllUsers: true, getAllUsers: true,
restMode: true,
}, { }, {
prefix: config.prefix, prefix: config.prefix,
ignoreSelf: true, ignoreSelf: true,

View File

@ -4,6 +4,7 @@ const moment = require('moment');
const uuid = require('uuid'); const uuid = require('uuid');
const humanizeDuration = require('humanize-duration'); const humanizeDuration = require('humanize-duration');
const bot = require('../bot');
const knex = require('../knex'); const knex = require('../knex');
const config = require('../config'); const config = require('../config');
const utils = require('../utils'); const utils = require('../utils');
@ -134,29 +135,36 @@ async function createNewThreadForUser(user, quiet = false) {
let infoHeader = infoHeaderItems.join(', '); let infoHeader = infoHeaderItems.join(', ');
// Guild info // Guild member info
const guildInfoHeaderItems = new Map();
const mainGuilds = utils.getMainGuilds(); const mainGuilds = utils.getMainGuilds();
mainGuilds.forEach(guild => { for (const guild of mainGuilds) {
const member = guild.members.get(user.id); let member = guild.members.get(user.id);
if (! member) return;
if (! member) {
try {
member = await bot.getRESTGuildMember(guild.id, user.id);
} catch (e) {
continue;
}
}
if (member) {
const {nickname, joinDate} = getHeaderGuildInfo(member); const {nickname, joinDate} = getHeaderGuildInfo(member);
guildInfoHeaderItems.set(guild.name, [ const headerStr = [
`NICKNAME **${nickname}**`, `NICKNAME **${nickname}**`,
`JOINED **${joinDate}** ago` `JOINED **${joinDate}** ago`
]); ].join(', ');
});
guildInfoHeaderItems.forEach((items, guildName) => {
if (mainGuilds.length === 1) { if (mainGuilds.length === 1) {
infoHeader += `\n${items.join(', ')}`; infoHeader += `\n${headerStr}`;
} else { } else {
infoHeader += `\n**[${guildName}]** ${items.join(', ')}`; infoHeader += `\n**[${guild.name}]** ${headerStr}`;
}
}
} }
});
// ModMail history / previous logs
const userLogCount = await getClosedThreadCountByUserId(user.id); const userLogCount = await getClosedThreadCountByUserId(user.id);
if (userLogCount > 0) { if (userLogCount > 0) {
infoHeader += `\n\nThis user has **${userLogCount}** previous modmail threads. Use \`${config.prefix}logs\` to see them.`; infoHeader += `\n\nThis user has **${userLogCount}** previous modmail threads. Use \`${config.prefix}logs\` to see them.`;