mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Finish preliminary rework, ready to test
This commit is contained in:
parent
57893e7f76
commit
d0a1beb809
177 changed files with 854 additions and 707 deletions
|
@ -5,6 +5,8 @@ import moment from "moment-timezone";
|
|||
import humanizeDuration from "humanize-duration";
|
||||
import { EmbedWith, formatNumber, preEmbedPadding, trimLines } from "../../../utils";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageEmbedOptions, Constants, VoiceChannel, StageChannel } from "discord.js";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
|
||||
const TEXT_CHANNEL_ICON =
|
||||
"https://cdn.discordapp.com/attachments/740650744830623756/740656843545772062/text-channel.png";
|
||||
|
@ -19,7 +21,7 @@ export async function getChannelInfoEmbed(
|
|||
pluginData: GuildPluginData<UtilityPluginType>,
|
||||
channelId: string,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions | null> {
|
||||
): Promise<MessageEmbedOptions | null> {
|
||||
const channel = pluginData.guild.channels.cache.get(channelId);
|
||||
if (!channel) {
|
||||
return null;
|
||||
|
@ -30,22 +32,22 @@ export async function getChannelInfoEmbed(
|
|||
};
|
||||
|
||||
let icon = TEXT_CHANNEL_ICON;
|
||||
if (channel.type === Constants.ChannelTypes.GUILD_VOICE) {
|
||||
if (channel.type === ChannelTypeStrings.VOICE) {
|
||||
icon = VOICE_CHANNEL_ICON;
|
||||
} else if (channel.type === Constants.ChannelTypes.GUILD_NEWS) {
|
||||
} else if (channel.type === ChannelTypeStrings.NEWS) {
|
||||
icon = ANNOUNCEMENT_CHANNEL_ICON;
|
||||
} else if (channel.type === Constants.ChannelTypes.GUILD_STAGE) {
|
||||
} else if (channel.type === ChannelTypeStrings.STAGE) {
|
||||
icon = STAGE_CHANNEL_ICON;
|
||||
}
|
||||
|
||||
const channelType =
|
||||
{
|
||||
[Constants.ChannelTypes.GUILD_TEXT]: "Text channel",
|
||||
[Constants.ChannelTypes.GUILD_VOICE]: "Voice channel",
|
||||
[Constants.ChannelTypes.GUILD_CATEGORY]: "Category",
|
||||
[Constants.ChannelTypes.GUILD_NEWS]: "Announcement channel",
|
||||
[Constants.ChannelTypes.GUILD_STORE]: "Store channel",
|
||||
[Constants.ChannelTypes.GUILD_STAGE]: "Stage channel",
|
||||
[ChannelTypeStrings.TEXT]: "Text channel",
|
||||
[ChannelTypeStrings.VOICE]: "Voice channel",
|
||||
[ChannelTypeStrings.CATEGORY]: "Category",
|
||||
[ChannelTypeStrings.NEWS]: "Announcement channel",
|
||||
[ChannelTypeStrings.STORE]: "Store channel",
|
||||
[ChannelTypeStrings.STAGE]: "Stage channel",
|
||||
}[channel.type] || "Channel";
|
||||
|
||||
embed.author = {
|
||||
|
@ -55,9 +57,9 @@ export async function getChannelInfoEmbed(
|
|||
|
||||
let channelName = `#${channel.name}`;
|
||||
if (
|
||||
channel.type === Constants.ChannelTypes.GUILD_VOICE ||
|
||||
channel.type === Constants.ChannelTypes.GUILD_CATEGORY ||
|
||||
channel.type === Constants.ChannelTypes.GUILD_STAGE
|
||||
channel.type === ChannelTypeStrings.VOICE ||
|
||||
channel.type === ChannelTypeStrings.CATEGORY ||
|
||||
channel.type === ChannelTypeStrings.STAGE
|
||||
) {
|
||||
channelName = channel.name;
|
||||
}
|
||||
|
@ -68,12 +70,12 @@ export async function getChannelInfoEmbed(
|
|||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
||||
: timeAndDate.inGuildTz(createdAt);
|
||||
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const channelAge = humanizeDuration(Date.now() - channel.createdAt, {
|
||||
const channelAge = humanizeDuration(Date.now() - channel.createdTimestamp, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
||||
const showMention = channel.type !== Constants.ChannelTypes.GUILD_CATEGORY;
|
||||
const showMention = channel.type !== ChannelTypeStrings.CATEGORY;
|
||||
|
||||
embed.fields.push({
|
||||
name: preEmbedPadding + "Channel information",
|
||||
|
@ -86,11 +88,11 @@ export async function getChannelInfoEmbed(
|
|||
`),
|
||||
});
|
||||
|
||||
if (channel.type === Constants.ChannelTypes.GUILD_VOICE || channel.type === Constants.ChannelTypes.GUILD_STAGE) {
|
||||
const voiceMembers = Array.from(channel.voiceMembers.values());
|
||||
const muted = voiceMembers.filter(vm => vm.voiceState.mute || vm.voiceState.selfMute);
|
||||
const deafened = voiceMembers.filter(vm => vm.voiceState.deaf || vm.voiceState.selfDeaf);
|
||||
const voiceOrStage = channel.type === Constants.ChannelTypes.GUILD_VOICE ? "Voice" : "Stage";
|
||||
if (channel.type === ChannelTypeStrings.VOICE || channel.type === ChannelTypeStrings.STAGE) {
|
||||
const voiceMembers = Array.from((channel as VoiceChannel | StageChannel).members.values());
|
||||
const muted = voiceMembers.filter(vm => vm.voice.mute || vm.voice.selfMute);
|
||||
const deafened = voiceMembers.filter(vm => vm.voice.deaf || vm.voice.selfDeaf);
|
||||
const voiceOrStage = channel.type === ChannelTypeStrings.VOICE ? "Voice" : "Stage";
|
||||
|
||||
embed.fields.push({
|
||||
name: preEmbedPadding + `${voiceOrStage} information`,
|
||||
|
@ -102,21 +104,20 @@ export async function getChannelInfoEmbed(
|
|||
});
|
||||
}
|
||||
|
||||
if (channel.type === Constants.ChannelTypes.GUILD_CATEGORY) {
|
||||
const textChannels = pluginData.guild.channels.filter(
|
||||
ch => ch.parentID === channel.id && ch.type !== Constants.ChannelTypes.GUILD_VOICE,
|
||||
if (channel.type === ChannelTypeStrings.CATEGORY) {
|
||||
const textChannels = pluginData.guild.channels.cache.filter(
|
||||
ch => ch.parentID === channel.id && ch.type !== ChannelTypeStrings.VOICE,
|
||||
);
|
||||
const voiceChannels = pluginData.guild.channels.filter(
|
||||
const voiceChannels = pluginData.guild.channels.cache.filter(
|
||||
ch =>
|
||||
ch.parentID === channel.id &&
|
||||
(ch.type === Constants.ChannelTypes.GUILD_VOICE || ch.type === Constants.ChannelTypes.GUILD_STAGE),
|
||||
ch.parentID === channel.id && (ch.type === ChannelTypeStrings.VOICE || ch.type === ChannelTypeStrings.STAGE),
|
||||
);
|
||||
|
||||
embed.fields.push({
|
||||
name: preEmbedPadding + "Category information",
|
||||
value: trimLines(`
|
||||
Text channels: **${textChannels.length}**
|
||||
Voice channels: **${voiceChannels.length}**
|
||||
Text channels: **${textChannels.size}**
|
||||
Voice channels: **${voiceChannels.size}**
|
||||
`),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { UtilityPluginType } from "../types";
|
||||
import { trimLines, preEmbedPadding, EmbedWith } from "../../../utils";
|
||||
import { MessageEmbedOptions } from "discord.js";
|
||||
|
||||
export async function getEmojiInfoEmbed(
|
||||
pluginData: GuildPluginData<UtilityPluginType>,
|
||||
emojiId: string,
|
||||
): Promise<EmbedOptions | null> {
|
||||
const emoji = pluginData.guild.emojis.find(e => e.id === emojiId);
|
||||
): Promise<MessageEmbedOptions | null> {
|
||||
const emoji = pluginData.guild.emojis.cache.find(e => e.id === emojiId);
|
||||
if (!emoji) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { Client, GuildPreview } from "discord.js";
|
||||
import { memoize, MINUTES } from "../../../utils";
|
||||
|
||||
/**
|
||||
* Memoized getGuildPreview
|
||||
*/
|
||||
export function getGuildPreview(client: Client, guildId: string): Promise<GuildPreview | null> {
|
||||
return memoize(() => client.getGuildPreview(guildId).catch(() => null), `getGuildPreview_${guildId}`, 10 * MINUTES);
|
||||
return memoize(() => client.fetchGuildPreview(guildId).catch(() => null), `getGuildPreview_${guildId}`, 10 * MINUTES);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
EmbedWith,
|
||||
emptyEmbedValue,
|
||||
formatNumber,
|
||||
GroupDMInvite,
|
||||
inviteHasCounts,
|
||||
isGroupDMInvite,
|
||||
isGuildInvite,
|
||||
|
@ -16,12 +17,14 @@ import {
|
|||
resolveInvite,
|
||||
trimLines,
|
||||
} from "../../../utils";
|
||||
import { MessageEmbedOptions, Constants, Invite } from "discord.js";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
|
||||
export async function getInviteInfoEmbed(
|
||||
pluginData: GuildPluginData<UtilityPluginType>,
|
||||
inviteCode: string,
|
||||
): Promise<EmbedOptions | null> {
|
||||
const invite = await resolveInvite(pluginData.client, inviteCode, true);
|
||||
): Promise<MessageEmbedOptions | null> {
|
||||
let invite = await resolveInvite(pluginData.client, inviteCode, true);
|
||||
if (!invite) {
|
||||
return null;
|
||||
}
|
||||
|
@ -67,9 +70,7 @@ export async function getInviteInfoEmbed(
|
|||
});
|
||||
|
||||
const channelName =
|
||||
invite.channel.type === Constants.ChannelTypes.GUILD_VOICE
|
||||
? `🔉 ${invite.channel.name}`
|
||||
: `#${invite.channel.name}`;
|
||||
invite.channel.type === ChannelTypeStrings.VOICE ? `🔉 ${invite.channel.name}` : `#${invite.channel.name}`;
|
||||
|
||||
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id);
|
||||
const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x");
|
||||
|
@ -84,7 +85,7 @@ export async function getInviteInfoEmbed(
|
|||
Created: **${channelAge} ago**
|
||||
`);
|
||||
|
||||
if (invite.channel.type !== Constants.ChannelTypes.GUILD_VOICE) {
|
||||
if (invite.channel.type !== ChannelTypeStrings.VOICE) {
|
||||
channelInfo += `\nMention: <#${invite.channel.id}>`;
|
||||
}
|
||||
|
||||
|
@ -113,16 +114,17 @@ export async function getInviteInfoEmbed(
|
|||
fields: [],
|
||||
};
|
||||
|
||||
invite = invite as GroupDMInvite;
|
||||
embed.author = {
|
||||
name: invite.channel.name ? `Group DM invite: ${invite.channel.name}` : `Group DM invite`,
|
||||
url: `https://discord.gg/${invite.code}`,
|
||||
};
|
||||
}; // 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`;
|
||||
}
|
||||
|
||||
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id);
|
||||
}*/ const channelCreatedAtTimestamp = snowflakeToTimestamp(
|
||||
invite.channel.id,
|
||||
);
|
||||
const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x");
|
||||
const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, {
|
||||
largest: 2,
|
||||
|
|
|
@ -6,6 +6,8 @@ import humanizeDuration from "humanize-duration";
|
|||
import { chunkMessageLines, EmbedWith, messageLink, preEmbedPadding, trimEmptyLines, trimLines } from "../../../utils";
|
||||
import { getDefaultPrefix } from "knub/dist/commands/commandUtils";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageEmbedOptions, Constants, TextChannel } from "discord.js";
|
||||
import { MessageTypeStrings } from "src/types";
|
||||
|
||||
const MESSAGE_ICON = "https://cdn.discordapp.com/attachments/740650744830623756/740685652152025088/message.png";
|
||||
|
||||
|
@ -14,8 +16,10 @@ export async function getMessageInfoEmbed(
|
|||
channelId: string,
|
||||
messageId: string,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions | null> {
|
||||
const message = await pluginData.client.getMessage(channelId, messageId).catch(() => null);
|
||||
): Promise<MessageEmbedOptions | null> {
|
||||
const message = await (pluginData.guild.channels.resolve(channelId) as TextChannel).messages
|
||||
.fetch(messageId)
|
||||
.catch(() => null);
|
||||
if (!message) {
|
||||
return null;
|
||||
}
|
||||
|
@ -36,12 +40,12 @@ export async function getMessageInfoEmbed(
|
|||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
||||
: timeAndDate.inGuildTz(createdAt);
|
||||
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const messageAge = humanizeDuration(Date.now() - message.createdAt, {
|
||||
const messageAge = humanizeDuration(Date.now() - message.createdTimestamp, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
||||
const editedAt = message.editedTimestamp && moment.utc(message.editedTimestamp, "x");
|
||||
const editedAt = message.editedTimestamp ? moment.utc(message.editedTimestamp!, "x") : undefined;
|
||||
const tzEditedAt = requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, editedAt)
|
||||
: timeAndDate.inGuildTz(editedAt);
|
||||
|
@ -55,16 +59,16 @@ export async function getMessageInfoEmbed(
|
|||
|
||||
const type =
|
||||
{
|
||||
[Constants.MessageTypes.DEFAULT]: "Regular message",
|
||||
[Constants.MessageTypes.CHANNEL_PINNED_MESSAGE]: "System message",
|
||||
[Constants.MessageTypes.GUILD_MEMBER_JOIN]: "System message",
|
||||
[Constants.MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION]: "System message",
|
||||
[Constants.MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1]: "System message",
|
||||
[Constants.MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2]: "System message",
|
||||
[Constants.MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3]: "System message",
|
||||
[Constants.MessageTypes.CHANNEL_FOLLOW_ADD]: "System message",
|
||||
[Constants.MessageTypes.GUILD_DISCOVERY_DISQUALIFIED]: "System message",
|
||||
[Constants.MessageTypes.GUILD_DISCOVERY_REQUALIFIED]: "System message",
|
||||
[MessageTypeStrings.DEFAULT]: "Regular message",
|
||||
[MessageTypeStrings.PINS_ADD]: "System message",
|
||||
[MessageTypeStrings.GUILD_MEMBER_JOIN]: "System message",
|
||||
[MessageTypeStrings.USER_PREMIUM_GUILD_SUBSCRIPTION]: "System message",
|
||||
[MessageTypeStrings.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1]: "System message",
|
||||
[MessageTypeStrings.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2]: "System message",
|
||||
[MessageTypeStrings.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3]: "System message",
|
||||
[MessageTypeStrings.CHANNEL_FOLLOW_ADD]: "System message",
|
||||
[MessageTypeStrings.GUILD_DISCOVERY_DISQUALIFIED]: "System message",
|
||||
[MessageTypeStrings.GUILD_DISCOVERY_REQUALIFIED]: "System message",
|
||||
}[message.type] || "Unknown";
|
||||
|
||||
embed.fields.push({
|
||||
|
@ -87,12 +91,12 @@ export async function getMessageInfoEmbed(
|
|||
? await timeAndDate.inMemberTz(requestMemberId, authorCreatedAt)
|
||||
: timeAndDate.inGuildTz(authorCreatedAt);
|
||||
const prettyAuthorCreatedAt = tzAuthorCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const authorAccountAge = humanizeDuration(Date.now() - message.author.createdAt, {
|
||||
const authorAccountAge = humanizeDuration(Date.now() - message.author.createdTimestamp, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
||||
const authorJoinedAt = message.member && moment.utc(message.member.joinedAt, "x");
|
||||
const authorJoinedAt = message.member && moment.utc(message.member.joinedTimestamp!, "x");
|
||||
const tzAuthorJoinedAt = authorJoinedAt
|
||||
? requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, authorJoinedAt)
|
||||
|
@ -101,7 +105,7 @@ export async function getMessageInfoEmbed(
|
|||
const prettyAuthorJoinedAt = tzAuthorJoinedAt?.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const authorServerAge =
|
||||
message.member &&
|
||||
humanizeDuration(Date.now() - message.member.joinedAt, {
|
||||
humanizeDuration(Date.now() - message.member.joinedTimestamp!, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
@ -126,7 +130,7 @@ export async function getMessageInfoEmbed(
|
|||
});
|
||||
}
|
||||
|
||||
if (message.attachments.length) {
|
||||
if (message.attachments.size) {
|
||||
embed.fields.push({
|
||||
name: preEmbedPadding + "Attachments",
|
||||
value: message.attachments[0].url,
|
||||
|
|
|
@ -4,6 +4,7 @@ import { trimLines, preEmbedPadding, EmbedWith } from "../../../utils";
|
|||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { Role, MessageEmbedOptions } from "discord.js";
|
||||
|
||||
const MENTION_ICON = "https://cdn.discordapp.com/attachments/705009450855039042/839284872152481792/mention.png";
|
||||
|
||||
|
@ -11,7 +12,7 @@ export async function getRoleInfoEmbed(
|
|||
pluginData: GuildPluginData<UtilityPluginType>,
|
||||
role: Role,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions> {
|
||||
): Promise<MessageEmbedOptions> {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
@ -29,12 +30,12 @@ export async function getRoleInfoEmbed(
|
|||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
||||
: timeAndDate.inGuildTz(createdAt);
|
||||
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const roleAge = humanizeDuration(Date.now() - role.createdAt, {
|
||||
const roleAge = humanizeDuration(Date.now() - role.createdTimestamp, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
||||
const rolePerms = Object.keys(role.permissions.json).map(p =>
|
||||
const rolePerms = Object.keys(role.permissions.toJSON()).map(p =>
|
||||
p
|
||||
// Voice channel related permission names start with 'voice'
|
||||
.replace(/^voice/i, "")
|
||||
|
@ -44,7 +45,7 @@ export async function getRoleInfoEmbed(
|
|||
);
|
||||
|
||||
// -1 because of the @everyone role
|
||||
const totalGuildRoles = pluginData.guild.roles.size - 1;
|
||||
const totalGuildRoles = pluginData.guild.roles.cache.size - 1;
|
||||
|
||||
embed.fields.push({
|
||||
name: preEmbedPadding + "Role information",
|
||||
|
|
|
@ -17,16 +17,17 @@ import moment from "moment-timezone";
|
|||
import humanizeDuration from "humanize-duration";
|
||||
import { getGuildPreview } from "./getGuildPreview";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageEmbedOptions, CategoryChannel, TextChannel, VoiceChannel } from "discord.js";
|
||||
|
||||
export async function getServerInfoEmbed(
|
||||
pluginData: GuildPluginData<UtilityPluginType>,
|
||||
serverId: string,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions | null> {
|
||||
): Promise<MessageEmbedOptions | null> {
|
||||
const thisServer = serverId === pluginData.guild.id ? pluginData.guild : null;
|
||||
const [restGuild, guildPreview] = await Promise.all([
|
||||
thisServer
|
||||
? memoize(() => pluginData.client.getRESTGuild(serverId), `getRESTGuild_${serverId}`, 10 * MINUTES)
|
||||
? memoize(() => pluginData.client.guilds.fetch(serverId), `getRESTGuild_${serverId}`, 10 * MINUTES)
|
||||
: null,
|
||||
getGuildPreview(pluginData.client, serverId),
|
||||
]);
|
||||
|
@ -46,12 +47,12 @@ export async function getServerInfoEmbed(
|
|||
|
||||
embed.author = {
|
||||
name: `Server: ${(guildPreview || restGuild)!.name}`,
|
||||
icon_url: (guildPreview || restGuild)!.iconURL ?? undefined,
|
||||
iconURL: (guildPreview || restGuild)!.iconURL() ?? undefined,
|
||||
};
|
||||
|
||||
// BASIC INFORMATION
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
const createdAt = moment.utc((guildPreview || restGuild)!.createdAt, "x");
|
||||
const createdAt = moment.utc((guildPreview || restGuild)!.id, "x"); // FIXME ID -> Timestamp
|
||||
const tzCreatedAt = requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
||||
: timeAndDate.inGuildTz(createdAt);
|
||||
|
@ -86,7 +87,7 @@ export async function getServerInfoEmbed(
|
|||
const bannerUrl = restGuild?.bannerURL ? `[Link](${restGuild.bannerURL})` : "None";
|
||||
const splashUrl =
|
||||
(restGuild || guildPreview)!.splashURL != null
|
||||
? `[Link](${(restGuild || guildPreview)!.splashURL?.replace("size=128", "size=2048")})`
|
||||
? `[Link](${(restGuild || guildPreview)!.splashURL()?.replace("size=128", "size=2048")})`
|
||||
: "None";
|
||||
|
||||
embed.fields.push(
|
||||
|
@ -113,33 +114,33 @@ export async function getServerInfoEmbed(
|
|||
restGuild?.approximateMemberCount ||
|
||||
restGuild?.memberCount ||
|
||||
thisServer?.memberCount ||
|
||||
thisServer?.members.size ||
|
||||
thisServer?.members.cache.size ||
|
||||
0;
|
||||
|
||||
let onlineMemberCount = (guildPreview?.approximatePresenceCount || restGuild?.approximatePresenceCount)!;
|
||||
|
||||
if (onlineMemberCount == null && restGuild?.vanityURL) {
|
||||
if (onlineMemberCount == null && restGuild?.vanityURLCode) {
|
||||
// For servers with a vanity URL, we can also use the numbers from the invite for online count
|
||||
const invite = await resolveInvite(pluginData.client, restGuild.vanityURL!, true);
|
||||
const invite = await resolveInvite(pluginData.client, restGuild.vanityURLCode!, true);
|
||||
if (invite && inviteHasCounts(invite)) {
|
||||
onlineMemberCount = invite.presenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
if (!onlineMemberCount && thisServer) {
|
||||
onlineMemberCount = thisServer.members.filter(m => m.status !== "offline").length; // Extremely inaccurate fallback
|
||||
onlineMemberCount = thisServer.members.cache.filter(m => m.presence.status !== "offline").size; // Extremely inaccurate fallback
|
||||
}
|
||||
|
||||
const offlineMemberCount = totalMembers - onlineMemberCount;
|
||||
|
||||
let memberCountTotalLines = `Total: **${formatNumber(totalMembers)}**`;
|
||||
if (restGuild?.maxMembers) {
|
||||
memberCountTotalLines += `\nMax: **${formatNumber(restGuild.maxMembers)}**`;
|
||||
if (restGuild?.maximumMembers) {
|
||||
memberCountTotalLines += `\nMax: **${formatNumber(restGuild.maximumMembers)}**`;
|
||||
}
|
||||
|
||||
let memberCountOnlineLines = `Online: **${formatNumber(onlineMemberCount)}**`;
|
||||
if (restGuild?.maxPresences) {
|
||||
memberCountOnlineLines += `\nMax online: **${formatNumber(restGuild.maxPresences)}**`;
|
||||
if (restGuild?.maximumPresences) {
|
||||
memberCountOnlineLines += `\nMax online: **${formatNumber(restGuild.maximumPresences)}**`;
|
||||
}
|
||||
|
||||
embed.fields.push({
|
||||
|
@ -154,19 +155,19 @@ export async function getServerInfoEmbed(
|
|||
|
||||
// CHANNEL COUNTS
|
||||
if (thisServer) {
|
||||
const totalChannels = thisServer.channels.size;
|
||||
const categories = thisServer.channels.filter(channel => channel instanceof CategoryChannel);
|
||||
const textChannels = thisServer.channels.filter(channel => channel instanceof TextChannel);
|
||||
const voiceChannels = thisServer.channels.filter(channel => channel instanceof VoiceChannel);
|
||||
const totalChannels = thisServer.channels.cache.size;
|
||||
const categories = thisServer.channels.cache.filter(channel => channel instanceof CategoryChannel);
|
||||
const textChannels = thisServer.channels.cache.filter(channel => channel instanceof TextChannel);
|
||||
const voiceChannels = thisServer.channels.cache.filter(channel => channel instanceof VoiceChannel);
|
||||
|
||||
embed.fields.push({
|
||||
name: preEmbedPadding + "Channels",
|
||||
inline: true,
|
||||
value: trimLines(`
|
||||
Total: **${totalChannels}** / 500
|
||||
Categories: **${categories.length}**
|
||||
Text: **${textChannels.length}**
|
||||
Voice: **${voiceChannels.length}**
|
||||
Categories: **${categories.size}**
|
||||
Text: **${textChannels.size}**
|
||||
Voice: **${voiceChannels.size}**
|
||||
`),
|
||||
});
|
||||
}
|
||||
|
@ -175,7 +176,7 @@ export async function getServerInfoEmbed(
|
|||
const otherStats: string[] = [];
|
||||
|
||||
if (thisServer) {
|
||||
otherStats.push(`Roles: **${thisServer.roles.size}** / 250`);
|
||||
otherStats.push(`Roles: **${thisServer.roles.cache.size}** / 250`);
|
||||
}
|
||||
|
||||
if (restGuild) {
|
||||
|
@ -186,9 +187,9 @@ export async function getServerInfoEmbed(
|
|||
2: 150,
|
||||
3: 250,
|
||||
}[restGuild.premiumTier] || 50;
|
||||
otherStats.push(`Emojis: **${restGuild.emojis.length}** / ${maxEmojis * 2}`);
|
||||
otherStats.push(`Emojis: **${restGuild.emojis.cache.size}** / ${maxEmojis * 2}`);
|
||||
} else {
|
||||
otherStats.push(`Emojis: **${guildPreview!.emojis.length}**`);
|
||||
otherStats.push(`Emojis: **${guildPreview!.emojis.size}**`);
|
||||
}
|
||||
|
||||
if (thisServer) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import { CaseTypes } from "../../../data/CaseTypes";
|
|||
import humanizeDuration from "humanize-duration";
|
||||
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageEmbedOptions } from "discord.js";
|
||||
|
||||
const SNOWFLAKE_ICON = "https://cdn.discordapp.com/attachments/740650744830623756/742020790471491668/snowflake.png";
|
||||
|
||||
|
@ -22,7 +23,7 @@ export async function getSnowflakeInfoEmbed(
|
|||
snowflake: string,
|
||||
showUnknownWarning = false,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions> {
|
||||
): Promise<MessageEmbedOptions> {
|
||||
const embed: EmbedWith<"fields"> = {
|
||||
fields: [],
|
||||
};
|
||||
|
|
|
@ -15,13 +15,14 @@ import moment from "moment-timezone";
|
|||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { MessageEmbedOptions, Role } from "discord.js";
|
||||
|
||||
export async function getUserInfoEmbed(
|
||||
pluginData: GuildPluginData<UtilityPluginType>,
|
||||
userId: string,
|
||||
compact = false,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions | null> {
|
||||
): Promise<MessageEmbedOptions | null> {
|
||||
const user = await resolveUser(pluginData.client, userId);
|
||||
if (!user || user instanceof UnknownUser) {
|
||||
return null;
|
||||
|
@ -39,7 +40,7 @@ export async function getUserInfoEmbed(
|
|||
name: `User: ${user.username}#${user.discriminator}`,
|
||||
};
|
||||
|
||||
const avatarURL = user.avatarURL || user.defaultAvatarURL;
|
||||
const avatarURL = user.avatarURL() || user.defaultAvatarURL;
|
||||
embed.author.icon_url = avatarURL;
|
||||
|
||||
const createdAt = moment.utc(user.createdAt, "x");
|
||||
|
@ -47,7 +48,7 @@ export async function getUserInfoEmbed(
|
|||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
||||
: timeAndDate.inGuildTz(createdAt);
|
||||
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const accountAge = humanizeDuration(moment.utc().valueOf() - user.createdAt, {
|
||||
const accountAge = humanizeDuration(moment.utc().valueOf() - user.createdTimestamp, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
@ -61,12 +62,12 @@ export async function getUserInfoEmbed(
|
|||
`),
|
||||
});
|
||||
if (member) {
|
||||
const joinedAt = moment.utc(member.joinedAt, "x");
|
||||
const joinedAt = moment.utc(member.joinedTimestamp!, "x");
|
||||
const tzJoinedAt = requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, joinedAt)
|
||||
: timeAndDate.inGuildTz(joinedAt);
|
||||
const prettyJoinedAt = tzJoinedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const joinAge = humanizeDuration(moment.utc().valueOf() - member.joinedAt, {
|
||||
const joinAge = humanizeDuration(moment.utc().valueOf() - member.joinedTimestamp!, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
@ -92,16 +93,18 @@ export async function getUserInfoEmbed(
|
|||
});
|
||||
|
||||
if (member) {
|
||||
const joinedAt = moment.utc(member.joinedAt, "x");
|
||||
const joinedAt = moment.utc(member.joinedTimestamp!, "x");
|
||||
const tzJoinedAt = requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, joinedAt)
|
||||
: timeAndDate.inGuildTz(joinedAt);
|
||||
const prettyJoinedAt = tzJoinedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
const joinAge = humanizeDuration(moment.utc().valueOf() - member.joinedAt, {
|
||||
const joinAge = humanizeDuration(moment.utc().valueOf() - member.joinedTimestamp!, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
const roles = member.roles.map(id => pluginData.guild.roles.cache.get(id)).filter(r => r != null) as Role[];
|
||||
const roles = member.roles.cache
|
||||
.map(role => pluginData.guild.roles.cache.get(role.id))
|
||||
.filter(r => r != null) as Role[];
|
||||
roles.sort(sorter("position", "DESC"));
|
||||
|
||||
embed.fields.push({
|
||||
|
@ -112,16 +115,14 @@ export async function getUserInfoEmbed(
|
|||
`),
|
||||
});
|
||||
|
||||
const voiceChannel = member.voiceState.channelID
|
||||
? pluginData.guild.channels.cache.get(member.voiceState.channelID)
|
||||
: null;
|
||||
if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) {
|
||||
const voiceChannel = member.voice.channelID ? pluginData.guild.channels.cache.get(member.voice.channelID) : null;
|
||||
if (voiceChannel || member.voice.mute || member.voice.deaf) {
|
||||
embed.fields.push({
|
||||
name: preEmbedPadding + "Voice information",
|
||||
value: trimLines(`
|
||||
${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""}
|
||||
${member.voiceState.mute ? "Server voice muted: **Yes**" : ""}
|
||||
${member.voiceState.deaf ? "Server voice deafened: **Yes**" : ""}
|
||||
${member.voice.mute ? "Server voice muted: **Yes**" : ""}
|
||||
${member.voice.deaf ? "Server voice deafened: **Yes**" : ""}
|
||||
`),
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue