oceanic-transcripts
Version:
A nicely formatted html transcript generator for oceanic.js.
69 lines • 3.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildProfiles = buildProfiles;
const oceanic_js_1 = require("oceanic.js");
async function buildProfiles(messages) {
const profiles = {};
let members = null;
try {
members = new Map((await messages[0].channel.guild.fetchMembers()).map((member) => [member.id, member]));
}
catch (error) {
console.error('Failed to fetch members in bulk, will fetch individually as needed.', error);
}
async function getMember(userId, members, channel) {
if (members) {
return members.get(userId) || null;
}
else {
return await channel.guild.getMember(userId).catch(() => null);
}
}
// loop through messages
for (const message of messages) {
// Adjusted calls to getMember to pass the necessary parameters
const channel = message.channel;
// add all users
const author = message.author;
if (!profiles[author.id]) {
const member = await getMember(author.id, members, channel);
profiles[author.id] = await buildProfile(member, author);
}
// add interaction users
if (message.interactionMetadata) {
const user = message.interactionMetadata.user;
if (!profiles[user.id]) {
const member = await getMember(user.id, members, channel);
profiles[user.id] = await buildProfile(member, user);
}
}
// threads
if (message.thread && message.thread.lastMessage) {
const threadAuthor = message.thread.lastMessage.author;
if (!profiles[threadAuthor.id]) {
const member = await getMember(threadAuthor.id, members, channel);
profiles[threadAuthor.id] = await buildProfile(member, threadAuthor);
}
}
}
// return as a JSON
return profiles;
}
async function buildProfile(member, author) {
var _a, _b, _c, _d, _e;
const guild = member === null || member === void 0 ? void 0 : member.guild;
const roles = await (guild === null || guild === void 0 ? void 0 : guild.getRoles());
const highestRoleColor = roles === null || roles === void 0 ? void 0 : roles.sort((a, b) => b.position - a.position).find((role) => (member === null || member === void 0 ? void 0 : member.roles.includes(role.id)) && role.color);
const highestRoleIcon = roles === null || roles === void 0 ? void 0 : roles.sort((a, b) => b.position - a.position).find((role) => (member === null || member === void 0 ? void 0 : member.roles.includes(role.id)) && role.icon);
const highestRoleName = roles === null || roles === void 0 ? void 0 : roles.sort((a, b) => b.position - a.position).find((role) => (member === null || member === void 0 ? void 0 : member.roles.includes(role.id)) && role.hoist);
return {
author: (_b = (_a = member === null || member === void 0 ? void 0 : member.nick) !== null && _a !== void 0 ? _a : author.globalName) !== null && _b !== void 0 ? _b : author.username,
avatar: (_c = member === null || member === void 0 ? void 0 : member.avatarURL('jpg', 64)) !== null && _c !== void 0 ? _c : author.avatarURL('jpg', 64),
roleColor: '#' + (highestRoleColor === null || highestRoleColor === void 0 ? void 0 : highestRoleColor.color.toString(16).padStart(6, '0')),
roleIcon: (_d = highestRoleIcon === null || highestRoleIcon === void 0 ? void 0 : highestRoleIcon.icon) !== null && _d !== void 0 ? _d : undefined,
roleName: (_e = highestRoleName === null || highestRoleName === void 0 ? void 0 : highestRoleName.name) !== null && _e !== void 0 ? _e : undefined,
bot: author.bot,
verified: (author.publicFlags & oceanic_js_1.UserFlags.VERIFIED_BOT) !== 0,
};
}
//# sourceMappingURL=buildProfiles.js.map