2021-04-06 06:15:17 +00:00
|
|
|
|
import {MessageEmbed, version as djsversion, Guild, User, GuildMember} from "discord.js";
|
2020-12-15 01:44:28 +00:00
|
|
|
|
import ms from "ms";
|
|
|
|
|
import os from "os";
|
2021-04-10 11:41:48 +00:00
|
|
|
|
import {Command, NamedCommand, getMemberByName, CHANNEL_TYPE} from "../../core";
|
2021-04-05 04:35:12 +00:00
|
|
|
|
import {formatBytes, trimArray} from "../../lib";
|
2021-03-31 03:22:25 +00:00
|
|
|
|
import {verificationLevels, filterLevels, regions} from "../../defs/info";
|
2021-04-05 04:35:12 +00:00
|
|
|
|
import moment, {utc} from "moment";
|
2020-12-15 01:44:28 +00:00
|
|
|
|
|
2021-04-05 04:35:12 +00:00
|
|
|
|
export default new NamedCommand({
|
2020-12-15 07:56:09 +00:00
|
|
|
|
description: "Command to provide all sorts of info about the current server, a user, etc.",
|
2021-04-06 06:15:17 +00:00
|
|
|
|
async run({message, channel, guild, author, member, client, args}) {
|
|
|
|
|
channel.send(await getUserInfo(author, member));
|
|
|
|
|
},
|
2020-12-15 01:44:28 +00:00
|
|
|
|
subcommands: {
|
2021-04-05 04:35:12 +00:00
|
|
|
|
avatar: new NamedCommand({
|
2020-12-15 01:44:28 +00:00
|
|
|
|
description: "Shows your own, or another user's avatar.",
|
|
|
|
|
usage: "(<user>)",
|
2021-04-05 04:35:12 +00:00
|
|
|
|
async run({message, channel, guild, author, member, client, args}) {
|
|
|
|
|
channel.send(author.displayAvatarURL({dynamic: true, size: 2048}));
|
2020-12-15 01:44:28 +00:00
|
|
|
|
},
|
2021-04-06 06:15:17 +00:00
|
|
|
|
id: "user",
|
2020-12-15 01:44:28 +00:00
|
|
|
|
user: new Command({
|
|
|
|
|
description: "Shows your own, or another user's avatar.",
|
2021-04-05 04:35:12 +00:00
|
|
|
|
async run({message, channel, guild, author, member, client, args}) {
|
|
|
|
|
channel.send(
|
|
|
|
|
args[0].displayAvatarURL({
|
2020-12-15 01:44:28 +00:00
|
|
|
|
dynamic: true,
|
|
|
|
|
size: 2048
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-03-30 23:14:15 +00:00
|
|
|
|
}),
|
|
|
|
|
any: new Command({
|
|
|
|
|
description: "Shows another user's avatar by searching their name",
|
2021-04-06 06:15:17 +00:00
|
|
|
|
channelType: CHANNEL_TYPE.GUILD,
|
|
|
|
|
async run({message, channel, guild, author, client, args}) {
|
|
|
|
|
const name = args.join(" ");
|
2021-04-10 11:41:48 +00:00
|
|
|
|
const member = await getMemberByName(guild!, name);
|
2021-03-30 23:14:15 +00:00
|
|
|
|
|
2021-04-10 11:41:48 +00:00
|
|
|
|
if (member instanceof GuildMember) {
|
2021-04-06 06:15:17 +00:00
|
|
|
|
channel.send(
|
|
|
|
|
member.user.displayAvatarURL({
|
|
|
|
|
dynamic: true,
|
|
|
|
|
size: 2048
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2021-04-10 11:41:48 +00:00
|
|
|
|
channel.send(member);
|
2021-03-30 23:14:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-15 01:44:28 +00:00
|
|
|
|
})
|
|
|
|
|
}),
|
2021-04-05 04:35:12 +00:00
|
|
|
|
bot: new NamedCommand({
|
2020-12-15 01:44:28 +00:00
|
|
|
|
description: "Displays info about the bot.",
|
2021-04-05 04:35:12 +00:00
|
|
|
|
async run({message, channel, guild, author, member, client, args}) {
|
2020-12-15 01:44:28 +00:00
|
|
|
|
const core = os.cpus()[0];
|
|
|
|
|
const embed = new MessageEmbed()
|
2021-04-05 04:35:12 +00:00
|
|
|
|
.setColor(guild?.me?.displayHexColor || "BLUE")
|
2020-12-15 01:44:28 +00:00
|
|
|
|
.addField("General", [
|
2021-04-05 04:35:12 +00:00
|
|
|
|
`**❯ Client:** ${client.user?.tag} (${client.user?.id})`,
|
|
|
|
|
`**❯ Servers:** ${client.guilds.cache.size.toLocaleString()}`,
|
|
|
|
|
`**❯ Users:** ${client.guilds.cache
|
2020-12-15 07:56:09 +00:00
|
|
|
|
.reduce((a: any, b: {memberCount: any}) => a + b.memberCount, 0)
|
2020-12-15 01:44:28 +00:00
|
|
|
|
.toLocaleString()}`,
|
2021-04-05 04:35:12 +00:00
|
|
|
|
`**❯ Channels:** ${client.channels.cache.size.toLocaleString()}`,
|
|
|
|
|
`**❯ Creation Date:** ${utc(client.user?.createdTimestamp).format("Do MMMM YYYY HH:mm:ss")}`,
|
2020-12-15 01:44:28 +00:00
|
|
|
|
`**❯ Node.JS:** ${process.version}`,
|
2021-01-26 13:22:23 +00:00
|
|
|
|
`**❯ Version:** v${process.env.npm_package_version}`,
|
2020-12-15 01:44:28 +00:00
|
|
|
|
`**❯ Discord.JS:** ${djsversion}`,
|
|
|
|
|
"\u200b"
|
|
|
|
|
])
|
|
|
|
|
.addField("System", [
|
|
|
|
|
`**❯ Platform:** ${process.platform}`,
|
|
|
|
|
`**❯ Uptime:** ${ms(os.uptime() * 1000, {
|
|
|
|
|
long: true
|
|
|
|
|
})}`,
|
|
|
|
|
`**❯ CPU:**`,
|
|
|
|
|
`\u3000 • Cores: ${os.cpus().length}`,
|
|
|
|
|
`\u3000 • Model: ${core.model}`,
|
|
|
|
|
`\u3000 • Speed: ${core.speed}MHz`,
|
|
|
|
|
`**❯ Memory:**`,
|
2020-12-15 07:56:09 +00:00
|
|
|
|
`\u3000 • Total: ${formatBytes(process.memoryUsage().heapTotal)}`,
|
2021-01-29 13:34:46 +00:00
|
|
|
|
`\u3000 • Used: ${formatBytes(process.memoryUsage().heapUsed)}`
|
2020-12-15 01:44:28 +00:00
|
|
|
|
])
|
|
|
|
|
.setTimestamp();
|
2021-04-05 04:35:12 +00:00
|
|
|
|
const avatarURL = client.user?.displayAvatarURL({
|
2021-01-29 17:15:18 +00:00
|
|
|
|
dynamic: true,
|
|
|
|
|
size: 2048
|
|
|
|
|
});
|
|
|
|
|
if (avatarURL) embed.setThumbnail(avatarURL);
|
2021-04-05 04:35:12 +00:00
|
|
|
|
channel.send(embed);
|
2020-12-15 01:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}),
|
2021-04-05 04:35:12 +00:00
|
|
|
|
guild: new NamedCommand({
|
2021-03-28 14:34:31 +00:00
|
|
|
|
description: "Displays info about the current guild or another guild.",
|
|
|
|
|
usage: "(<guild name>/<guild ID>)",
|
2021-04-06 06:15:17 +00:00
|
|
|
|
channelType: CHANNEL_TYPE.GUILD,
|
2021-04-05 04:35:12 +00:00
|
|
|
|
async run({message, channel, guild, author, member, client, args}) {
|
2021-04-06 06:15:17 +00:00
|
|
|
|
channel.send(await getGuildInfo(guild!, guild));
|
2021-03-28 14:34:31 +00:00
|
|
|
|
},
|
|
|
|
|
any: new Command({
|
|
|
|
|
description: "Display info about a guild by finding its name or ID.",
|
2021-04-05 04:35:12 +00:00
|
|
|
|
async run({message, channel, guild, author, member, client, args}) {
|
2021-03-28 14:34:31 +00:00
|
|
|
|
// If a guild ID is provided (avoid the "number" subcommand because of inaccuracies), search for that guild
|
2021-04-10 04:06:16 +00:00
|
|
|
|
if (args.length === 1 && /^\d{17,}$/.test(args[0])) {
|
2021-04-05 04:35:12 +00:00
|
|
|
|
const id = args[0];
|
2021-04-06 06:15:17 +00:00
|
|
|
|
const targetGuild = client.guilds.cache.get(id);
|
2021-03-28 14:34:31 +00:00
|
|
|
|
|
2021-04-06 06:15:17 +00:00
|
|
|
|
if (targetGuild) {
|
|
|
|
|
channel.send(await getGuildInfo(targetGuild, guild));
|
2021-03-28 14:34:31 +00:00
|
|
|
|
} else {
|
2021-04-05 04:35:12 +00:00
|
|
|
|
channel.send(`None of the servers I'm in matches the guild ID \`${id}\`!`);
|
2021-03-28 14:34:31 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2021-04-05 04:35:12 +00:00
|
|
|
|
const query: string = args.join(" ").toLowerCase();
|
2021-04-06 06:15:17 +00:00
|
|
|
|
const targetGuild = client.guilds.cache.find((guild) =>
|
|
|
|
|
guild.name.toLowerCase().includes(query)
|
|
|
|
|
);
|
2021-03-28 14:34:31 +00:00
|
|
|
|
|
2021-04-06 06:15:17 +00:00
|
|
|
|
if (targetGuild) {
|
|
|
|
|
channel.send(await getGuildInfo(targetGuild, guild));
|
2021-03-28 14:34:31 +00:00
|
|
|
|
} else {
|
2021-04-05 04:35:12 +00:00
|
|
|
|
channel.send(`None of the servers I'm in matches the query \`${query}\`!`);
|
2021-03-28 14:34:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-12-15 01:44:28 +00:00
|
|
|
|
})
|
|
|
|
|
},
|
2021-04-06 06:15:17 +00:00
|
|
|
|
id: "user",
|
2020-12-15 01:44:28 +00:00
|
|
|
|
user: new Command({
|
|
|
|
|
description: "Displays info about mentioned user.",
|
2021-04-05 04:35:12 +00:00
|
|
|
|
async run({message, channel, guild, author, client, args}) {
|
2021-04-06 06:15:17 +00:00
|
|
|
|
const user = args[0] as User;
|
2020-12-15 01:44:28 +00:00
|
|
|
|
// Transforms the User object into a GuildMember object of the current guild.
|
2021-04-06 06:15:17 +00:00
|
|
|
|
const member = guild?.members.resolve(args[0]);
|
|
|
|
|
channel.send(await getUserInfo(user, member));
|
2020-12-15 01:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
2021-03-28 14:34:31 +00:00
|
|
|
|
|
2021-04-06 06:15:17 +00:00
|
|
|
|
async function getUserInfo(user: User, member: GuildMember | null | undefined): Promise<MessageEmbed> {
|
|
|
|
|
const userFlags = (await user.fetchFlags()).toArray();
|
|
|
|
|
|
|
|
|
|
const embed = new MessageEmbed()
|
|
|
|
|
.setThumbnail(user.displayAvatarURL({dynamic: true, size: 512}))
|
|
|
|
|
.setColor("BLUE")
|
|
|
|
|
.addField("User", [
|
|
|
|
|
`**❯ Username:** ${user.username}`,
|
|
|
|
|
`**❯ Discriminator:** ${user.discriminator}`,
|
|
|
|
|
`**❯ ID:** ${user.id}`,
|
|
|
|
|
`**❯ Flags:** ${userFlags.length ? userFlags.join(", ") : "None"}`,
|
|
|
|
|
`**❯ Avatar:** [Link to avatar](${user.displayAvatarURL({
|
|
|
|
|
dynamic: true
|
|
|
|
|
})})`,
|
|
|
|
|
`**❯ Time Created:** ${moment(user.createdTimestamp).format("LT")} ${moment(user.createdTimestamp).format(
|
|
|
|
|
"LL"
|
|
|
|
|
)} ${moment(user.createdTimestamp).fromNow()}`,
|
|
|
|
|
`**❯ Status:** ${user.presence.status}`,
|
|
|
|
|
`**❯ Game:** ${user.presence.activities || "Not playing a game."}`
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if (member) {
|
|
|
|
|
const roles = member.roles.cache
|
|
|
|
|
.sort((a: {position: number}, b: {position: number}) => b.position - a.position)
|
|
|
|
|
.map((role: {toString: () => any}) => role.toString())
|
|
|
|
|
.slice(0, -1);
|
|
|
|
|
|
|
|
|
|
embed
|
|
|
|
|
.setColor(member.displayHexColor)
|
|
|
|
|
.addField("Member", [
|
|
|
|
|
`**❯ Highest Role:** ${
|
|
|
|
|
member.roles.highest.id === member.guild.id ? "None" : member.roles.highest.name
|
|
|
|
|
}`,
|
|
|
|
|
`**❯ Server Join Date:** ${moment(member.joinedAt).format("LL LTS")}`,
|
|
|
|
|
`**❯ Hoist Role:** ${member.roles.hoist ? member.roles.hoist.name : "None"}`,
|
|
|
|
|
`**❯ Roles:** [${roles.length}]: ${
|
|
|
|
|
roles.length == 0 ? "None" : roles.length <= 10 ? roles.join(", ") : trimArray(roles).join(", ")
|
|
|
|
|
}`
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return embed;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 14:34:31 +00:00
|
|
|
|
async function getGuildInfo(guild: Guild, currentGuild: Guild | null) {
|
|
|
|
|
const members = await guild.members.fetch({
|
|
|
|
|
withPresences: true,
|
|
|
|
|
force: true
|
|
|
|
|
});
|
|
|
|
|
const roles = guild.roles.cache.sort((a, b) => b.position - a.position).map((role) => role.toString());
|
|
|
|
|
const channels = guild.channels.cache;
|
|
|
|
|
const emojis = guild.emojis.cache;
|
|
|
|
|
const iconURL = guild.iconURL({dynamic: true});
|
|
|
|
|
const embed = new MessageEmbed().setDescription(`**Guild information for __${guild.name}__**`).setColor("BLUE");
|
|
|
|
|
const displayRoles = !!(currentGuild && guild.id === currentGuild.id);
|
|
|
|
|
if (iconURL) {
|
|
|
|
|
embed
|
|
|
|
|
.setThumbnail(iconURL)
|
|
|
|
|
.addField("General", [
|
|
|
|
|
`**❯ Name:** ${guild.name}`,
|
|
|
|
|
`**❯ ID:** ${guild.id}`,
|
|
|
|
|
`**❯ Owner:** ${guild.owner?.user.tag} (${guild.ownerID})`,
|
|
|
|
|
`**❯ Region:** ${regions[guild.region]}`,
|
|
|
|
|
`**❯ Boost Tier:** ${guild.premiumTier ? `Tier ${guild.premiumTier}` : "None"}`,
|
|
|
|
|
`**❯ Explicit Filter:** ${filterLevels[guild.explicitContentFilter]}`,
|
|
|
|
|
`**❯ Verification Level:** ${verificationLevels[guild.verificationLevel]}`,
|
|
|
|
|
`**❯ Time Created:** ${moment(guild.createdTimestamp).format("LT")} ${moment(
|
|
|
|
|
guild.createdTimestamp
|
|
|
|
|
).format("LL")} ${moment(guild.createdTimestamp).fromNow()}`,
|
|
|
|
|
"\u200b"
|
|
|
|
|
])
|
|
|
|
|
.addField("Statistics", [
|
|
|
|
|
`**❯ Role Count:** ${roles.length}`,
|
|
|
|
|
`**❯ Emoji Count:** ${emojis.size}`,
|
|
|
|
|
`**❯ Regular Emoji Count:** ${emojis.filter((emoji) => !emoji.animated).size}`,
|
|
|
|
|
`**❯ Animated Emoji Count:** ${emojis.filter((emoji) => emoji.animated).size}`,
|
|
|
|
|
`**❯ Member Count:** ${guild.memberCount}`,
|
|
|
|
|
`**❯ Humans:** ${members.filter((member) => !member.user.bot).size}`,
|
|
|
|
|
`**❯ Bots:** ${members.filter((member) => member.user.bot).size}`,
|
|
|
|
|
`**❯ Text Channels:** ${channels.filter((channel) => channel.type === "text").size}`,
|
|
|
|
|
`**❯ Voice Channels:** ${channels.filter((channel) => channel.type === "voice").size}`,
|
|
|
|
|
`**❯ Boost Count:** ${guild.premiumSubscriptionCount || "0"}`,
|
|
|
|
|
`\u200b`
|
|
|
|
|
])
|
|
|
|
|
.addField("Presence", [
|
|
|
|
|
`**❯ Online:** ${members.filter((member) => member.presence.status === "online").size}`,
|
|
|
|
|
`**❯ Idle:** ${members.filter((member) => member.presence.status === "idle").size}`,
|
|
|
|
|
`**❯ Do Not Disturb:** ${members.filter((member) => member.presence.status === "dnd").size}`,
|
|
|
|
|
`**❯ Offline:** ${members.filter((member) => member.presence.status === "offline").size}`,
|
|
|
|
|
displayRoles ? "\u200b" : ""
|
|
|
|
|
])
|
|
|
|
|
.setTimestamp();
|
|
|
|
|
|
|
|
|
|
// Only add the roles if the guild the bot is sending the message to is the same one that's being requested.
|
|
|
|
|
if (displayRoles) {
|
|
|
|
|
embed.addField(
|
|
|
|
|
`Roles [${roles.length - 1}]`,
|
|
|
|
|
roles.length < 10 ? roles.join(", ") : roles.length > 10 ? trimArray(roles) : "None"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return embed;
|
|
|
|
|
}
|