history now does lines and not messages

This commit is contained in:
Cynthia Foxwell 2023-06-20 21:31:20 -06:00
parent b67347b18e
commit 5a0c0e9b67
2 changed files with 43 additions and 24 deletions

View File

@ -10,16 +10,18 @@ async function getHistory(limit = 20, channel = null) {
} }
const messages = await comcord.client.getMessages( const messages = await comcord.client.getMessages(
channel ?? comcord.state.currentChannel, channel ?? comcord.state.currentChannel
{limit}
); );
messages.reverse(); messages.reverse();
console.log("--Beginning-Review".padEnd(72, "-")); console.log("--Beginning-Review".padEnd(72, "-"));
const lines = [];
for (const msg of messages) { for (const msg of messages) {
processMessage(msg, {noColor: true, history: true}); const processedLines = processMessage(msg, {noColor: true, history: true});
if (processedLines) lines.push(...processedLines);
} }
console.log(lines.slice(-limit).join("\n"));
console.log("--Review-Complete".padEnd(73, "-")); console.log("--Review-Complete".padEnd(73, "-"));
} }

View File

@ -176,6 +176,16 @@ function formatMessage({
minutes = dateObj.getUTCMinutes().toString().padStart(2, "0"), minutes = dateObj.getUTCMinutes().toString().padStart(2, "0"),
seconds = dateObj.getUTCSeconds().toString().padStart(2, "0"); seconds = dateObj.getUTCSeconds().toString().padStart(2, "0");
let console = global.console;
const lines = [];
if (history) {
console = {
log: function (...args) {
lines.push(...args.join(" ").split("\n"));
},
};
}
if (name.length + 2 > comcord.state.nameLength) if (name.length + 2 > comcord.state.nameLength)
comcord.state.nameLength = name.length + 2; comcord.state.nameLength = name.length + 2;
@ -343,6 +353,10 @@ function formatMessage({
} }
} }
} }
if (history) {
return lines;
}
} }
function processMessage(msg, options = {}) { function processMessage(msg, options = {}) {
@ -371,7 +385,7 @@ function processMessage(msg, options = {}) {
); );
} else if (msg.content && msg.content.indexOf("\n") > -1) { } else if (msg.content && msg.content.indexOf("\n") > -1) {
if (msg.content.match(REGEX_CODEBLOCK)) { if (msg.content.match(REGEX_CODEBLOCK)) {
formatMessage({ return formatMessage({
channel: msg.channel, channel: msg.channel,
name: msg.author.username, name: msg.author.username,
bot: msg.author.bot, bot: msg.author.bot,
@ -391,31 +405,34 @@ function processMessage(msg, options = {}) {
}); });
} else { } else {
const lines = msg.content.split("\n"); const lines = msg.content.split("\n");
const outLines = [];
for (const index in lines) { for (const index in lines) {
const line = lines[index]; const line = lines[index];
formatMessage({ outLines.push(
channel: msg.channel, formatMessage({
name: msg.author.username, channel: msg.channel,
bot: msg.author.bot, name: msg.author.username,
content: bot: msg.author.bot,
line + content:
(msg.editedTimestamp != null && index == lines.length - 1 line +
? " (edited)" (msg.editedTimestamp != null && index == lines.length - 1
: ""), ? " (edited)"
attachments: index == lines.length - 1 ? msg.attachments : [], : ""),
stickers: index == lines.length - 1 ? msg.stickerItems : [], attachments: index == lines.length - 1 ? msg.attachments : [],
reply: index == 0 ? msg.referencedMessage : null, stickers: index == lines.length - 1 ? msg.stickerItems : [],
timestamp: msg.timestamp, reply: index == 0 ? msg.referencedMessage : null,
mention: timestamp: msg.timestamp,
index == 0 && mention:
(msg.mentionsEveryone || index == 0 &&
msg.mentions.find((user) => user.id == comcord.client.user.id)), (msg.mentionsEveryone ||
...options, msg.mentions.find((user) => user.id == comcord.client.user.id)),
}); ...options,
})
);
} }
} }
} else { } else {
formatMessage({ return formatMessage({
channel: msg.channel, channel: msg.channel,
name: msg.author.username, name: msg.author.username,
bot: msg.author.bot, bot: msg.author.bot,