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,8 +405,10 @@ 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];
outLines.push(
formatMessage({ formatMessage({
channel: msg.channel, channel: msg.channel,
name: msg.author.username, name: msg.author.username,
@ -411,11 +427,12 @@ function processMessage(msg, options = {}) {
(msg.mentionsEveryone || (msg.mentionsEveryone ||
msg.mentions.find((user) => user.id == comcord.client.user.id)), msg.mentions.find((user) => user.id == comcord.client.user.id)),
...options, ...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,