3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 22:21:51 +00:00

channel typings

Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
metal 2023-03-11 12:43:04 +00:00 committed by GitHub
parent c33a216857
commit 8347095fa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 91 additions and 103 deletions

View file

@ -2,7 +2,15 @@
* @file Utility functions that are plugin-instance-specific (i.e. use PluginData) * @file Utility functions that are plugin-instance-specific (i.e. use PluginData)
*/ */
import { GuildMember, Message, MessageMentionOptions, MessageOptions, TextChannel } from "discord.js"; import {
GuildMember,
GuildTextBasedChannel,
Message,
MessageMentionOptions,
MessageOptions,
TextBasedChannel,
TextChannel,
} from "discord.js";
import * as t from "io-ts"; import * as t from "io-ts";
import { CommandContext, configUtils, ConfigValidationError, GuildPluginData, helpers, PluginOptions } from "knub"; import { CommandContext, configUtils, ConfigValidationError, GuildPluginData, helpers, PluginOptions } from "knub";
import { PluginOverrideCriteria } from "knub/dist/config/configTypes"; import { PluginOverrideCriteria } from "knub/dist/config/configTypes";
@ -209,7 +217,7 @@ export async function sendSuccessMessage(
export async function sendErrorMessage( export async function sendErrorMessage(
pluginData: AnyPluginData<any>, pluginData: AnyPluginData<any>,
channel: TextChannel, channel: GuildTextBasedChannel,
body: string, body: string,
allowedMentions?: MessageMentionOptions, allowedMentions?: MessageMentionOptions,
): Promise<Message | undefined> { ): Promise<Message | undefined> {

View file

@ -1,6 +1,5 @@
import { Snowflake, TextChannel } from "discord.js"; import { ChannelType, Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts"; import * as t from "io-ts";
import { ChannelTypeStrings } from "src/types";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils"; import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils";
import { automodAction } from "../helpers"; import { automodAction } from "../helpers";
@ -23,15 +22,15 @@ export const SetSlowmodeAction = automodAction({
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake); const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
// Only text channels and text channels within categories support slowmodes // Only text channels and text channels within categories support slowmodes
if (!channel || !(channel.type === ChannelTypeStrings.TEXT || ChannelTypeStrings.CATEGORY)) { if (!channel || !(channel.type === ChannelType.GuildText || ChannelType.GuildCategory)) {
continue; continue;
} }
const channelsToSlowmode: TextChannel[] = []; const channelsToSlowmode: TextChannel[] = [];
if (channel.type === ChannelTypeStrings.CATEGORY) { if (channel.type === ChannelType.GuildCategory) {
// Find all text channels within the category // Find all text channels within the category
for (const ch of pluginData.guild.channels.cache.values()) { for (const ch of pluginData.guild.channels.cache.values()) {
if (ch.parentId === channel.id && ch.type === ChannelTypeStrings.TEXT) { if (ch.parentId === channel.id && ch.type === ChannelType.GuildText) {
channelsToSlowmode.push(ch as TextChannel); channelsToSlowmode.push(ch as TextChannel);
} }
} }

View file

@ -1,8 +1,7 @@
import { GuildFeature, ThreadAutoArchiveDuration } from "discord-api-types/v9"; import { GuildFeature, ThreadAutoArchiveDuration } from "discord-api-types/v9";
import { TextChannel } from "discord.js"; import { ChannelType, TextChannel } from "discord.js";
import * as t from "io-ts"; import * as t from "io-ts";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter"; import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { ChannelTypeStrings } from "../../../types";
import { convertDelayStringToMS, MINUTES, noop, tDelayString, tNullable } from "../../../utils"; import { convertDelayStringToMS, MINUTES, noop, tDelayString, tNullable } from "../../../utils";
import { savedMessageToTemplateSafeSavedMessage, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { savedMessageToTemplateSafeSavedMessage, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { automodAction } from "../helpers"; import { automodAction } from "../helpers";
@ -32,7 +31,7 @@ export const StartThreadAction = automodAction({
const threads = contexts.filter((c) => { const threads = contexts.filter((c) => {
if (!c.message || !c.user) return false; if (!c.message || !c.user) return false;
const channel = pluginData.guild.channels.cache.get(c.message.channel_id); const channel = pluginData.guild.channels.cache.get(c.message.channel_id);
if (channel?.type !== ChannelTypeStrings.TEXT || !channel.isTextBased()) return false; // for some reason the typing here for channel.type defaults to ThreadChannelTypes (?) if (channel?.type !== ChannelType.GuildText || !channel.isTextBased()) return false; // for some reason the typing here for channel.type defaults to ThreadChannelTypes (?)
// check against max threads per channel // check against max threads per channel
if (actionConfig.limit_per_channel && actionConfig.limit_per_channel > 0) { if (actionConfig.limit_per_channel && actionConfig.limit_per_channel > 0) {
const threadCount = channel.threads.cache.filter( const threadCount = channel.threads.cache.filter(
@ -67,10 +66,7 @@ export const StartThreadAction = automodAction({
.create({ .create({
name: threadName, name: threadName,
autoArchiveDuration: autoArchive, autoArchiveDuration: autoArchive,
type: type: actionConfig.private ? ChannelType.PrivateThread : ChannelType.PublicThread,
actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads)
? ChannelTypeStrings.PRIVATE_THREAD
: ChannelTypeStrings.PUBLIC_THREAD,
startMessage: startMessage:
!actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads) !actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads)
? threadContext.message!.id ? threadContext.message!.id

View file

@ -1,5 +1,4 @@
import { Util } from "discord.js"; import { ChannelType, escapeInlineCode } from "discord.js";
import { ChannelTypeStrings } from "src/types";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { asSingleLine } from "../../../utils"; import { asSingleLine } from "../../../utils";
@ -39,7 +38,7 @@ export const SlowmodeClearCmd = slowmodeCmd({
} }
try { try {
if (args.channel.type === ChannelTypeStrings.TEXT) { if (args.channel.type === ChannelType.GuildText) {
await clearBotSlowmodeFromUserId(pluginData, args.channel, args.user.id, args.force); await clearBotSlowmodeFromUserId(pluginData, args.channel, args.user.id, args.force);
} else { } else {
sendErrorMessage( sendErrorMessage(
@ -58,7 +57,7 @@ export const SlowmodeClearCmd = slowmodeCmd({
msg.channel, msg.channel,
asSingleLine(` asSingleLine(`
Failed to clear slowmode from **${args.user.tag}** in <#${args.channel.id}>: Failed to clear slowmode from **${args.user.tag}** in <#${args.channel.id}>:
\`${Util.escapeInlineCode(e.message)}\` \`${escapeInlineCode(e.message)}\`
`), `),
); );
return; return;

View file

@ -1,6 +1,5 @@
import { Permissions, TextChannel, ThreadChannel, Util } from "discord.js"; import { ChannelType, GuildTextBasedChannel, Permissions, TextChannel, ThreadChannel, Util } from "discord.js";
import humanizeDuration from "humanize-duration"; import humanizeDuration from "humanize-duration";
import { ChannelTypeStrings } from "src/types";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { asSingleLine, DAYS, HOURS, MINUTES } from "../../../utils"; import { asSingleLine, DAYS, HOURS, MINUTES } from "../../../utils";
@ -39,7 +38,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
], ],
async run({ message: msg, args, pluginData }) { async run({ message: msg, args, pluginData }) {
const channel: TextChannel | ThreadChannel = args.channel || msg.channel; const channel: GuildTextBasedChannel = args.channel || msg.channel;
if (args.time === 0) { if (args.time === 0) {
// Workaround until we can call SlowmodeDisableCmd from here // Workaround until we can call SlowmodeDisableCmd from here
@ -123,7 +122,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
if (mode === "native") { if (mode === "native") {
// If there is an existing bot-maintained slowmode, disable that first // If there is an existing bot-maintained slowmode, disable that first
const existingBotSlowmode = await pluginData.state.slowmodes.getChannelSlowmode(channel.id); const existingBotSlowmode = await pluginData.state.slowmodes.getChannelSlowmode(channel.id);
if (existingBotSlowmode && channel.type === ChannelTypeStrings.TEXT) { if (existingBotSlowmode && channel.isTextBased()) {
await disableBotSlowmodeForChannel(pluginData, channel); await disableBotSlowmodeForChannel(pluginData, channel);
} }

View file

@ -1,4 +1,4 @@
import { Snowflake, VoiceChannel } from "discord.js"; import { ChannelType, Snowflake, VoiceChannel } from "discord.js";
import { import {
channelToTemplateSafeChannel, channelToTemplateSafeChannel,
memberToTemplateSafeMember, memberToTemplateSafeMember,
@ -9,7 +9,6 @@ import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils"; import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { channelMentionRegex, isSnowflake, simpleClosestStringMatch } from "../../../utils"; import { channelMentionRegex, isSnowflake, simpleClosestStringMatch } from "../../../utils";
import { utilityCmd } from "../types"; import { utilityCmd } from "../types";
import { ChannelTypeStrings } from "../../../types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
export const VcmoveCmd = utilityCmd({ export const VcmoveCmd = utilityCmd({
@ -48,7 +47,7 @@ export const VcmoveCmd = utilityCmd({
} else { } else {
// Search string -> find closest matching voice channel name // Search string -> find closest matching voice channel name
const voiceChannels = [...pluginData.guild.channels.cache.values()].filter( const voiceChannels = [...pluginData.guild.channels.cache.values()].filter(
(c): c is VoiceChannel => c.type === ChannelTypeStrings.VOICE, (c): c is VoiceChannel => c.type === ChannelType.GuildVoice,
); );
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, (ch) => ch.name); const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, (ch) => ch.name);
if (!closestMatch) { if (!closestMatch) {
@ -127,7 +126,7 @@ export const VcmoveAllCmd = utilityCmd({
} else { } else {
// Search string -> find closest matching voice channel name // Search string -> find closest matching voice channel name
const voiceChannels = [...pluginData.guild.channels.cache.values()].filter( const voiceChannels = [...pluginData.guild.channels.cache.values()].filter(
(c): c is VoiceChannel => c.type === ChannelTypeStrings.VOICE, (c): c is VoiceChannel => c.type === ChannelType.GuildVoice,
); );
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, (ch) => ch.name); const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, (ch) => ch.name);
if (!closestMatch) { if (!closestMatch) {

View file

@ -1,8 +1,7 @@
import { MessageEmbedOptions, Snowflake, StageChannel, ThreadChannel, VoiceChannel } from "discord.js"; import { ChannelType, 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 { EmbedWith, formatNumber, MINUTES, preEmbedPadding, trimLines, verboseUserMention } 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";
@ -36,24 +35,25 @@ export async function getChannelInfoEmbed(
const icon = const icon =
{ {
[ChannelTypeStrings.VOICE]: VOICE_CHANNEL_ICON, [ChannelType.GuildVoice]: VOICE_CHANNEL_ICON,
[ChannelTypeStrings.NEWS]: ANNOUNCEMENT_CHANNEL_ICON, [ChannelType.GuildAnnouncement]: ANNOUNCEMENT_CHANNEL_ICON,
[ChannelTypeStrings.STAGE]: STAGE_CHANNEL_ICON, [ChannelType.GuildStageVoice]: STAGE_CHANNEL_ICON,
[ChannelTypeStrings.PUBLIC_THREAD]: PUBLIC_THREAD_ICON, [ChannelType.PublicThread]: PUBLIC_THREAD_ICON,
[ChannelTypeStrings.PRIVATE_THREAD]: PRIVATE_THREAD_UCON, [ChannelType.PrivateThread]: PRIVATE_THREAD_UCON,
}[channel.type] || TEXT_CHANNEL_ICON; }[channel.type] || TEXT_CHANNEL_ICON;
const channelType = const channelType =
{ {
[ChannelTypeStrings.TEXT]: "Text channel", [ChannelType.GuildText]: "Text channel",
[ChannelTypeStrings.VOICE]: "Voice channel", [ChannelType.GuildVoice]: "Voice channel",
[ChannelTypeStrings.CATEGORY]: "Category", [ChannelType.GuildCategory]: "Category channel",
[ChannelTypeStrings.NEWS]: "Announcement channel", [ChannelType.GuildAnnouncement]: "Announcement channel",
[ChannelTypeStrings.STORE]: "Store channel", [ChannelType.GuildStageVoice]: "Stage channel",
[ChannelTypeStrings.STAGE]: "Stage channel", [ChannelType.PublicThread]: "Public Thread channel",
[ChannelTypeStrings.PUBLIC_THREAD]: "Public Thread channel", [ChannelType.PrivateThread]: "Private Thread channel",
[ChannelTypeStrings.PRIVATE_THREAD]: "Private Thread channel", [ChannelType.AnnouncementThread]: "News Thread channel",
[ChannelTypeStrings.NEWS_THREAD]: "News Thread channel", [ChannelType.GuildDirectory]: "Hub channel",
[ChannelType.GuildForum]: "Forum channel",
}[channel.type] || "Channel"; }[channel.type] || "Channel";
embed.author = { embed.author = {
@ -63,9 +63,10 @@ export async function getChannelInfoEmbed(
let channelName = `#${channel.name}`; let channelName = `#${channel.name}`;
if ( if (
channel.type === ChannelTypeStrings.VOICE || channel.type === ChannelType.GuildVoice ||
channel.type === ChannelTypeStrings.CATEGORY || channel.type === ChannelType.GuildCategory ||
channel.type === ChannelTypeStrings.STAGE channel.type === ChannelType.GuildStageVoice ||
channel.type === ChannelType.GuildDirectory
) { ) {
channelName = channel.name; channelName = channel.name;
} }
@ -81,7 +82,7 @@ export async function getChannelInfoEmbed(
round: true, round: true,
}); });
const showMention = channel.type !== ChannelTypeStrings.CATEGORY; const showMention = channel.type !== ChannelType.GuildCategory;
embed.fields.push({ embed.fields.push({
name: preEmbedPadding + "Channel information", name: preEmbedPadding + "Channel information",
@ -94,11 +95,11 @@ export async function getChannelInfoEmbed(
`), `),
}); });
if (channel.type === ChannelTypeStrings.VOICE || channel.type === ChannelTypeStrings.STAGE) { if (channel.type === ChannelType.GuildVoice || channel.type === ChannelType.GuildStageVoice) {
const voiceMembers = Array.from((channel as VoiceChannel | StageChannel).members.values()); const voiceMembers = Array.from((channel as VoiceChannel | StageChannel).members.values());
const muted = voiceMembers.filter((vm) => vm.voice.mute || vm.voice.selfMute); const muted = voiceMembers.filter((vm) => vm.voice.mute || vm.voice.selfMute);
const deafened = voiceMembers.filter((vm) => vm.voice.deaf || vm.voice.selfDeaf); const deafened = voiceMembers.filter((vm) => vm.voice.deaf || vm.voice.selfDeaf);
const voiceOrStage = channel.type === ChannelTypeStrings.VOICE ? "Voice" : "Stage"; const voiceOrStage = channel.type === ChannelType.GuildVoice ? "Voice" : "Stage";
embed.fields.push({ embed.fields.push({
name: preEmbedPadding + `${voiceOrStage} information`, name: preEmbedPadding + `${voiceOrStage} information`,
@ -110,13 +111,13 @@ export async function getChannelInfoEmbed(
}); });
} }
if (channel.type === ChannelTypeStrings.CATEGORY) { if (channel.type === ChannelType.GuildCategory) {
const textChannels = pluginData.guild.channels.cache.filter( const textChannels = pluginData.guild.channels.cache.filter(
(ch) => ch.parentId === channel.id && ch.type !== ChannelTypeStrings.VOICE, (ch) => ch.parentId === channel.id && ch.type !== ChannelType.GuildVoice,
); );
const voiceChannels = pluginData.guild.channels.cache.filter( const voiceChannels = pluginData.guild.channels.cache.filter(
(ch) => (ch) =>
ch.parentId === channel.id && (ch.type === ChannelTypeStrings.VOICE || ch.type === ChannelTypeStrings.STAGE), ch.parentId === channel.id && (ch.type === ChannelType.GuildVoice || ch.type === ChannelType.GuildStageVoice),
); );
embed.fields.push({ embed.fields.push({
@ -128,7 +129,7 @@ export async function getChannelInfoEmbed(
}); });
} }
if (channel.type === ChannelTypeStrings.PRIVATE_THREAD || channel.type === ChannelTypeStrings.PUBLIC_THREAD) { if (channel.type === ChannelType.PrivateThread || channel.type === ChannelType.PublicThread) {
const thread = channel as ThreadChannel; const thread = channel as ThreadChannel;
const parentChannelName = thread.parent?.name ?? `<#${thread.parentId}>`; const parentChannelName = thread.parent?.name ?? `<#${thread.parentId}>`;
const memberCount = thread.memberCount ?? thread.members.cache.size; const memberCount = thread.memberCount ?? thread.members.cache.size;

View file

@ -1,8 +1,7 @@
import { MessageEmbedOptions } from "discord.js"; import { ChannelType, EmbedData } 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 { import {
EmbedWith, EmbedWith,
formatNumber, formatNumber,
@ -20,7 +19,7 @@ import { UtilityPluginType } from "../types";
export async function getInviteInfoEmbed( export async function getInviteInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>, pluginData: GuildPluginData<UtilityPluginType>,
inviteCode: string, inviteCode: string,
): Promise<MessageEmbedOptions | null> { ): Promise<EmbedData | null> {
let invite = await resolveInvite(pluginData.client, inviteCode, true); let invite = await resolveInvite(pluginData.client, inviteCode, true);
if (!invite) { if (!invite) {
return null; return null;
@ -67,7 +66,7 @@ export async function getInviteInfoEmbed(
}); });
if (invite.channel) { if (invite.channel) {
const channelName = const channelName =
invite.channel.type === ChannelTypeStrings.VOICE ? `🔉 ${invite.channel.name}` : `#${invite.channel.name}`; invite.channel.type === ChannelType.GuildVoice ? `🔉 ${invite.channel.name}` : `#${invite.channel.name}`;
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id); const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id);
const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x"); const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x");
@ -82,7 +81,7 @@ export async function getInviteInfoEmbed(
Created: **${channelAge} ago** Created: **${channelAge} ago**
`); `);
if (invite.channel.type !== ChannelTypeStrings.VOICE) { if (invite.channel.type !== ChannelType.GuildVoice) {
channelInfo += `\nMention: <#${invite.channel.id}>`; channelInfo += `\nMention: <#${invite.channel.id}>`;
} }
@ -114,13 +113,13 @@ export async function getInviteInfoEmbed(
invite = invite as GroupDMInvite; invite = invite as GroupDMInvite;
embed.author = { embed.author = {
name: invite.channel.name ? `Group DM invite: ${invite.channel.name}` : `Group DM invite`, name: invite.channel!.name ? `Group DM invite: ${invite.channel!.name}` : `Group DM invite`,
url: `https://discord.gg/${invite.code}`, url: `https://discord.gg/${invite.code}`,
}; // FIXME pending invite re-think }; // FIXME pending invite re-think
/*if (invite.channel.icon) { /*if (invite.channel.icon) {
embed.author.icon_url = `https://cdn.discordapp.com/channel-icons/${invite.channel.id}/${invite.channel.icon}.png?size=256`; embed.author.icon_url = `https://cdn.discordapp.com/channel-icons/${invite.channel.id}/${invite.channel.icon}.png?size=256`;
}*/ const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id); }*/ const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel!.id);
const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x"); const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x");
const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, { const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, {
largest: 2, largest: 2,
@ -130,8 +129,8 @@ export async function getInviteInfoEmbed(
embed.fields.push({ embed.fields.push({
name: preEmbedPadding + "Group DM information", name: preEmbedPadding + "Group DM information",
value: trimLines(` value: trimLines(`
Name: ${invite.channel.name ? `**${invite.channel.name}**` : `_Unknown_`} Name: ${invite.channel!.name ? `**${invite.channel!.name}**` : `_Unknown_`}
ID: \`${invite.channel.id}\` ID: \`${invite.channel!.id}\`
Created: **${channelAge} ago** Created: **${channelAge} ago**
Members: **${formatNumber((invite as any).memberCount)}** Members: **${formatNumber((invite as any).memberCount)}**
`), `),

View file

@ -1,8 +1,8 @@
import { MessageEmbedOptions, PremiumTier, Snowflake } from "discord.js"; import { ChannelType, MessageEmbedOptions, PremiumTier, Snowflake } 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 "../../../types";
import { import {
EmbedWith, EmbedWith,
formatNumber, formatNumber,
@ -90,10 +90,10 @@ export async function getServerInfoEmbed(
}); });
// IMAGE LINKS // IMAGE LINKS
const iconUrl = `[Link](${(restGuild || guildPreview)!.iconURL({ dynamic: true, format: "png", size: 2048 })})`; const iconUrl = `[Link](${(restGuild || guildPreview)!.iconURL({ size: 2048 })})`;
const bannerUrl = restGuild?.banner ? `[Link](${restGuild.bannerURL({ format: "png", size: 2048 })})` : "None"; const bannerUrl = restGuild?.banner ? `[Link](${restGuild.bannerURL({ size: 2048 })})` : "None";
const splashUrl = (restGuild || guildPreview)!.splash const splashUrl = (restGuild || guildPreview)!.splash
? `[Link](${(restGuild || guildPreview)!.splashURL({ format: "png", size: 2048 })})` ? `[Link](${(restGuild || guildPreview)!.splashURL({ size: 2048 })})`
: "None"; : "None";
embed.fields.push( embed.fields.push(
@ -162,9 +162,19 @@ export async function getServerInfoEmbed(
// CHANNEL COUNTS // CHANNEL COUNTS
if (thisServer) { if (thisServer) {
const totalChannels = thisServer.channels.cache.size; const totalChannels = thisServer.channels.cache.size;
const categories = thisServer.channels.cache.filter((channel) => channel.type === ChannelTypeStrings.CATEGORY); const categories = thisServer.channels.cache.filter((channel) => channel.type === ChannelType.GuildCategory);
const textChannels = thisServer.channels.cache.filter((channel) => channel.type === ChannelTypeStrings.TEXT); const textChannels = thisServer.channels.cache.filter((channel) => channel.type === ChannelType.GuildText);
const voiceChannels = thisServer.channels.cache.filter((channel) => channel.type === ChannelTypeStrings.VOICE); const voiceChannels = thisServer.channels.cache.filter((channel) => channel.type === ChannelType.GuildVoice);
const threadChannels = thisServer.channels.cache.filter(
(channel) =>
channel.type === ChannelType.PublicThread ||
channel.type === ChannelType.PrivateThread ||
channel.type === ChannelType.AnnouncementThread,
);
const announcementChannels = thisServer.channels.cache.filter(
(channel) => channel.type === ChannelType.GuildAnnouncement,
);
const stageChannels = thisServer.channels.cache.filter((channel) => channel.type === ChannelType.GuildStageVoice);
embed.fields.push({ embed.fields.push({
name: preEmbedPadding + "Channels", name: preEmbedPadding + "Channels",
@ -172,8 +182,10 @@ export async function getServerInfoEmbed(
value: trimLines(` value: trimLines(`
Total: **${totalChannels}** / 500 Total: **${totalChannels}** / 500
Categories: **${categories.size}** Categories: **${categories.size}**
Text: **${textChannels.size}** Text: **${textChannels.size}** (**${threadChannels.size} threads**)
Announcement: **${announcementChannels.size}**
Voice: **${voiceChannels.size}** Voice: **${voiceChannels.size}**
Stage: **${stageChannels.size}**
`), `),
}); });
} }

View file

@ -65,21 +65,6 @@ export interface CommandInfo {
}; };
} }
export enum ChannelTypeStrings {
TEXT = "GUILD_TEXT",
DM = "DM",
VOICE = "GUILD_VOICE",
GROUP = "GROUP_DM",
CATEGORY = "GUILD_CATEGORY",
NEWS = "GUILD_NEWS",
STORE = "GUILD_STORE",
NEWS_THREAD = "GUILD_NEWS_THREAD",
PUBLIC_THREAD = "GUILD_PUBLIC_THREAD",
PRIVATE_THREAD = "GUILD_PRIVATE_THREAD",
STAGE = "GUILD_STAGE_VOICE",
UNKNOWN = "UNKNOWN",
}
export enum MessageTypeStrings { export enum MessageTypeStrings {
"DEFAULT", "DEFAULT",
"RECIPIENT_ADD", "RECIPIENT_ADD",

View file

@ -1,4 +1,5 @@
import { import {
ChannelType,
Client, Client,
Constants, Constants,
DiscordAPIError, DiscordAPIError,
@ -42,7 +43,6 @@ import tmp from "tmp";
import { URL } from "url"; import { URL } from "url";
import { ISavedMessageAttachmentData, SavedMessage } from "./data/entities/SavedMessage"; import { ISavedMessageAttachmentData, SavedMessage } from "./data/entities/SavedMessage";
import { SimpleCache } from "./SimpleCache"; import { SimpleCache } from "./SimpleCache";
import { ChannelTypeStrings } from "./types";
import { sendDM } from "./utils/sendDM"; import { sendDM } from "./utils/sendDM";
import { waitForButtonConfirm } from "./utils/waitForInteraction"; import { waitForButtonConfirm } from "./utils/waitForInteraction";
import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils"; import { decodeAndValidateStrict, StrictValidationError } from "./validatorUtils";
@ -1444,7 +1444,7 @@ export function verboseUserName(user: User | UnknownUser): string {
export function verboseChannelMention(channel: GuildChannel | ThreadChannel): string { export function verboseChannelMention(channel: GuildChannel | ThreadChannel): string {
const plainTextName = const plainTextName =
channel.type === ChannelTypeStrings.VOICE || channel.type === ChannelTypeStrings.STAGE channel.type === ChannelType.GuildVoice || channel.type === ChannelType.GuildStageVoice
? channel.name ? channel.name
: `#${channel.name}`; : `#${channel.name}`;
return `<#${channel.id}> (**${plainTextName}**, \`${channel.id}\`)`; return `<#${channel.id}> (**${plainTextName}**, \`${channel.id}\`)`;
@ -1578,7 +1578,7 @@ export function isGuildInvite(invite: Invite): invite is GuildInvite {
} }
export function isGroupDMInvite(invite: Invite): invite is GroupDMInvite { export function isGroupDMInvite(invite: Invite): invite is GroupDMInvite {
return invite.guild == null && invite.channel?.type === ChannelTypeStrings.GROUP; return invite.guild == null && invite.channel?.type === ChannelType.GroupDM;
} }
export function inviteHasCounts(invite: Invite): invite is Invite { export function inviteHasCounts(invite: Invite): invite is Invite {

View file

@ -1,6 +1,5 @@
import { Channel, DMChannel } from "discord.js"; import { Channel, ChannelType, DMChannel } from "discord.js";
import { ChannelTypeStrings } from "src/types";
export function isDmChannel(channel: Channel): channel is DMChannel { export function isDmChannel(channel: Channel): channel is DMChannel {
return channel.type === ChannelTypeStrings.DM || channel.type === ChannelTypeStrings.GROUP; return channel.isDMBased();
} }

View file

@ -1,5 +1,5 @@
import { Channel, GuildChannel } from "discord.js"; import { Channel, GuildBasedChannel, GuildChannel } from "discord.js";
export function isGuildChannel(channel: Channel): channel is GuildChannel { export function isGuildChannel(channel: Channel): channel is GuildBasedChannel {
return channel.type.startsWith("GUILD_"); return channel.type.toString().startsWith("GUILD_");
} }

View file

@ -1,10 +1,5 @@
import { AnyThreadChannel, Channel, ChannelType } from "discord.js"; import { AnyThreadChannel, Channel, ChannelType } from "discord.js";
import { ChannelTypeStrings } from "src/types";
export function isThreadChannel(channel: Channel): channel is AnyThreadChannel { export function isThreadChannel(channel: Channel): channel is AnyThreadChannel {
return ( return channel.isThread();
channel.type === ChannelType.PublicThread ||
channel.type === ChannelType.PrivateThread ||
channel.type === ChannelType.AnnouncementThread
);
} }

View file

@ -1,7 +1,4 @@
import { ChannelType } from "discord-api-types/v9";
import { CategoryChannel, Channel } from "discord.js"; import { CategoryChannel, Channel } from "discord.js";
import { ChannelTypes } from "discord.js/typings/enums";
import { ChannelTypeStrings } from "src/types";
import { isDmChannel } from "./isDmChannel"; import { isDmChannel } from "./isDmChannel";
import { isGuildChannel } from "./isGuildChannel"; import { isGuildChannel } from "./isGuildChannel";
import { isThreadChannel } from "./isThreadChannel"; import { isThreadChannel } from "./isThreadChannel";