From 3cc566e6b0bd1d0155fc4d81539c83a9213f81e7 Mon Sep 17 00:00:00 2001 From: Dragory Date: Thu, 28 Mar 2019 04:29:40 +0200 Subject: [PATCH] Re-fetch member info from the API if we can't find a user on a main guild --- src/bot.js | 1 + src/data/threads.js | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/bot.js b/src/bot.js index a8e8efb..05ffec7 100644 --- a/src/bot.js +++ b/src/bot.js @@ -3,6 +3,7 @@ const config = require('./config'); const bot = new Eris.CommandClient(config.token, { getAllUsers: true, + restMode: true, }, { prefix: config.prefix, ignoreSelf: true, diff --git a/src/data/threads.js b/src/data/threads.js index d14c53d..cb1a312 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -4,6 +4,7 @@ const moment = require('moment'); const uuid = require('uuid'); const humanizeDuration = require('humanize-duration'); +const bot = require('../bot'); const knex = require('../knex'); const config = require('../config'); const utils = require('../utils'); @@ -134,29 +135,36 @@ async function createNewThreadForUser(user, quiet = false) { let infoHeader = infoHeaderItems.join(', '); - // Guild info - const guildInfoHeaderItems = new Map(); + // Guild member info const mainGuilds = utils.getMainGuilds(); - mainGuilds.forEach(guild => { - const member = guild.members.get(user.id); - if (! member) return; + for (const guild of mainGuilds) { + let member = guild.members.get(user.id); - const {nickname, joinDate} = getHeaderGuildInfo(member); - guildInfoHeaderItems.set(guild.name, [ - `NICKNAME **${nickname}**`, - `JOINED **${joinDate}** ago` - ]); - }); - - guildInfoHeaderItems.forEach((items, guildName) => { - if (mainGuilds.length === 1) { - infoHeader += `\n${items.join(', ')}`; - } else { - infoHeader += `\n**[${guildName}]** ${items.join(', ')}`; + if (! member) { + try { + member = await bot.getRESTGuildMember(guild.id, user.id); + } catch (e) { + continue; + } } - }); + if (member) { + const {nickname, joinDate} = getHeaderGuildInfo(member); + const headerStr = [ + `NICKNAME **${nickname}**`, + `JOINED **${joinDate}** ago` + ].join(', '); + + if (mainGuilds.length === 1) { + infoHeader += `\n${headerStr}`; + } else { + infoHeader += `\n**[${guild.name}]** ${headerStr}`; + } + } + } + + // ModMail history / previous logs const userLogCount = await getClosedThreadCountByUserId(user.id); if (userLogCount > 0) { infoHeader += `\n\nThis user has **${userLogCount}** previous modmail threads. Use \`${config.prefix}logs\` to see them.`;