Updated the guild subcommands

This commit is contained in:
2023-11-16 23:42:05 +01:00
parent 2873664324
commit 6c7afbe98a
3 changed files with 134 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
const { SlashCommandBuilder } = require('discord.js') const { SlashCommandBuilder } = require('discord.js')
const { color } = require('../config/options.json') const { color } = require('../config/options.json')
const { guildMember } = require('./guild/member.js') const { guildMember } = require('./guild/member.js')
const { guildInfo } = require('./guild/info.js')
module.exports = { module.exports = {
name: 'guild', name: 'guild',
@@ -21,6 +22,17 @@ module.exports = {
.setRequired(true) .setRequired(true)
) )
) )
.addSubcommand(subcommand =>
subcommand
.setName('info')
.setDescription('Get info about a guild.')
.addStringOption(option =>
option
.setName('ign')
.setDescription('The IGN of a member.')
.setRequired(true)
)
)
.setDMPermission(false), .setDMPermission(false),
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */ /** @param { import('discord.js').ChatInputCommandInteraction } interaction */
@@ -37,6 +49,11 @@ module.exports = {
return return
} }
if (subcommand === 'info') {
await guildInfo(interaction)
return
}
await interaction.editReply({ await interaction.editReply({
embeds: [{ embeds: [{
description: "This command is currently under development", description: "This command is currently under development",

103
commands/guild/info.js Normal file
View File

@@ -0,0 +1,103 @@
const { getUUID, getIGN, getPlayer, getGuild, guildLevel } = require("../../utils/utils.js")
const { color } = require("../../config/options.json");
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
async function guildInfo(interaction) {
const ign = interaction.options.getString("ign");
const embedColor = Number(color.replace("#", "0x"));
const uuid = await getUUID(ign)
if (!uuid) {
interaction.editReply({
embeds: [{
description: "That player doen't exist!",
color: embedColor
}]
})
return
}
const player = await getPlayer(uuid)
if (!player) {
interaction.editReply({
embeds: [{
description: "That player has never joined the server!",
color: embedColor
}]
})
return
}
const guild = await getGuild(uuid)
if (!guild) {
interaction.editReply({
embeds: [{
description: "That player is not in a guild!",
color: embedColor
}]
})
return
}
const guildName = guild.name;
const guildCreatedMS = guild.created;
const guildCreated = new Date(guildCreatedMS);
const guildTag = guild.tag;
const guildExp = guild.exp;
const guildLvl = guildLevel(guildExp);
const guildMembers = guild.members
const guildCreatedDate = guildCreated.getDate()
const guildCreatedMonth = guildCreated.getMonth() + 1
const guildCreatedYear = guildCreated.getFullYear()
const guildCreatedHour = guildCreated.getHours()
const guildCreatedMinute = guildCreated.getMinutes()
const guildCreatedSecond = guildCreated.getSeconds()
const guildCreatedTime = guildCreatedDate + "." +
guildCreatedMonth + "." +
guildCreatedYear + " " +
guildCreatedHour + ":" +
guildCreatedMinute + ":" +
guildCreatedSecond
const guildOwner = guildMembers.find((m) => m.rank === "Guild Master").uuid
const guildOwnerName = await getIGN(guildOwner)
const guildRanks = guild.ranks.map((r) => "**➺ " + r.name + "** `[" + r.tag + "]`").join("\n")
const guildMembersDailyXP = Object.values(guildMembers).map((m) => m.expHistory[Object.keys(m.expHistory)[0]])
const totalGuildMembersDailyXP = guildMembersDailyXP.reduce((a, b) => a + b, 0)
await interaction.editReply({
embeds: [{
title: "**Info on** " + guildName,
description: "**Guild Name: **`" + guildName + "`\n" +
"**Guild Tag: **`" + guildTag + "`\n" +
"**Guild Level: **`" + guildLvl + "`\n" +
"**Guild Owner: **`" + guildOwnerName + "`",
fields: [
{
name: "**Guild Ranks**",
value: guildRanks
},
{
name: "**GEXP**",
value: "**➺ Total weekly GEXP:** `" + totalGuildMembersDailyXP + "`"
},
{
name: "**Guild Created**",
value: "**➺ **`" + guildCreatedTime + "`"
}
],
color: embedColor,
footer: {
text: interaction.guild.name + " | Developed by taken.lua",
icon_url: interaction.guild.iconURL({ dynamic: true })
}
}]
})
}
module.exports = { guildInfo }

View File

@@ -1,4 +1,4 @@
const { guildLevel, getUUID, getIGN, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js"); const { getUUID, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js");
const { color } = require("../../config/options.json"); const { color } = require("../../config/options.json");
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */ /** @param { import('discord.js').ChatInputCommandInteraction } interaction */
@@ -23,6 +23,7 @@ async function guildMember(interaction) {
}); });
} }
const head = await getHeadURL(ign);
const player = await getPlayer(uuid); const player = await getPlayer(uuid);
if (!player) { if (!player) {
await interaction.editReply({ await interaction.editReply({
@@ -42,9 +43,9 @@ async function guildMember(interaction) {
}); });
} }
const serverRank = player.data.player.newPackageRank; const serverRank = player.newPackageRank;
const monthlyRank = player.data.player.monthlyPackageRank; const monthlyRank = player.monthlyPackageRank;
const displayName = player.data.player.displayname; const displayName = player.displayname;
if (serverRank === "VIP") { if (serverRank === "VIP") {
var rank = "[VIP] "; var rank = "[VIP] ";
@@ -101,29 +102,19 @@ async function guildMember(interaction) {
const guildMemberJoinSeconds = guildMemberJoinTime.getSeconds(); const guildMemberJoinSeconds = guildMemberJoinTime.getSeconds();
const guildMemberJoin = const guildMemberJoin =
guildMemberJoinDate + guildMemberJoinDate + "." +
"." + guildMemberJoinMonth + "." +
guildMemberJoinMonth + guildMemberJoinYear + " " +
"." + guildMemberJoinHours + ":" +
guildMemberJoinYear + guildMemberJoinMinutes + ":" +
" " +
guildMemberJoinHours +
":" +
guildMemberJoinMinutes +
":" +
guildMemberJoinSeconds; guildMemberJoinSeconds;
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
{ {
title: rank + displayName + guildTag, title: rank + displayName + guildTag,
description: description: "**Guild Name:** `" + guildName + "`\n" +
"**Guild Name:** `" + "**Guild Rank:** `" + guildRank + "`\n",
guildName +
"`\n" +
"**Guild Rank:** `" +
guildRank +
"`\n",
color: embedColor, color: embedColor,
thumbnail: { thumbnail: {
url: head, url: head,
@@ -135,13 +126,8 @@ async function guildMember(interaction) {
}, },
{ {
name: "**Weekly GEXP**", name: "**Weekly GEXP**",
value: value: "**➺ Total:** `" + totalWeeklyGexp + "`\n" +
"**➺ Total:** `" + "**➺ Daily avarage:** `" + averageWeeklyGexp + "`",
totalWeeklyGexp +
"`\n" +
"**➺ Daily avarage:** `" +
averageWeeklyGexp +
"`",
}, },
{ {
name: "**Join date**", name: "**Join date**",