add peek
This commit is contained in:
parent
8ea671bad3
commit
b67347b18e
2 changed files with 37 additions and 3 deletions
|
@ -1,15 +1,16 @@
|
|||
const {addCommand} = require("../lib/command");
|
||||
const {startPrompt} = require("../lib/prompt");
|
||||
const {processMessage} = require("../lib/messages");
|
||||
const {listChannels} = require("./listChannels");
|
||||
|
||||
async function getHistory(limit = 20) {
|
||||
if (!comcord.state.currentChannel) {
|
||||
async function getHistory(limit = 20, channel = null) {
|
||||
if (!channel && !comcord.state.currentChannel) {
|
||||
console.log("<not in a channel>");
|
||||
return;
|
||||
}
|
||||
|
||||
const messages = await comcord.client.getMessages(
|
||||
comcord.state.currentChannel,
|
||||
channel ?? comcord.state.currentChannel,
|
||||
{limit}
|
||||
);
|
||||
messages.reverse();
|
||||
|
@ -44,3 +45,35 @@ addCommand("R", "extended history", function () {
|
|||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -267,6 +267,7 @@ client.on("messageReactionAdd", async function (msg, emoji, reactor) {
|
|||
referencedMessage: reply,
|
||||
author: reactor?.user ?? client.users.get(reactor.id),
|
||||
timestamp: Date.now(),
|
||||
mentions: [],
|
||||
content: `*reacted with ${emoji.id ? `:${emoji.name}:` : emoji.name}*`,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue