JaBa/commands/Fun/lovecalc.js

81 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
md5 = require("md5");
class Lovecalc extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("lovecalc")
.setDescription(client.translate("fun/lovecalc:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("fun/lovecalc:DESCRIPTION", null, "uk-UA"),
ru: client.translate("fun/lovecalc:DESCRIPTION", null, "ru-RU"),
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.Guild])
.addUserOption(option =>
2023-07-05 00:58:06 +05:00
option
.setName("first_member")
.setDescription(client.translate("common:USER"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("common:USER", null, "uk-UA"),
ru: client.translate("common:USER", null, "ru-RU"),
})
2023-07-05 00:58:06 +05:00
.setRequired(true),
)
.addUserOption(option =>
2023-07-05 00:58:06 +05:00
option
.setName("second_member")
.setDescription(client.translate("common:USER"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("common:USER", null, "uk-UA"),
ru: client.translate("common:USER", null, "ru-RU"),
}),
),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async execute(client, interaction) {
const firstMember = interaction.options.getMember("first_member"),
secondMember = interaction.options.getMember("second_member") || interaction.member;
const members = [firstMember, secondMember].sort((a, b) => parseInt(a.id, 10) - parseInt(b.id, 10)),
hash = md5(`${members[0].id}${members[1].user.username}${members[0].user.username}${members[1].id}`);
const string = hash
.split("")
.filter(e => !isNaN(e))
.join("");
const percent = parseInt(string.slice(0, 2), 10);
const embed = client.embed({
author: {
name: `❤️ ${interaction.translate("fun/lovecalc:DESCRIPTION")}`,
},
description: interaction.translate("fun/lovecalc:CONTENT", {
percent,
firstMember: firstMember.user.toString(),
secondMember: secondMember.user.toString(),
}),
});
interaction.reply({
embeds: [embed],
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Lovecalc;