Compare commits

..

No commits in common. "e0e4f3802c90f48c5c07c263f50dd1a78d3cb686" and "05fb6a3437fc4eda4f6b05238d8b9f6763da9c6d" have entirely different histories.

5 changed files with 46 additions and 235 deletions

View file

@ -50,11 +50,10 @@ 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
- [x] Common markdown (bold, italic, etc) - [ ] Common markdown (bold, italic, etc)
- [x] Figure out how spoilers would work - [ ] Figure out how spoilers would work
- [x] Emotes????? - [x] Emotes?????
- [x] Timestamp parsing - [x] Timestamp parsing
- [x] Mentions parsing - [x] Mentions parsing

View file

@ -1,27 +1,24 @@
const {addCommand} = require("../lib/command"); const {addCommand} = require("../lib/command");
const {startPrompt} = require("../lib/prompt"); const {startPrompt} = require("../lib/prompt");
const {processMessage} = require("../lib/messages"); const {processMessage} = require("../lib/messages");
const {listChannels} = require("./listChannels");
async function getHistory(limit = 20, channel = null) { async function getHistory(limit = 20) {
if (!channel && !comcord.state.currentChannel) { if (!comcord.state.currentChannel) {
console.log("<not in a channel>"); console.log("<not in a channel>");
return; return;
} }
const messages = await comcord.client.getMessages( const messages = await comcord.client.getMessages(
channel ?? comcord.state.currentChannel 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) {
const processedLines = processMessage(msg, {noColor: true, history: true}); 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, "-"));
} }
@ -47,35 +44,3 @@ addCommand("R", "extended history", function () {
await getExtendedHistory(input); await getExtendedHistory(input);
}); });
}); });
addCommand("p", "peek at channel", function () {
if (!comcord.state.currentGuild) {
console.log("<not in a guild>");
return;
}
listChannels();
startPrompt(":peek> ", async function (input) {
console.log("");
if (input == "") {
return;
}
let target;
const guild = comcord.client.guilds.get(comcord.state.currentGuild);
const channels = [...guild.channels.values()].filter((c) => c.type == 0);
channels.sort((a, b) => a.position - b.position);
for (const channel of channels) {
if (channel.name.toLowerCase().indexOf(input.toLowerCase()) > -1) {
target = channel.id;
break;
}
}
if (target == null) {
console.log("<channel not found>");
} else {
await getHistory(20, target);
}
});
});

View file

@ -1,7 +1,6 @@
const {addCommand} = require("../lib/command"); const {addCommand} = require("../lib/command");
addCommand("q", "quit comcord", function () { addCommand("q", "quit comcord", function () {
comcord.state.quitting = true;
comcord.client.disconnect({reconnect: false}); comcord.client.disconnect({reconnect: false});
process.exit(0); process.exit(0);
}); });

View file

@ -31,7 +31,6 @@ process.title = "comcord";
global.comcord = { global.comcord = {
config, config,
state: { state: {
connected: true,
rpcConnected: false, rpcConnected: false,
startTime: Date.now(), startTime: Date.now(),
currentGuild: null, currentGuild: null,
@ -119,17 +118,6 @@ client.once("ready", function () {
} }
}); });
client.on("error", function () {}); client.on("error", function () {});
client.on("ready", function () {
if (comcord.state.connected === false) {
console.log("% Reconnected");
}
});
client.on("disconnect", function () {
if (!comcord.state.quitting) {
comcord.state.connected = false;
console.log("% Disconnected, retrying...");
}
});
rpc.on("connected", function () { rpc.on("connected", function () {
comcord.state.rpcConnected = true; comcord.state.rpcConnected = true;
@ -159,21 +147,6 @@ rpc.once("ready", function () {
rpc.on("error", function () {}); rpc.on("error", function () {});
client.on("messageCreate", async function (msg) { client.on("messageCreate", async function (msg) {
if (
(msg.mentions.find((user) => user.id == client.user.id) ||
msg.mentionEveryone) &&
msg.channel.id != comcord.state.currentChannel &&
msg.channel.type !== Constants.ChannelTypes.DM &&
msg.channel.type !== Constants.ChannelTypes.GROUP_DM
) {
const data = {ping: true, channel: msg.channel, author: msg.author};
if (comcord.state.inPrompt) {
comcord.state.messageQueue.push(data);
} else {
processMessage(data);
}
}
if (!msg.author) return; if (!msg.author) return;
if (msg.author.id === client.user.id) return; if (msg.author.id === client.user.id) return;
@ -267,7 +240,6 @@ client.on("messageReactionAdd", async function (msg, emoji, reactor) {
referencedMessage: reply, referencedMessage: reply,
author: reactor?.user ?? client.users.get(reactor.id), author: reactor?.user ?? client.users.get(reactor.id),
timestamp: Date.now(), timestamp: Date.now(),
mentions: [],
content: `*reacted with ${emoji.id ? `:${emoji.name}:` : emoji.name}*`, content: `*reacted with ${emoji.id ? `:${emoji.name}:` : emoji.name}*`,
}; };

View file

@ -3,7 +3,7 @@ const chalk = require("chalk");
const REGEX_CODEBLOCK = /```(?:([a-z0-9_+\-.]+?)\n)?\n*([^\n][^]*?)\n*```/i; const REGEX_CODEBLOCK = /```(?:([a-z0-9_+\-.]+?)\n)?\n*([^\n][^]*?)\n*```/i;
const REGEX_CODEBLOCK_GLOBAL = const REGEX_CODEBLOCK_GLOBAL =
/```(?:[a-z0-9_+\-.]+?\n)?\n*([^\n][^]*?)\n*```/gi; /```(?:([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;
@ -11,16 +11,6 @@ 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;
@ -164,37 +154,6 @@ 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,
@ -204,7 +163,6 @@ function formatMessage({
stickers, stickers,
reply, reply,
timestamp, timestamp,
mention = false,
noColor = false, noColor = false,
dump = false, dump = false,
history = false, history = false,
@ -217,16 +175,6 @@ 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;
@ -264,11 +212,13 @@ 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 `${
? replyContent.substring(0, 79 - headerLength) + "\u2026" length > 79
: replyContent ? replyContent.substring(0, 79 - headerLength) + "\u2026"
}` : replyContent
}`
)
); );
} }
} }
@ -311,46 +261,18 @@ 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 {
content = replaceStyledMarkdown(content); console.log(
chalk.bold.red(`*${name}*`) + chalk.reset(" " + content + "\x07")
console.log(`${chalk.bold.red(`*${name}*`)} ${content}\x07`);
}
} else if (
content.length > 1 &&
((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("")}>`
); );
} }
} else if (
(content.length > 1 &&
content.startsWith("*") &&
content.endsWith("*")) ||
(content.startsWith("_") && content.endsWith("_"))
) {
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);
@ -373,36 +295,19 @@ 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))
)} ${content}` )} ${content}`
); );
} else { } else {
const nameColor = mention const nameColor = bot ? chalk.bold.yellow : chalk.bold.cyan;
? chalk.bold.red
: bot
? chalk.bold.yellow
: chalk.bold.cyan;
content = replaceStyledMarkdown(content);
// TODO: markdown
console.log( console.log(
`${nameColor(`[${name}]`)}${" ".repeat( nameColor(`[${name}]`) +
Math.abs(comcord.state.nameLength - (name.length + 2)) " ".repeat(Math.abs(comcord.state.nameLength - (name.length + 2))) +
)} ${content}${mention ? "\x07" : ""}` chalk.reset(" " + content)
); );
} }
} }
@ -433,11 +338,6 @@ function formatMessage({
} }
} }
} }
if (history) {
return lines;
}
return null;
} }
function processMessage(msg, options = {}) { function processMessage(msg, options = {}) {
@ -456,67 +356,46 @@ function processMessage(msg, options = {}) {
if (msg.time) { if (msg.time) {
console.log(msg.content); console.log(msg.content);
return null;
} else if (msg.ping) {
console.log(
chalk.bold.red(
`**mentioned by ${msg.author?.username ?? "<unknown>"} in #${
msg.channel?.name ?? "<unknown>"
} 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({ formatMessage({
channel: msg.channel, channel: msg.channel,
name: msg.author.username, name: msg.author.username,
bot: msg.author.bot, bot: msg.author.bot,
content: msg.content.replace( content: msg.content.replace(
REGEX_CODEBLOCK_GLOBAL, REGEX_CODEBLOCK_GLOBAL,
(_, content) => content (_, lang, content) => content
), ),
attachments: msg.attachments, attachments: msg.attachments,
stickers: msg.stickerItems, stickers: msg.stickerItems,
reply: msg.referencedMessage, reply: msg.referencedMessage,
timestamp: msg.timestamp, timestamp: msg.timestamp,
mention:
msg.mentionsEveryone ||
msg.mentions.find((user) => user.id == comcord.client.user.id),
dump: true, dump: true,
...options, ...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, bot: msg.author.bot,
bot: msg.author.bot, content:
content: line +
line + (msg.editedTimestamp != null && index == lines.length - 1
(msg.editedTimestamp != null && index == lines.length - 1 ? " (edited)"
? " (edited)" : ""),
: ""), 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, timestamp: msg.timestamp,
timestamp: msg.timestamp, ...options,
mention: });
index == 0 &&
(msg.mentionsEveryone ||
msg.mentions.find((user) => user.id == comcord.client.user.id)),
...options,
})
);
} }
return outLines;
} }
} else { } else {
return formatMessage({ formatMessage({
channel: msg.channel, channel: msg.channel,
name: msg.author.username, name: msg.author.username,
bot: msg.author.bot, bot: msg.author.bot,
@ -525,9 +404,6 @@ function processMessage(msg, options = {}) {
stickers: msg.stickerItems, stickers: msg.stickerItems,
reply: msg.referencedMessage, reply: msg.referencedMessage,
timestamp: msg.timestamp, timestamp: msg.timestamp,
mention:
msg.mentionsEveryone ||
msg.mentions.find((user) => user.id == comcord.client.user.id),
...options, ...options,
}); });
} }