From 7bee5755ae48c60ebb3e0df6856620a2b3a5fa0c Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Wed, 21 Jun 2023 13:26:57 -0600 Subject: [PATCH] add cross-guild peek --- src/commands/history.js | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/commands/history.js b/src/commands/history.js index 80ba873..987856a 100644 --- a/src/commands/history.js +++ b/src/commands/history.js @@ -53,7 +53,6 @@ addCommand("p", "peek at channel", function () { return; } - listChannels(); startPrompt(":peek> ", async function (input) { console.log(""); if (input == "") { @@ -79,3 +78,49 @@ addCommand("p", "peek at channel", function () { } }); }); +addCommand("P", "cross-guild peek", function () { + startPrompt(":guild> ", async function (input) { + console.log(""); + if (input == "") { + return; + } + let targetGuild; + for (const guild of comcord.client.guilds.values()) { + if (guild.name.toLowerCase().indexOf(input.toLowerCase()) > -1) { + targetGuild = guild.id; + break; + } + } + + if (targetGuild == null) { + console.log(""); + } else { + startPrompt(":peek> ", async function (input) { + console.log(""); + if (input == "") { + return; + } + let target; + + const guild = comcord.client.guilds.get(targetGuild); + 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); + } + }); + } + }); +});