Fix role member counts, add threads to channel info command
This commit is contained in:
parent
3c6c9ebecf
commit
0053f55576
2 changed files with 38 additions and 17 deletions
|
@ -34,13 +34,9 @@ export const RolesCmd = utilityCmd({
|
||||||
if (args.counts) {
|
if (args.counts) {
|
||||||
await refreshMembersIfNeeded(guild);
|
await refreshMembersIfNeeded(guild);
|
||||||
|
|
||||||
// If the user requested role member counts as well, calculate them and sort the roles by their member count
|
// If the user requested role member counts as well, fetch them and sort the roles by their member count
|
||||||
const roleCounts: Map<string, number> = Array.from(guild.members.cache.values()).reduce((map, member) => {
|
const roleCounts: Map<string, number> = Array.from(guild.roles.cache.values()).reduce((map, role) => {
|
||||||
for (const roleId of member.roles.cache) {
|
map.set(role.id, role.members.size);
|
||||||
if (!map.has(roleId)) map.set(roleId, 0);
|
|
||||||
map.set(roleId, map.get(roleId) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}, new Map());
|
}, new Map());
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { MessageEmbedOptions, Snowflake, StageChannel, VoiceChannel } from "discord.js";
|
import { MessageEmbedOptions, Snowflake, StageChannel, ThreadChannel, VoiceChannel } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
import humanizeDuration from "humanize-duration";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { ChannelTypeStrings } from "src/types";
|
import { ChannelTypeStrings } from "src/types";
|
||||||
import { EmbedWith, formatNumber, preEmbedPadding, trimLines } from "../../../utils";
|
import { EmbedWith, formatNumber, MINUTES, preEmbedPadding, trimLines, verboseUserMention } from "../../../utils";
|
||||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||||
import { UtilityPluginType } from "../types";
|
import { UtilityPluginType } from "../types";
|
||||||
|
|
||||||
|
@ -15,6 +15,10 @@ const ANNOUNCEMENT_CHANNEL_ICON =
|
||||||
"https://cdn.discordapp.com/attachments/740650744830623756/740656841687564348/announcement-channel.png";
|
"https://cdn.discordapp.com/attachments/740650744830623756/740656841687564348/announcement-channel.png";
|
||||||
const STAGE_CHANNEL_ICON =
|
const STAGE_CHANNEL_ICON =
|
||||||
"https://cdn.discordapp.com/attachments/740650744830623756/839930647711186995/stage-channel.png";
|
"https://cdn.discordapp.com/attachments/740650744830623756/839930647711186995/stage-channel.png";
|
||||||
|
const PUBLIC_THREAD_ICON =
|
||||||
|
"https://cdn.discordapp.com/attachments/740650744830623756/870343055855738921/public-thread.png";
|
||||||
|
const PRIVATE_THREAD_UCON =
|
||||||
|
"https://cdn.discordapp.com/attachments/740650744830623756/870343402447839242/private-thread.png";
|
||||||
|
|
||||||
export async function getChannelInfoEmbed(
|
export async function getChannelInfoEmbed(
|
||||||
pluginData: GuildPluginData<UtilityPluginType>,
|
pluginData: GuildPluginData<UtilityPluginType>,
|
||||||
|
@ -30,14 +34,14 @@ export async function getChannelInfoEmbed(
|
||||||
fields: [],
|
fields: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
let icon = TEXT_CHANNEL_ICON;
|
const icon =
|
||||||
if (channel.type === ChannelTypeStrings.VOICE) {
|
{
|
||||||
icon = VOICE_CHANNEL_ICON;
|
[ChannelTypeStrings.VOICE]: VOICE_CHANNEL_ICON,
|
||||||
} else if (channel.type === ChannelTypeStrings.NEWS) {
|
[ChannelTypeStrings.NEWS]: ANNOUNCEMENT_CHANNEL_ICON,
|
||||||
icon = ANNOUNCEMENT_CHANNEL_ICON;
|
[ChannelTypeStrings.STAGE]: STAGE_CHANNEL_ICON,
|
||||||
} else if (channel.type === ChannelTypeStrings.STAGE) {
|
[ChannelTypeStrings.PUBLIC_THREAD]: PUBLIC_THREAD_ICON,
|
||||||
icon = STAGE_CHANNEL_ICON;
|
[ChannelTypeStrings.PRIVATE_THREAD]: PRIVATE_THREAD_UCON,
|
||||||
}
|
}[channel.type] || TEXT_CHANNEL_ICON;
|
||||||
|
|
||||||
const channelType =
|
const channelType =
|
||||||
{
|
{
|
||||||
|
@ -47,6 +51,9 @@ export async function getChannelInfoEmbed(
|
||||||
[ChannelTypeStrings.NEWS]: "Announcement channel",
|
[ChannelTypeStrings.NEWS]: "Announcement channel",
|
||||||
[ChannelTypeStrings.STORE]: "Store channel",
|
[ChannelTypeStrings.STORE]: "Store channel",
|
||||||
[ChannelTypeStrings.STAGE]: "Stage channel",
|
[ChannelTypeStrings.STAGE]: "Stage channel",
|
||||||
|
[ChannelTypeStrings.PUBLIC_THREAD]: "Public Thread channel",
|
||||||
|
[ChannelTypeStrings.PRIVATE_THREAD]: "Private Thread channel",
|
||||||
|
[ChannelTypeStrings.NEWS_THREAD]: "News Thread channel",
|
||||||
}[channel.type] || "Channel";
|
}[channel.type] || "Channel";
|
||||||
|
|
||||||
embed.author = {
|
embed.author = {
|
||||||
|
@ -121,5 +128,23 @@ export async function getChannelInfoEmbed(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (channel.type === ChannelTypeStrings.PRIVATE_THREAD || channel.type === ChannelTypeStrings.PUBLIC_THREAD) {
|
||||||
|
const thread = channel as ThreadChannel;
|
||||||
|
const parentChannelName = thread.parent?.name ? thread.parent.name : `<#${thread.parentId}>`;
|
||||||
|
const memberCount = thread.memberCount ?? thread.members.cache.size;
|
||||||
|
const owner = await pluginData.guild.members.fetch(thread.ownerId).catch(() => null);
|
||||||
|
const ownerMention = owner ? verboseUserMention(owner.user) : "Unknown#0000";
|
||||||
|
const humanizedArchiveTime = `Archive duration: **${humanizeDuration(thread.autoArchiveDuration * MINUTES)}**`;
|
||||||
|
|
||||||
|
embed.fields.push({
|
||||||
|
name: preEmbedPadding + "Thread information",
|
||||||
|
value: trimLines(`
|
||||||
|
Parent channel: **#${parentChannelName}**
|
||||||
|
Member count: **${memberCount}**
|
||||||
|
Thread creator: ${ownerMention}
|
||||||
|
${thread.archived ? "Archived: **True**" : humanizedArchiveTime}`),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return embed;
|
return embed;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue