mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-22 09:15:03 +00:00
More work on porting Utility commands
This commit is contained in:
parent
55f5509705
commit
f2d4eb1cdf
6 changed files with 187 additions and 45 deletions
|
@ -1,4 +1,4 @@
|
|||
import { CategoryChannel, EmbedOptions, TextChannel, VoiceChannel } from "eris";
|
||||
import { CategoryChannel, EmbedOptions, RESTChannelInvite, TextChannel, VoiceChannel } from "eris";
|
||||
import moment from "moment-timezone";
|
||||
import { embedPadding, formatNumber, memoize, MINUTES, trimLines } from "../../../utils";
|
||||
import { utilityCmd } from "../types";
|
||||
|
@ -10,56 +10,56 @@ export const ServerCmd = utilityCmd({
|
|||
usage: "!server",
|
||||
permission: "can_server",
|
||||
|
||||
async run({ message }) {
|
||||
async run({ message, pluginData }) {
|
||||
const { guild } = pluginData;
|
||||
|
||||
const embed: EmbedOptions = {
|
||||
fields: [],
|
||||
color: parseInt("6b80cf", 16),
|
||||
};
|
||||
|
||||
embed.thumbnail = { url: this.guild.iconURL };
|
||||
embed.thumbnail = { url: guild.iconURL };
|
||||
|
||||
const createdAt = moment(this.guild.createdAt);
|
||||
const serverAge = humanizeDuration(moment().valueOf() - this.guild.createdAt, {
|
||||
const createdAt = moment(guild.createdAt);
|
||||
const serverAge = humanizeDuration(moment().valueOf() - guild.createdAt, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
||||
const owner = this.bot.users.get(this.guild.ownerID);
|
||||
const owner = pluginData.client.users.get(guild.ownerID);
|
||||
const ownerName = owner ? `${owner.username}#${owner.discriminator}` : "Unknown#0000";
|
||||
|
||||
embed.fields.push({
|
||||
name: `Server information - ${this.guild.name}`,
|
||||
name: `Server information - ${guild.name}`,
|
||||
value:
|
||||
trimLines(`
|
||||
Created: **${serverAge} ago** (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})
|
||||
Owner: **${ownerName}** (${this.guild.ownerID})
|
||||
Voice region: **${this.guild.region}**
|
||||
${this.guild.features.length > 0 ? "Features: " + this.guild.features.join(", ") : ""}
|
||||
Owner: **${ownerName}** (${guild.ownerID})
|
||||
Voice region: **${guild.region}**
|
||||
${guild.features.length > 0 ? "Features: " + guild.features.join(", ") : ""}
|
||||
`) + embedPadding,
|
||||
});
|
||||
|
||||
const restGuild = await memoize(
|
||||
() => this.bot.getRESTGuild(this.guildId),
|
||||
`getRESTGuild_${this.guildId}`,
|
||||
() => pluginData.client.getRESTGuild(guild.id),
|
||||
`getRESTGuild_${guild.id}`,
|
||||
10 * MINUTES,
|
||||
);
|
||||
|
||||
// For servers with a vanity URL, we can use the numbers from the invite for online count
|
||||
// (which is nowadays usually more accurate for large servers)
|
||||
const invite = this.guild.vanityURL
|
||||
? await memoize(
|
||||
() => this.bot.getInvite(this.guild.vanityURL, true),
|
||||
`getInvite_${this.guild.vanityURL}`,
|
||||
10 * MINUTES,
|
||||
)
|
||||
const invite = guild.vanityURL
|
||||
? ((await memoize(
|
||||
() => pluginData.client.getInvite(guild.vanityURL, true),
|
||||
`getInvite_${guild.vanityURL}`,
|
||||
10 * MINUTES,
|
||||
)) as RESTChannelInvite)
|
||||
: null;
|
||||
|
||||
const totalMembers = invite ? invite.memberCount : this.guild.memberCount;
|
||||
const totalMembers = invite?.memberCount || guild.memberCount;
|
||||
|
||||
const onlineMemberCount = invite
|
||||
? invite.presenceCount
|
||||
: this.guild.members.filter(m => m.status !== "offline").length;
|
||||
const offlineMemberCount = this.guild.memberCount - onlineMemberCount;
|
||||
const onlineMemberCount = invite ? invite.presenceCount : guild.members.filter(m => m.status !== "offline").length;
|
||||
const offlineMemberCount = guild.memberCount - onlineMemberCount;
|
||||
|
||||
let memberCountTotalLines = `Total: **${formatNumber(totalMembers)}**`;
|
||||
if (restGuild.maxMembers) {
|
||||
|
@ -81,10 +81,10 @@ export const ServerCmd = utilityCmd({
|
|||
`),
|
||||
});
|
||||
|
||||
const totalChannels = this.guild.channels.size;
|
||||
const categories = this.guild.channels.filter(channel => channel instanceof CategoryChannel);
|
||||
const textChannels = this.guild.channels.filter(channel => channel instanceof TextChannel);
|
||||
const voiceChannels = this.guild.channels.filter(channel => channel instanceof VoiceChannel);
|
||||
const totalChannels = guild.channels.size;
|
||||
const categories = guild.channels.filter(channel => channel instanceof CategoryChannel);
|
||||
const textChannels = guild.channels.filter(channel => channel instanceof TextChannel);
|
||||
const voiceChannels = guild.channels.filter(channel => channel instanceof VoiceChannel);
|
||||
|
||||
embed.fields.push({
|
||||
name: "Channels",
|
||||
|
@ -104,16 +104,16 @@ export const ServerCmd = utilityCmd({
|
|||
1: 100,
|
||||
2: 150,
|
||||
3: 250,
|
||||
}[this.guild.premiumTier] || 50;
|
||||
}[guild.premiumTier] || 50;
|
||||
|
||||
embed.fields.push({
|
||||
name: "Other stats",
|
||||
inline: true,
|
||||
value:
|
||||
trimLines(`
|
||||
Roles: **${this.guild.roles.size}** / 250
|
||||
Emojis: **${this.guild.emojis.length}** / ${maxEmojis}
|
||||
Boosts: **${this.guild.premiumSubscriptionCount ?? 0}** (level ${this.guild.premiumTier})
|
||||
Roles: **${guild.roles.size}** / 250
|
||||
Emojis: **${guild.emojis.length}** / ${maxEmojis}
|
||||
Boosts: **${guild.premiumSubscriptionCount ?? 0}** (level ${guild.premiumTier})
|
||||
`) + embedPadding,
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue