3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

added better support for stage channels on channelinfo (#197)

This commit is contained in:
Almeida 2021-05-06 19:25:17 +01:00 committed by GitHub
parent a4a7eb41b0
commit 8846a016ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,8 @@ const VOICE_CHANNEL_ICON =
"https://cdn.discordapp.com/attachments/740650744830623756/740656845982662716/voice-channel.png"; "https://cdn.discordapp.com/attachments/740650744830623756/740656845982662716/voice-channel.png";
const ANNOUNCEMENT_CHANNEL_ICON = 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 =
"https://cdn.discordapp.com/attachments/705009450855039042/839292597859516446/stage-channel.png";
export async function getChannelInfoEmbed( export async function getChannelInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>, pluginData: GuildPluginData<UtilityPluginType>,
@ -27,13 +29,13 @@ export async function getChannelInfoEmbed(
fields: [], fields: [],
}; };
let icon; let icon = TEXT_CHANNEL_ICON;
if (channel.type === Constants.ChannelTypes.GUILD_VOICE) { if (channel.type === Constants.ChannelTypes.GUILD_VOICE) {
icon = VOICE_CHANNEL_ICON; icon = VOICE_CHANNEL_ICON;
} else if (channel.type === Constants.ChannelTypes.GUILD_NEWS) { } else if (channel.type === Constants.ChannelTypes.GUILD_NEWS) {
icon = ANNOUNCEMENT_CHANNEL_ICON; icon = ANNOUNCEMENT_CHANNEL_ICON;
} else { } else if (channel.type === Constants.ChannelTypes.GUILD_STAGE) {
icon = TEXT_CHANNEL_ICON; icon = STAGE_CHANNEL_ICON;
} }
const channelType = const channelType =
@ -43,6 +45,7 @@ export async function getChannelInfoEmbed(
[Constants.ChannelTypes.GUILD_CATEGORY]: "Category", [Constants.ChannelTypes.GUILD_CATEGORY]: "Category",
[Constants.ChannelTypes.GUILD_NEWS]: "Announcement channel", [Constants.ChannelTypes.GUILD_NEWS]: "Announcement channel",
[Constants.ChannelTypes.GUILD_STORE]: "Store channel", [Constants.ChannelTypes.GUILD_STORE]: "Store channel",
[Constants.ChannelTypes.GUILD_STAGE]: "Stage channel",
}[channel.type] || "Channel"; }[channel.type] || "Channel";
embed.author = { embed.author = {
@ -50,11 +53,13 @@ export async function getChannelInfoEmbed(
icon_url: icon, icon_url: icon,
}; };
let channelName; let channelName = `#${channel.name}`;
if (channel.type === Constants.ChannelTypes.GUILD_VOICE || channel.type === Constants.ChannelTypes.GUILD_CATEGORY) { if (
channel.type === Constants.ChannelTypes.GUILD_VOICE ||
channel.type === Constants.ChannelTypes.GUILD_CATEGORY ||
channel.type === Constants.ChannelTypes.GUILD_STAGE
) {
channelName = channel.name; channelName = channel.name;
} else {
channelName = `#${channel.name}`;
} }
const createdAt = moment.utc(channel.createdAt, "x"); const createdAt = moment.utc(channel.createdAt, "x");
@ -68,8 +73,7 @@ export async function getChannelInfoEmbed(
round: true, round: true,
}); });
const showMention = const showMention = channel.type !== Constants.ChannelTypes.GUILD_CATEGORY;
channel.type !== Constants.ChannelTypes.GUILD_VOICE && channel.type !== Constants.ChannelTypes.GUILD_CATEGORY;
embed.fields.push({ embed.fields.push({
name: preEmbedPadding + "Channel information", name: preEmbedPadding + "Channel information",
@ -82,15 +86,16 @@ export async function getChannelInfoEmbed(
`), `),
}); });
if (channel.type === Constants.ChannelTypes.GUILD_VOICE) { if (channel.type === Constants.ChannelTypes.GUILD_VOICE || channel.type === Constants.ChannelTypes.GUILD_STAGE) {
const voiceMembers = Array.from(channel.voiceMembers.values()); const voiceMembers = Array.from(channel.voiceMembers.values());
const muted = voiceMembers.filter(vm => vm.voiceState.mute || vm.voiceState.selfMute); const muted = voiceMembers.filter(vm => vm.voiceState.mute || vm.voiceState.selfMute);
const deafened = voiceMembers.filter(vm => vm.voiceState.deaf || vm.voiceState.selfDeaf); const deafened = voiceMembers.filter(vm => vm.voiceState.deaf || vm.voiceState.selfDeaf);
const voiceOrStage = channel.type === Constants.ChannelTypes.GUILD_VOICE ? "Voice" : "Stage";
embed.fields.push({ embed.fields.push({
name: preEmbedPadding + "Voice information", name: preEmbedPadding + `${voiceOrStage} information`,
value: trimLines(` value: trimLines(`
Users on voice channel: **${formatNumber(voiceMembers.length)}** Users on ${voiceOrStage.toLowerCase()} channel: **${formatNumber(voiceMembers.length)}**
Muted: **${formatNumber(muted.length)}** Muted: **${formatNumber(muted.length)}**
Deafened: **${formatNumber(deafened.length)}** Deafened: **${formatNumber(deafened.length)}**
`), `),
@ -102,7 +107,9 @@ export async function getChannelInfoEmbed(
ch => ch.parentID === channel.id && ch.type !== Constants.ChannelTypes.GUILD_VOICE, ch => ch.parentID === channel.id && ch.type !== Constants.ChannelTypes.GUILD_VOICE,
); );
const voiceChannels = pluginData.guild.channels.filter( const voiceChannels = pluginData.guild.channels.filter(
ch => ch.parentID === channel.id && ch.type === Constants.ChannelTypes.GUILD_VOICE, ch =>
ch.parentID === channel.id &&
(ch.type === Constants.ChannelTypes.GUILD_VOICE || ch.type === Constants.ChannelTypes.GUILD_STAGE),
); );
embed.fields.push({ embed.fields.push({