support for replies

This commit is contained in:
Cynthia Foxwell 2022-08-27 20:57:40 -06:00
parent 3d55bdf31c
commit aeca9294af
2 changed files with 33 additions and 8 deletions

View file

@ -24,9 +24,9 @@ You **MUST** grant your bot all Privileged Gateway Intents.
- [x] Commands - [x] Commands
- [x] Quit (q) - [x] Quit (q)
- [x] Switch guilds (G) - [x] Switch guilds (G)
- [ ] Switch channels (g) - [x] Switch channels (g)
- [x] List online users in guild (w) - [x] List online users in guild (w)
- [ ] Emote (e) - [x] Emote (e)
- Just sends message surrounded in `*`'s - Just sends message surrounded in `*`'s
- [ ] Finger (f) - [ ] Finger (f)
- [ ] Shows presence data if available - [ ] Shows presence data if available

View file

@ -52,9 +52,28 @@ client.once("ready", function () {
listGuilds(); listGuilds();
}); });
function processMessage({name, content, bot, attachments}) { function processMessage({name, content, bot, attachments, reply}) {
if (name.length + 2 > nameLength) nameLength = name.length + 2; if (name.length + 2 > nameLength) nameLength = name.length + 2;
if (reply) {
const nameColor = reply.author.bot ? chalk.bold.yellow : chalk.bold.cyan;
const headerLength = 5 + reply.author.username.length;
const length = headerLength + reply.content.length;
console.log(
chalk.bold.white(" \u250d ") +
nameColor(`[${reply.author.username}] `) +
chalk.reset(
`${
length > 79
? reply.content.substring(0, length - headerLength) + "\u2026"
: reply.content
}`
)
);
}
if ( if (
(content.startsWith("*") && content.endsWith("*")) || (content.startsWith("*") && content.endsWith("*")) ||
(content.startsWith("_") && content.endsWith("_")) (content.startsWith("_") && content.endsWith("_"))
@ -63,8 +82,7 @@ function processMessage({name, content, bot, attachments}) {
chalk.bold.green(`<${name} ${content.substring(1, content.length - 1)}>`) chalk.bold.green(`<${name} ${content.substring(1, content.length - 1)}>`)
); );
} else { } else {
let nameColor = chalk.bold.cyan; const nameColor = bot ? chalk.bold.yellow : chalk.bold.cyan;
if (bot) nameColor = chalk.bold.yellow;
// TODO: markdown // TODO: markdown
console.log( console.log(
@ -72,10 +90,11 @@ function processMessage({name, content, bot, attachments}) {
" ".repeat(nameLength - (name.length + 2)) + " ".repeat(nameLength - (name.length + 2)) +
chalk.reset(" " + content) chalk.reset(" " + content)
); );
}
for (const attachment of attachments) { for (const attachment of attachments) {
console.log(chalk.bold.yellow(`<attachment: ${attachment.url} >`)); console.log(chalk.bold.yellow(`<attachment: ${attachment.url} >`));
} }
}
} }
function processQueue() { function processQueue() {
@ -89,6 +108,7 @@ function processQueue() {
bot: msg.author.bot, bot: msg.author.bot,
content: line, content: line,
attachments: index == lines.length - 1 ? msg.attachments : null, attachments: index == lines.length - 1 ? msg.attachments : null,
reply: index == 0 ? msg.referencedMessage : null,
}); });
} }
} else { } else {
@ -97,6 +117,7 @@ function processQueue() {
bot: msg.author.bot, bot: msg.author.bot,
content: msg.content, content: msg.content,
attachments: msg.attachments, attachments: msg.attachments,
reply: msg.referencedMessage,
}); });
} }
} }
@ -120,6 +141,7 @@ client.on("messageCreate", function (msg) {
bot: msg.author.bot, bot: msg.author.bot,
content: line, content: line,
attachments: index == lines.length - 1 ? msg.attachments : null, attachments: index == lines.length - 1 ? msg.attachments : null,
reply: index == 0 ? msg.referencedMessage : null,
}); });
} }
} else { } else {
@ -128,6 +150,7 @@ client.on("messageCreate", function (msg) {
bot: msg.author.bot, bot: msg.author.bot,
content: msg.content, content: msg.content,
attachments: msg.attachments, attachments: msg.attachments,
reply: msg.referencedMessage,
}); });
} }
} }
@ -151,6 +174,7 @@ client.on("messageUpdate", function (msg, old) {
bot: msg.author.bot, bot: msg.author.bot,
content: line + index == lines.length - 1 ? " (edited)" : null, content: line + index == lines.length - 1 ? " (edited)" : null,
attachments: index == lines.length - 1 ? msg.attachments : null, attachments: index == lines.length - 1 ? msg.attachments : null,
reply: index == 0 ? msg.referencedMessage : null,
}); });
} }
} else { } else {
@ -159,6 +183,7 @@ client.on("messageUpdate", function (msg, old) {
bot: msg.author.bot, bot: msg.author.bot,
content: msg.content + " (edited)", content: msg.content + " (edited)",
attachments: msg.attachments, attachments: msg.attachments,
reply: msg.referencedMessage,
}); });
} }
} }