2022-08-09 23:48:33 +05:00
|
|
|
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand"),
|
|
|
|
pendings = {};
|
|
|
|
|
|
|
|
class Marry extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../base/Client")} client
|
2022-08-09 23:48:33 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("marry")
|
|
|
|
.setDescription(client.translate("economy/marry:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("economy/marry:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("economy/marry:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(false)
|
2023-07-05 00:58:06 +05:00
|
|
|
.addUserOption(option =>
|
|
|
|
option
|
|
|
|
.setName("user")
|
|
|
|
.setDescription(client.translate("common:USER"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:USER", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:USER", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
),
|
2022-08-09 23:48:33 +05:00
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-09 23:48:33 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
* @param {Object} data
|
|
|
|
*/
|
|
|
|
async execute(client, interaction, data) {
|
|
|
|
if (data.userData.lover) return interaction.error("economy/marry:ALREADY_MARRIED");
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const member = interaction.options.getMember("user");
|
|
|
|
if (member.user.bot) return interaction.error("economy/marry:BOT_USER");
|
|
|
|
if (member.id === interaction.member.id) return interaction.error("economy/marry:YOURSELF");
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2023-10-30 21:45:10 +05:00
|
|
|
const userData = await client.findOrCreateUser(member.id);
|
2022-08-09 23:48:33 +05:00
|
|
|
if (userData.lover) return interaction.error("economy/marry:ALREADY_MARRIED_USER", { user: member.toString() });
|
|
|
|
|
|
|
|
for (const requester in pendings) {
|
|
|
|
const receiver = pendings[requester];
|
|
|
|
|
|
|
|
if (requester === interaction.author.id) {
|
2023-07-05 00:58:06 +05:00
|
|
|
const user = client.users.cache.get(receiver) || (await client.users.fetch(receiver));
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
return interaction.error("economy/marry:REQUEST_AUTHOR_TO_AMEMBER", {
|
2022-12-15 21:02:38 +05:00
|
|
|
user: user.toString,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
} else if (receiver === interaction.member.id) {
|
2023-07-05 00:58:06 +05:00
|
|
|
const user = client.users.cache.get(requester) || (await client.users.fetch(requester));
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
return interaction.error("economy/marry:REQUEST_AMEMBER_TO_AUTHOR", {
|
2022-12-15 21:02:38 +05:00
|
|
|
user: user.toString(),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
} else if (requester === member.id) {
|
2023-07-05 00:58:06 +05:00
|
|
|
const user = client.users.cache.get(receiver) || (await client.users.fetch(receiver));
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
return interaction.error("economy/marry:REQUEST_AMEMBER_TO_MEMBER", {
|
|
|
|
firstUser: member.toString(),
|
2022-12-15 21:02:38 +05:00
|
|
|
secondUser: user.toString(),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
} else if (receiver === member.id) {
|
2023-07-05 00:58:06 +05:00
|
|
|
const user = client.users.cache.get(requester) || (await client.users.fetch(requester));
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
return interaction.error("economy/marry:REQUEST_MEMBER_TO_AMEMBER", {
|
|
|
|
firstUser: member.toString(),
|
2022-12-15 21:02:38 +05:00
|
|
|
secondUser: user.toString(),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pendings[interaction.member.id] = member.id;
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
const row = new ActionRowBuilder().addComponents(
|
|
|
|
new ButtonBuilder().setCustomId("marry_confirm_yes").setLabel(interaction.translate("common:ACCEPT")).setStyle(ButtonStyle.Success),
|
|
|
|
new ButtonBuilder().setCustomId("marry_confirm_no").setLabel(interaction.translate("common:CANCEL")).setStyle(ButtonStyle.Danger),
|
|
|
|
);
|
2022-08-09 23:48:33 +05:00
|
|
|
|
|
|
|
await interaction.reply({
|
|
|
|
content: interaction.translate("economy/marry:REQUEST", {
|
|
|
|
to: member.toString(),
|
2022-12-15 21:02:38 +05:00
|
|
|
from: interaction.member.toString(),
|
2022-08-09 23:48:33 +05:00
|
|
|
}),
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
const filter = i => i.user.id === member.id;
|
2023-07-05 00:58:06 +05:00
|
|
|
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: 10 * 60 * 1000 });
|
2022-08-09 23:48:33 +05:00
|
|
|
|
|
|
|
collector.on("collect", async i => {
|
|
|
|
if (i.isButton()) {
|
|
|
|
if (i.customId === "marry_confirm_yes") return collector.stop(true);
|
|
|
|
else if (i.customId === "marry_confirm_no") return collector.stop(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
collector.on("end", async (_, reason) => {
|
|
|
|
delete pendings[interaction.member.id];
|
2022-08-26 00:21:26 +05:00
|
|
|
if (reason === "time") {
|
2022-08-28 21:53:54 +05:00
|
|
|
row.components.forEach(component => {
|
|
|
|
component.setDisabled(true);
|
|
|
|
});
|
|
|
|
|
2022-08-26 00:21:26 +05:00
|
|
|
return interaction.editReply({
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [row],
|
2022-08-26 00:21:26 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
if (reason) {
|
|
|
|
data.userData.lover = member.id;
|
|
|
|
userData.lover = interaction.member.id;
|
2023-07-03 19:30:47 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
data.userData.markModified("lover");
|
|
|
|
userData.markModified("lover");
|
2023-07-03 19:30:47 +05:00
|
|
|
await data.userData.save();
|
2022-08-09 23:48:33 +05:00
|
|
|
await userData.save();
|
|
|
|
|
|
|
|
const messageOptions = {
|
|
|
|
content: `${member.toString()} :heart: ${interaction.member.toString()}`,
|
2023-07-05 00:58:06 +05:00
|
|
|
files: [
|
|
|
|
{
|
|
|
|
name: "achievement_unlocked3.png",
|
|
|
|
attachment: "./assets/img/achievements/achievement_unlocked3.png",
|
|
|
|
},
|
|
|
|
],
|
2022-08-09 23:48:33 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
let sent = false;
|
|
|
|
if (!userData.achievements.married.achieved) {
|
|
|
|
interaction.followUp(messageOptions);
|
|
|
|
sent = true;
|
|
|
|
userData.achievements.married.achieved = true;
|
|
|
|
userData.achievements.married.progress.now = 1;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
userData.markModified("achievements");
|
2022-08-09 23:48:33 +05:00
|
|
|
await userData.save();
|
|
|
|
}
|
2022-08-26 00:21:26 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
if (!data.userData.achievements.married.achieved) {
|
|
|
|
if (!sent) interaction.followUp(messageOptions);
|
|
|
|
data.userData.achievements.married.achieved = true;
|
|
|
|
data.userData.achievements.married.progress.now = 1;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
data.userData.markModified("achievements");
|
2022-08-09 23:48:33 +05:00
|
|
|
await data.userData.save();
|
|
|
|
}
|
|
|
|
|
2022-08-26 00:21:26 +05:00
|
|
|
return interaction.editReply({
|
|
|
|
content: interaction.translate("economy/marry:SUCCESS", {
|
|
|
|
creator: interaction.member.toString(),
|
2022-12-15 21:02:38 +05:00
|
|
|
partner: member.toString(),
|
2023-11-04 23:06:51 +05:00
|
|
|
}),
|
2022-12-15 21:02:38 +05:00
|
|
|
components: [],
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
2023-11-04 16:56:10 +05:00
|
|
|
} else return interaction.editReply({
|
|
|
|
content: interaction.translate("economy/marry:DENIED", {
|
|
|
|
creator: interaction.member.toString(),
|
|
|
|
partner: member.toString(),
|
|
|
|
}, "error"),
|
|
|
|
components: [],
|
|
|
|
});
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Marry;
|