This commit is contained in:
Cynthia Foxwell 2023-06-20 22:34:42 -06:00
parent 5a0c0e9b67
commit e0e4f3802c
2 changed files with 105 additions and 20 deletions

View file

@ -50,10 +50,11 @@ You **MUST** grant your bot all Privileged Gateway Intents.
- [x] AFK toggle (A) - [x] AFK toggle (A)
- [x] Send DM (s) - [x] Send DM (s)
- [x] Answer DM (a) - [x] Answer DM (a)
- [x] Peek (p)
- [x] Message Receiving - [x] Message Receiving
- [x] Markdown styling - [x] Markdown styling
- [ ] Common markdown (bold, italic, etc) - [x] Common markdown (bold, italic, etc)
- [ ] Figure out how spoilers would work - [x] Figure out how spoilers would work
- [x] Emotes????? - [x] Emotes?????
- [x] Timestamp parsing - [x] Timestamp parsing
- [x] Mentions parsing - [x] Mentions parsing

View file

@ -11,6 +11,16 @@ const REGEX_CHANNEL = /<#(\d+)>/g;
const REGEX_EMOTE = /<(?:\u200b|&)?a?:(\w+):(\d+)>/g; const REGEX_EMOTE = /<(?:\u200b|&)?a?:(\w+):(\d+)>/g;
const REGEX_COMMAND = /<\/([^\s]+?):(\d+)>/g; const REGEX_COMMAND = /<\/([^\s]+?):(\d+)>/g;
const REGEX_BLOCKQUOTE = /^ *>>?>? +/;
const REGEX_GREENTEXT = /^(>.+?)(?:\n|$)/;
const REGEX_SPOILER = /\|\|(.+?)\|\|/;
const REGEX_BOLD = /\*\*(.+?)\*\*/g;
const REGEX_UNDERLINE = /__(.+?)__/g;
const REGEX_ITALIC_1 = /\*(.+?)\*/g;
const REGEX_ITALIC_2 = /_(.+?)_/g;
const REGEX_STRIKE = /~~(.+?)~~/g;
const REGEX_3Y3 = /[\u{e0020}-\u{e007e}]{1,}/gu;
function readableTime(time) { function readableTime(time) {
const seconds = time / 1000; const seconds = time / 1000;
const minutes = seconds / 60; const minutes = seconds / 60;
@ -154,6 +164,37 @@ function replaceTimestamps(_, time, format = "f") {
return TIME_FORMATS[format](time * 1000); return TIME_FORMATS[format](time * 1000);
} }
function replaceStyledMarkdown(content) {
content = content.replace(REGEX_BLOCKQUOTE, chalk.blackBright("\u258e"));
content = content.replace(REGEX_GREENTEXT, (orig) => chalk.green(orig));
if (comcord.config.enable3y3) {
content = content.replace(REGEX_3Y3, (text) =>
chalk.italic.magenta(
[...text]
.map((char) => String.fromCodePoint(char.codePointAt(0) - 0xe0000))
.join("")
)
);
}
content = content.replace(REGEX_SPOILER, (_, text) =>
chalk.bgBlack.black(text)
);
content = content.replace(REGEX_STRIKE, (_, text) =>
chalk.strikethrough(text)
);
content = content.replace(REGEX_BOLD, (_, text) => chalk.bold(text));
content = content.replace(REGEX_UNDERLINE, (_, text) =>
chalk.underline(text)
);
content = content
.replace(REGEX_ITALIC_1, (_, text) => chalk.italic(text))
.replace(REGEX_ITALIC_2, (_, text) => chalk.italic(text));
return content;
}
function formatMessage({ function formatMessage({
channel, channel,
name, name,
@ -223,13 +264,11 @@ function formatMessage({
console.log( console.log(
chalk.bold.white(" \u250d ") + chalk.bold.white(" \u250d ") +
nameColor(`[${reply.author.username}] `) + nameColor(`[${reply.author.username}] `) +
chalk.reset( `${
`${ length > 79
length > 79 ? replyContent.substring(0, 79 - headerLength) + "\u2026"
? replyContent.substring(0, 79 - headerLength) + "\u2026" : replyContent
: replyContent }`
}`
)
); );
} }
} }
@ -272,18 +311,46 @@ function formatMessage({
if (dm) { if (dm) {
if (noColor) { if (noColor) {
if (comcord.config.enable3y3) {
content = content.replace(
REGEX_3Y3,
(text) =>
`<3y3:${[...text]
.map((char) =>
String.fromCodePoint(char.codePointAt(0) - 0xe0000)
)
.join("")}>`
);
}
console.log(`*${name}* ${content}\x07`); console.log(`*${name}* ${content}\x07`);
} else { } else {
console.log( content = replaceStyledMarkdown(content);
chalk.bold.red(`*${name}*`) + chalk.reset(" " + content + "\x07")
); console.log(`${chalk.bold.red(`*${name}*`)} ${content}\x07`);
} }
} else if ( } else if (
(content.length > 1 && content.length > 1 &&
content.startsWith("*") && ((content.startsWith("*") &&
content.endsWith("*")) || content.endsWith("*") &&
(content.startsWith("_") && content.endsWith("_")) !content.startsWith("**") &&
!content.endsWith("**")) ||
(content.startsWith("_") &&
content.endsWith("_") &&
!content.startsWith("__") &&
!content.endsWith("__")))
) { ) {
if (comcord.config.enable3y3) {
content = content.replace(
REGEX_3Y3,
(text) =>
`<3y3:${[...text]
.map((char) =>
String.fromCodePoint(char.codePointAt(0) - 0xe0000)
)
.join("")}>`
);
}
const str = `<${name} ${content.substring(1, content.length - 1)}>`; const str = `<${name} ${content.substring(1, content.length - 1)}>`;
if (noColor) { if (noColor) {
console.log(str); console.log(str);
@ -306,6 +373,18 @@ function formatMessage({
} }
} else { } else {
if (noColor) { if (noColor) {
if (comcord.config.enable3y3) {
content = content.replace(
REGEX_3Y3,
(text) =>
`<3y3:${[...text]
.map((char) =>
String.fromCodePoint(char.codePointAt(0) - 0xe0000)
)
.join("")}>`
);
}
console.log( console.log(
`[${name}]${" ".repeat( `[${name}]${" ".repeat(
Math.abs(comcord.state.nameLength - (name.length + 2)) Math.abs(comcord.state.nameLength - (name.length + 2))
@ -318,11 +397,12 @@ function formatMessage({
? chalk.bold.yellow ? chalk.bold.yellow
: chalk.bold.cyan; : chalk.bold.cyan;
content = replaceStyledMarkdown(content);
console.log( console.log(
nameColor(`[${name}]`) + `${nameColor(`[${name}]`)}${" ".repeat(
" ".repeat(Math.abs(comcord.state.nameLength - (name.length + 2))) + Math.abs(comcord.state.nameLength - (name.length + 2))
chalk.reset(" " + content) + )} ${content}${mention ? "\x07" : ""}`
(mention ? "\x07" : "")
); );
} }
} }
@ -357,6 +437,7 @@ function formatMessage({
if (history) { if (history) {
return lines; return lines;
} }
return null;
} }
function processMessage(msg, options = {}) { function processMessage(msg, options = {}) {
@ -375,6 +456,7 @@ function processMessage(msg, options = {}) {
if (msg.time) { if (msg.time) {
console.log(msg.content); console.log(msg.content);
return null;
} else if (msg.ping) { } else if (msg.ping) {
console.log( console.log(
chalk.bold.red( chalk.bold.red(
@ -383,6 +465,7 @@ function processMessage(msg, options = {}) {
} in ${msg.channel.guild?.name ?? "<unknown>"}**\x07` } in ${msg.channel.guild?.name ?? "<unknown>"}**\x07`
) )
); );
return null;
} 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)) {
return formatMessage({ return formatMessage({
@ -430,6 +513,7 @@ function processMessage(msg, options = {}) {
}) })
); );
} }
return outLines;
} }
} else { } else {
return formatMessage({ return formatMessage({