add channel listing

This commit is contained in:
Cynthia Foxwell 2022-08-27 21:56:02 -06:00
parent 080d20396b
commit 0b1387f7b9
2 changed files with 40 additions and 1 deletions

View file

@ -33,7 +33,7 @@ You **MUST** grant your bot all Privileged Gateway Intents.
- [ ] Creation date, join date, ID, etc - [ ] Creation date, join date, ID, etc
- [x] Room history (r) - [x] Room history (r)
- [x] Extended room history (R) - [x] Extended room history (R)
- [ ] List channels (l) - [x] List channels (l)
- [x] List guilds (L) - [x] List guilds (L)
- [x] Clear (c) - [x] Clear (c)
- [ ] Surf channels forwards (>) - [ ] Surf channels forwards (>)

View file

@ -313,6 +313,42 @@ function listGuilds() {
console.log(""); console.log("");
} }
function listChannels() {
let longest = 0;
let longestTopic = 0;
const guild = client.guilds.get(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.length > longest) longest = channel.name.length;
if (channel.topic != null && channel.topic.length > longestTopic)
longestTopic = channel.topic.length;
}
console.log("");
console.log(
" " +
"channel-name".padStart(longest, " ") +
" " +
"topic".padStart(Math.min(80 - (longest + 5), longestTopic), " ")
);
console.log("-".repeat(80));
for (const channel of channels) {
const topic =
channel.topic != null ? channel.topic.replace(/\n/g, " ") : "";
console.log(
" " +
channel.name.padStart(longest, " ") +
" " +
(topic.length > 80 - longest + 9
? topic.substring(0, 79 - (longest + 5)) + "\u2026"
: topic.padStart(Math.min(80 - (longest + 5), longestTopic), " "))
);
}
console.log("");
}
let targetGuild = ""; let targetGuild = "";
function gotoGuild() { function gotoGuild() {
targetGuild = ""; targetGuild = "";
@ -398,6 +434,7 @@ function listUsers() {
function switchGuild() { function switchGuild() {
targetGuild = targetGuild.trim(); targetGuild = targetGuild.trim();
if (targetGuild == "") { if (targetGuild == "") {
listChannels();
listUsers(); listUsers();
guildSwitch = false; guildSwitch = false;
return; return;
@ -420,6 +457,7 @@ function switchGuild() {
const topChannel = findTopChannel(target); const topChannel = findTopChannel(target);
currentChannel = topChannel.id; currentChannel = topChannel.id;
listChannels();
listUsers(); listUsers();
} }
@ -667,6 +705,7 @@ stdin.on("data", function (key) {
console.log("<not in a guild>"); console.log("<not in a guild>");
break; break;
} }
listChannels();
break; break;
} }
case "L": { case "L": {