seyfert-html-transcripts
Version:
A nicely formatted html transcript generator for seyfert.
52 lines • 2.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildProfiles = buildProfiles;
const utils_1 = require("./utils");
const types_1 = require("seyfert/lib/types");
async function buildProfiles(messages) {
const profiles = {};
// loop through messages
for (const message of messages) {
// add all users
const author = message.author;
if (!profiles[author.id]) {
// add profile
profiles[author.id] = await buildProfile(message.member, message.guildId, author);
}
// add interaction users
if (message.interactionMetadata) {
const user = await message.client.users.fetch(message.interactionMetadata.user.id);
if (!profiles[user.id]) {
profiles[user.id] = await buildProfile(null, message.guildId, user);
}
}
// threads
if (message.thread && message.thread.lastMessageId) {
const thread = await message.client.messages.fetch(message.thread.lastMessageId, message.channelId);
profiles[thread.author.id] = await buildProfile(thread.member, message.guildId, thread.author);
}
}
// return as a JSON
return profiles;
}
async function buildProfile(member, guildId, author) {
var _a, _b, _c, _d, _e, _f;
await author.fetch();
if (guildId && !member)
member = await author.client.members.fetch(guildId, author.id);
await (member === null || member === void 0 ? void 0 : member.fetch());
const role = await (member === null || member === void 0 ? void 0 : member.roles.highest());
await (role === null || role === void 0 ? void 0 : role.fetch());
const authorName = author.bot ? author.username : author.tag;
const roleColor = (_a = role === null || role === void 0 ? void 0 : role.color) !== null && _a !== void 0 ? _a : author.accentColor;
return {
author: (_b = member === null || member === void 0 ? void 0 : member.nick) !== null && _b !== void 0 ? _b : authorName,
avatar: (_c = member === null || member === void 0 ? void 0 : member.avatarURL({ size: 64 })) !== null && _c !== void 0 ? _c : author.avatarURL({ size: 64 }),
roleColor: roleColor ? (0, utils_1.convertToHEX)(roleColor) : undefined,
roleIcon: (_d = role === null || role === void 0 ? void 0 : role.icon) !== null && _d !== void 0 ? _d : undefined,
roleName: (_e = role === null || role === void 0 ? void 0 : role.name) !== null && _e !== void 0 ? _e : undefined,
bot: author.bot,
verified: ((_f = author.publicFlags) !== null && _f !== void 0 ? _f : 0 & types_1.UserFlags.VerifiedBot) === types_1.UserFlags.VerifiedBot,
};
}
//# sourceMappingURL=buildProfiles.js.map