process codeblocks as dumps, minor internal message processing changes
This commit is contained in:
parent
ae5f412d4b
commit
1ec0eb8a6b
3 changed files with 120 additions and 119 deletions
|
@ -17,33 +17,7 @@ async function getHistory(limit = 20) {
|
||||||
console.log("--Beginning-Review".padEnd(72, "-"));
|
console.log("--Beginning-Review".padEnd(72, "-"));
|
||||||
|
|
||||||
for (const msg of messages) {
|
for (const msg of messages) {
|
||||||
if (msg.content.indexOf("\n") > -1) {
|
processMessage(msg, {noColor: true, history: true});
|
||||||
const lines = msg.content.split("\n");
|
|
||||||
for (const index in lines) {
|
|
||||||
const line = lines[index];
|
|
||||||
processMessage({
|
|
||||||
name: msg.author.username,
|
|
||||||
bot: msg.author.bot,
|
|
||||||
content:
|
|
||||||
line +
|
|
||||||
(msg.editedTimestamp != null && index == lines.length - 1
|
|
||||||
? " (edited)"
|
|
||||||
: ""),
|
|
||||||
attachments: index == lines.length - 1 ? msg.attachments : null,
|
|
||||||
reply: index == 0 ? msg.referencedMessage : null,
|
|
||||||
noColor: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
processMessage({
|
|
||||||
name: msg.author.username,
|
|
||||||
bot: msg.author.bot,
|
|
||||||
content: msg.content + (msg.editedTimestamp != null ? " (edited)" : ""),
|
|
||||||
attachments: msg.attachments,
|
|
||||||
reply: msg.referencedMessage,
|
|
||||||
noColor: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("--Review-Complete".padEnd(73, "-"));
|
console.log("--Review-Complete".padEnd(73, "-"));
|
||||||
|
|
44
src/index.js
44
src/index.js
|
@ -60,27 +60,7 @@ client.on("messageCreate", function (msg) {
|
||||||
if (comcord.state.inPrompt) {
|
if (comcord.state.inPrompt) {
|
||||||
comcord.state.messageQueue.push(msg);
|
comcord.state.messageQueue.push(msg);
|
||||||
} else {
|
} else {
|
||||||
if (msg.content.indexOf("\n") > -1) {
|
processMessage(msg);
|
||||||
const lines = msg.content.split("\n");
|
|
||||||
for (const index in lines) {
|
|
||||||
const line = lines[index];
|
|
||||||
processMessage({
|
|
||||||
name: msg.author.username,
|
|
||||||
bot: msg.author.bot,
|
|
||||||
content: line,
|
|
||||||
attachments: index == lines.length - 1 ? msg.attachments : [],
|
|
||||||
reply: index == 0 ? msg.referencedMessage : null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
processMessage({
|
|
||||||
name: msg.author.username,
|
|
||||||
bot: msg.author.bot,
|
|
||||||
content: msg.content,
|
|
||||||
attachments: msg.attachments,
|
|
||||||
reply: msg.referencedMessage,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -93,27 +73,7 @@ client.on("messageUpdate", function (msg, old) {
|
||||||
if (comcord.state.inPrompt) {
|
if (comcord.state.inPrompt) {
|
||||||
comcord.state.messageQueue.push(msg);
|
comcord.state.messageQueue.push(msg);
|
||||||
} else {
|
} else {
|
||||||
if (msg.content.indexOf("\n") > -1) {
|
processMessage(msg);
|
||||||
const lines = msg.content.split("\n");
|
|
||||||
for (const index in lines) {
|
|
||||||
const line = lines[index];
|
|
||||||
processMessage({
|
|
||||||
name: msg.author.username,
|
|
||||||
bot: msg.author.bot,
|
|
||||||
content: line + (index == lines.length - 1 ? " (edited)" : ""),
|
|
||||||
attachments: index == lines.length - 1 ? msg.attachments : [],
|
|
||||||
reply: index == 0 ? msg.referencedMessage : null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
processMessage({
|
|
||||||
name: msg.author.username,
|
|
||||||
bot: msg.author.bot,
|
|
||||||
content: msg.content + " (edited)",
|
|
||||||
attachments: msg.attachments,
|
|
||||||
reply: msg.referencedMessage,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
const chalk = require("chalk");
|
const chalk = require("chalk");
|
||||||
|
|
||||||
|
const REGEX_CODEBLOCK = /```(?:([a-z0-9_+\-.]+?)\n)?\n*([^\n][^]*?)\n*```/i;
|
||||||
|
const REGEX_CODEBLOCK_GLOBAL =
|
||||||
|
/```(?:([a-z0-9_+\-.]+?)\n)?\n*([^\n][^]*?)\n*```/gi;
|
||||||
|
|
||||||
const REGEX_MENTION = /<@!?(\d+)>/g;
|
const REGEX_MENTION = /<@!?(\d+)>/g;
|
||||||
const REGEX_ROLE_MENTION = /<@&?(\d+)>/g;
|
const REGEX_ROLE_MENTION = /<@&?(\d+)>/g;
|
||||||
const REGEX_CHANNEL = /<#(\d+)>/g;
|
const REGEX_CHANNEL = /<#(\d+)>/g;
|
||||||
|
@ -149,7 +153,7 @@ function replaceTimestamps(_, time, format = "f") {
|
||||||
return TIME_FORMATS[format](time * 1000);
|
return TIME_FORMATS[format](time * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processMessage({
|
function formatMessage({
|
||||||
name,
|
name,
|
||||||
content,
|
content,
|
||||||
bot,
|
bot,
|
||||||
|
@ -157,6 +161,8 @@ function processMessage({
|
||||||
stickers,
|
stickers,
|
||||||
reply,
|
reply,
|
||||||
noColor = false,
|
noColor = false,
|
||||||
|
dump = false,
|
||||||
|
history = false,
|
||||||
}) {
|
}) {
|
||||||
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;
|
||||||
|
@ -165,7 +171,6 @@ function processMessage({
|
||||||
const nameColor = reply.author.bot ? chalk.bold.yellow : chalk.bold.cyan;
|
const nameColor = reply.author.bot ? chalk.bold.yellow : chalk.bold.cyan;
|
||||||
|
|
||||||
const headerLength = 5 + reply.author.username.length;
|
const headerLength = 5 + reply.author.username.length;
|
||||||
const length = headerLength + reply.content.length;
|
|
||||||
|
|
||||||
let replyContent = reply.content.replace(/\n/g, " ");
|
let replyContent = reply.content.replace(/\n/g, " ");
|
||||||
replyContent = replyContent
|
replyContent = replyContent
|
||||||
|
@ -175,6 +180,14 @@ function processMessage({
|
||||||
.replace(REGEX_EMOTE, replaceEmotes)
|
.replace(REGEX_EMOTE, replaceEmotes)
|
||||||
.replace(REGEX_COMMAND, replaceCommands)
|
.replace(REGEX_COMMAND, replaceCommands)
|
||||||
.replace(REGEX_TIMESTAMP, replaceTimestamps);
|
.replace(REGEX_TIMESTAMP, replaceTimestamps);
|
||||||
|
if (reply.attachments.length > 0) {
|
||||||
|
replyContent += `<${reply.attachments.length} attachment${
|
||||||
|
reply.attachments.length > 1 ? "s" : ""
|
||||||
|
}>`;
|
||||||
|
replyContent = replyContent.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
const length = headerLength + replyContent.length;
|
||||||
|
|
||||||
if (noColor) {
|
if (noColor) {
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -199,6 +212,34 @@ function processMessage({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dump) {
|
||||||
|
if (history) {
|
||||||
|
const headerLength = 80 - (name.length + 5);
|
||||||
|
console.log(`--- ${name} ${"-".repeat(headerLength)}`);
|
||||||
|
console.log(content);
|
||||||
|
console.log(`--- ${name} ${"-".repeat(headerLength)}`);
|
||||||
|
} else {
|
||||||
|
const wordCount = content.split(" ").length;
|
||||||
|
const lineCount = content.split("\n").length;
|
||||||
|
if (noColor) {
|
||||||
|
console.log(
|
||||||
|
`<${name} DUMPs in ${content.length} characters of ${wordCount} word${
|
||||||
|
wordCount > 1 ? "s" : ""
|
||||||
|
} in ${lineCount} line${lineCount > 1 ? "s" : ""}>`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
chalk.bold.yellow(
|
||||||
|
`<${name} DUMPs in ${
|
||||||
|
content.length
|
||||||
|
} characters of ${wordCount} word${
|
||||||
|
wordCount > 1 ? "s" : ""
|
||||||
|
} in ${lineCount} line${lineCount > 1 ? "s" : ""}>`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
content = content
|
content = content
|
||||||
.replace(REGEX_MENTION, replaceMentions)
|
.replace(REGEX_MENTION, replaceMentions)
|
||||||
.replace(REGEX_ROLE_MENTION, replaceRoles)
|
.replace(REGEX_ROLE_MENTION, replaceRoles)
|
||||||
|
@ -208,7 +249,9 @@ function processMessage({
|
||||||
.replace(REGEX_TIMESTAMP, replaceTimestamps);
|
.replace(REGEX_TIMESTAMP, replaceTimestamps);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(content.length > 1 && content.startsWith("*") && content.endsWith("*")) ||
|
(content.length > 1 &&
|
||||||
|
content.startsWith("*") &&
|
||||||
|
content.endsWith("*")) ||
|
||||||
(content.startsWith("_") && content.endsWith("_"))
|
(content.startsWith("_") && content.endsWith("_"))
|
||||||
) {
|
) {
|
||||||
if (noColor) {
|
if (noColor) {
|
||||||
|
@ -238,6 +281,7 @@ function processMessage({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (attachments) {
|
if (attachments) {
|
||||||
for (const attachment of attachments) {
|
for (const attachment of attachments) {
|
||||||
|
@ -266,39 +310,62 @@ function processMessage({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function processQueue() {
|
function processMessage(msg, options) {
|
||||||
for (const msg of comcord.state.messageQueue) {
|
|
||||||
if (msg.time) {
|
if (msg.time) {
|
||||||
console.log(msg.content);
|
console.log(msg.content);
|
||||||
} else if (msg.content.indexOf("\n") > -1) {
|
} else if (msg.content.indexOf("\n") > -1) {
|
||||||
|
if (msg.content.match(REGEX_CODEBLOCK)) {
|
||||||
|
formatMessage({
|
||||||
|
name: msg.author.username,
|
||||||
|
bot: msg.author.bot,
|
||||||
|
content: msg.content.replace(
|
||||||
|
REGEX_CODEBLOCK_GLOBAL,
|
||||||
|
(_, lang, content) => content
|
||||||
|
),
|
||||||
|
attachments: msg.attachments,
|
||||||
|
stickers: msg.stickerItems,
|
||||||
|
reply: msg.referencedMessage,
|
||||||
|
dump: true,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
const lines = msg.content.split("\n");
|
const lines = msg.content.split("\n");
|
||||||
for (const index in lines) {
|
for (const index in lines) {
|
||||||
const line = lines[index];
|
const line = lines[index];
|
||||||
processMessage({
|
formatMessage({
|
||||||
name: msg.author.username,
|
name: msg.author.username,
|
||||||
bot: msg.author.bot,
|
bot: msg.author.bot,
|
||||||
content: line,
|
content: line,
|
||||||
attachments: index == lines.length - 1 ? msg.attachments : [],
|
attachments: index == lines.length - 1 ? msg.attachments : [],
|
||||||
stickers: index == lines.length - 1 ? msg.stickerItems : [],
|
stickers: index == lines.length - 1 ? msg.stickerItems : [],
|
||||||
reply: index == 0 ? msg.referencedMessage : null,
|
reply: index == 0 ? msg.referencedMessage : null,
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
processMessage({
|
formatMessage({
|
||||||
name: msg.author.username,
|
name: msg.author.username,
|
||||||
bot: msg.author.bot,
|
bot: msg.author.bot,
|
||||||
content: msg.content,
|
content: msg.content,
|
||||||
attachments: msg.attachments,
|
attachments: msg.attachments,
|
||||||
stickers: msg.stickerItems,
|
stickers: msg.stickerItems,
|
||||||
reply: msg.referencedMessage,
|
reply: msg.referencedMessage,
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processQueue() {
|
||||||
|
for (const msg of comcord.state.messageQueue) {
|
||||||
|
processMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
comcord.state.messageQueue.splice(0, comcord.state.messageQueue.length);
|
comcord.state.messageQueue.splice(0, comcord.state.messageQueue.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
processMessage,
|
processMessage,
|
||||||
processQueue,
|
processQueue,
|
||||||
|
formatMessage,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue