const {addCommand} = require("../lib/command"); const {startPrompt} = require("../lib/prompt"); const {processMessage} = require("../lib/messages"); const {listChannels} = require("./listChannels"); async function getHistory(limit = 20, channel = null) { if (!channel && !comcord.state.currentChannel) { console.log(""); return; } const messages = await comcord.client.getMessages( channel ?? comcord.state.currentChannel, {limit} ); messages.reverse(); console.log("--Beginning-Review".padEnd(72, "-")); for (const msg of messages) { processMessage(msg, {noColor: true, history: true}); } console.log("--Review-Complete".padEnd(73, "-")); } async function getExtendedHistory(input) { input = parseInt(input); if (isNaN(input)) { console.log(""); return; } try { await getHistory(input); } catch (err) { console.log(``); } } addCommand("r", "channel history", getHistory); addCommand("R", "extended history", function () { startPrompt(":lines> ", async function (input) { process.stdout.write("\n"); await getExtendedHistory(input); }); }); addCommand("p", "peek at channel", function () { if (!comcord.state.currentGuild) { console.log(""); 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(""); } else { await getHistory(20, target); } }); });