2020-08-05 18:52:15 +03:00
|
|
|
import { PluginData } from "knub";
|
|
|
|
import { UtilityPluginType } from "../types";
|
|
|
|
import { BaseInvite, Constants, EmbedOptions, RESTChannelInvite, RESTPrivateInvite } from "eris";
|
|
|
|
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp";
|
|
|
|
import moment from "moment-timezone";
|
|
|
|
import humanizeDuration from "humanize-duration";
|
2020-08-05 19:32:58 +03:00
|
|
|
import {
|
2020-08-05 20:18:30 +03:00
|
|
|
embedPadding,
|
2020-08-05 19:32:58 +03:00
|
|
|
emptyEmbedValue,
|
|
|
|
formatNumber,
|
|
|
|
isRESTGroupDMInvite,
|
|
|
|
isRESTGuildInvite,
|
2020-08-05 20:18:30 +03:00
|
|
|
preEmbedPadding,
|
2020-08-05 19:32:58 +03:00
|
|
|
resolveInvite,
|
|
|
|
trimLines,
|
|
|
|
} from "../../../utils";
|
2020-08-05 18:52:15 +03:00
|
|
|
|
|
|
|
export async function getInviteInfoEmbed(
|
|
|
|
pluginData: PluginData<UtilityPluginType>,
|
|
|
|
inviteCode: string,
|
|
|
|
): Promise<EmbedOptions | null> {
|
|
|
|
const invite = await resolveInvite(pluginData.client, inviteCode, true);
|
|
|
|
if (!invite) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRESTGuildInvite(invite)) {
|
|
|
|
const embed: EmbedOptions = {
|
|
|
|
fields: [],
|
|
|
|
};
|
|
|
|
|
2020-08-05 20:18:30 +03:00
|
|
|
embed.author = {
|
2020-08-05 22:03:07 +03:00
|
|
|
name: `Server invite: ${invite.guild.name}`,
|
2020-08-05 20:18:30 +03:00
|
|
|
url: `https://discord.gg/${invite.code}`,
|
|
|
|
};
|
|
|
|
|
2020-08-05 18:52:15 +03:00
|
|
|
if (invite.guild.icon) {
|
2020-08-05 20:18:30 +03:00
|
|
|
embed.author.icon_url = `https://cdn.discordapp.com/icons/${invite.guild.id}/${invite.guild.icon}.png?size=256`;
|
2020-08-05 18:52:15 +03:00
|
|
|
}
|
|
|
|
|
2020-08-05 20:18:30 +03:00
|
|
|
if (invite.guild.description) {
|
|
|
|
embed.description = invite.guild.description;
|
|
|
|
}
|
2020-08-05 18:52:15 +03:00
|
|
|
|
2020-08-05 20:18:30 +03:00
|
|
|
const serverCreatedAtTimestamp = snowflakeToTimestamp(invite.guild.id);
|
|
|
|
const serverCreatedAt = moment(serverCreatedAtTimestamp, "x");
|
|
|
|
const serverAge = humanizeDuration(Date.now() - serverCreatedAtTimestamp, {
|
|
|
|
largest: 2,
|
|
|
|
round: true,
|
2020-08-05 18:52:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
embed.fields.push({
|
2020-08-05 20:18:30 +03:00
|
|
|
name: preEmbedPadding + "Server information",
|
|
|
|
value: trimLines(`
|
|
|
|
Name: **${invite.guild.name}**
|
|
|
|
ID: \`${invite.guild.id}\`
|
|
|
|
Created: **${serverAge} ago**
|
|
|
|
Members: **${formatNumber(invite.memberCount)}** (${formatNumber(invite.presenceCount)} online)
|
|
|
|
`),
|
|
|
|
inline: true,
|
2020-08-05 18:52:15 +03:00
|
|
|
});
|
|
|
|
|
2020-08-05 20:18:30 +03:00
|
|
|
const channelName =
|
|
|
|
invite.channel.type === Constants.ChannelTypes.GUILD_VOICE
|
|
|
|
? `🔉 ${invite.channel.name}`
|
|
|
|
: `#${invite.channel.name}`;
|
|
|
|
|
|
|
|
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id);
|
|
|
|
const channelCreatedAt = moment(channelCreatedAtTimestamp, "x");
|
|
|
|
const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, {
|
2020-08-05 18:52:15 +03:00
|
|
|
largest: 2,
|
|
|
|
round: true,
|
|
|
|
});
|
|
|
|
|
2020-08-05 20:18:30 +03:00
|
|
|
let channelInfo = trimLines(`
|
|
|
|
Name: **${channelName}**
|
|
|
|
ID: \`${invite.channel.id}\`
|
|
|
|
Created: **${channelAge} ago**
|
|
|
|
`);
|
|
|
|
|
|
|
|
if (invite.channel.type !== Constants.ChannelTypes.GUILD_VOICE) {
|
|
|
|
channelInfo += `\nMention: <#${invite.channel.id}>`;
|
|
|
|
}
|
2020-08-05 18:52:15 +03:00
|
|
|
|
|
|
|
embed.fields.push({
|
2020-08-05 20:18:30 +03:00
|
|
|
name: preEmbedPadding + "Channel information",
|
|
|
|
value: channelInfo,
|
2020-08-05 18:52:15 +03:00
|
|
|
inline: true,
|
|
|
|
});
|
|
|
|
|
2020-08-05 19:32:58 +03:00
|
|
|
if (invite.inviter) {
|
|
|
|
embed.fields.push({
|
2020-08-05 20:18:30 +03:00
|
|
|
name: preEmbedPadding + "Invite creator",
|
2020-08-05 19:32:58 +03:00
|
|
|
value: trimLines(`
|
2020-08-05 20:18:30 +03:00
|
|
|
Name: **${invite.inviter.username}#${invite.inviter.discriminator}**
|
|
|
|
ID: \`${invite.inviter.id}\`
|
|
|
|
Mention: <@!${invite.inviter.id}>
|
2020-08-05 19:32:58 +03:00
|
|
|
`),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-05 18:52:15 +03:00
|
|
|
return embed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRESTGroupDMInvite(invite)) {
|
|
|
|
const embed: EmbedOptions = {
|
|
|
|
fields: [],
|
|
|
|
};
|
|
|
|
|
2020-08-05 20:18:30 +03:00
|
|
|
embed.author = {
|
2020-08-05 22:03:07 +03:00
|
|
|
name: invite.channel.name ? `Group DM invite: ${invite.channel.name}` : `Group DM invite`,
|
2020-08-05 20:18:30 +03:00
|
|
|
url: `https://discord.gg/${invite.code}`,
|
|
|
|
};
|
|
|
|
|
2020-08-05 18:52:15 +03:00
|
|
|
if (invite.channel.icon) {
|
2020-08-05 20:18:30 +03:00
|
|
|
embed.author.icon_url = `https://cdn.discordapp.com/channel-icons/${invite.channel.id}/${invite.channel.icon}.png?size=256`;
|
2020-08-05 18:52:15 +03:00
|
|
|
}
|
|
|
|
|
2020-08-05 20:18:30 +03:00
|
|
|
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id);
|
|
|
|
const channelCreatedAt = moment(channelCreatedAtTimestamp, "x");
|
|
|
|
const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, {
|
|
|
|
largest: 2,
|
|
|
|
round: true,
|
2020-08-05 18:52:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
embed.fields.push({
|
2020-08-05 20:18:30 +03:00
|
|
|
name: preEmbedPadding + "Group DM information",
|
|
|
|
value: trimLines(`
|
|
|
|
Name: ${invite.channel.name ? `**${invite.channel.name}**` : `_Unknown_`}
|
|
|
|
ID: \`${invite.channel.id}\`
|
|
|
|
Created: **${channelAge} ago**
|
|
|
|
Members: **${formatNumber((invite as any).memberCount)}**
|
|
|
|
`),
|
|
|
|
inline: true,
|
2020-08-05 18:52:15 +03:00
|
|
|
});
|
|
|
|
|
2020-08-05 19:32:58 +03:00
|
|
|
if (invite.inviter) {
|
|
|
|
embed.fields.push({
|
2020-08-05 20:18:30 +03:00
|
|
|
name: preEmbedPadding + "Invite creator",
|
2020-08-05 19:32:58 +03:00
|
|
|
value: trimLines(`
|
2020-08-05 20:18:30 +03:00
|
|
|
Name: **${invite.inviter.username}#${invite.inviter.discriminator}**
|
|
|
|
ID: \`${invite.inviter.id}\`
|
|
|
|
Mention: <@!${invite.inviter.id}>
|
2020-08-05 19:32:58 +03:00
|
|
|
`),
|
2020-08-05 20:18:30 +03:00
|
|
|
inline: true,
|
2020-08-05 19:32:58 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-05 18:52:15 +03:00
|
|
|
return embed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|