JaBa/commands/Administration/set.js

118 lines
3.6 KiB
JavaScript
Raw Normal View History

2022-08-08 18:19:56 +05:00
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Set extends BaseCommand {
/**
*
* @param {import("../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("set")
.setDescription(client.translate("administration/set:DESCRIPTION"))
.setDescriptionLocalizations({
"uk": client.translate("administration/set:DESCRIPTION", null, "uk-UA"),
"ru": client.translate("administration/set:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
2022-08-08 18:19:56 +05:00
.addStringOption(option => option.setName("type")
.setDescription(client.translate("owner/debug:TYPE"))
.setDescriptionLocalizations({
"uk": client.translate("owner/debug:TYPE", null, "uk-UA"),
"ru": client.translate("owner/debug:TYPE", null, "ru-RU"),
})
2022-08-08 18:19:56 +05:00
.setRequired(true)
.setChoices(
2022-08-08 18:19:56 +05:00
{ name: client.translate("common:LEVEL"), value: "level" },
{ name: client.translate("common:XP"), value: "xp" },
{ name: client.translate("common:CREDITS"), value: "credits" },
{ name: client.translate("economy/transactions:BANK"), value: "bank" },
2022-08-08 18:19:56 +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"),
})
2022-08-08 18:19:56 +05:00
.setRequired(true))
.addIntegerOption(option => option.setName("int")
.setDescription(client.translate("common:INT"))
.setDescriptionLocalizations({
"uk": client.translate("common:INT", null, "uk-UA"),
"ru": client.translate("common:INT", null, "ru-RU"),
})
2022-08-08 18:19:56 +05:00
.setRequired(true)),
aliases: [],
dirname: __dirname,
ownerOnly: false,
2022-08-08 18:19:56 +05:00
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
2022-08-09 23:48:33 +05:00
* @param {Object} data
2022-08-08 18:19:56 +05:00
*/
2022-10-03 20:24:49 +05:00
async execute(client, interaction) {
const type = interaction.options.getString("type"),
member = interaction.options.getMember("user");
2022-08-08 18:19:56 +05:00
if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true });
2022-10-03 20:24:49 +05:00
const memberData = await client.findOrCreateMember({
id: member.id,
guildId: interaction.guildId,
2022-08-09 23:48:33 +05:00
});
2022-08-08 18:19:56 +05:00
const int = interaction.options.getInteger("int");
if (int < 0) return interaction.error("administration/set:INVALID_NUMBER", null, { ephemeral: true });
switch (type) {
case "level": {
2022-08-09 23:48:33 +05:00
memberData.level = int;
await memberData.save();
return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, {
user: member.toString(),
amount: int,
2022-08-08 18:19:56 +05:00
}, { ephemeral: true });
}
case "xp": {
2022-08-09 23:48:33 +05:00
memberData.exp = int;
await memberData.save();
return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, {
user: member.toString(),
amount: int,
2022-08-08 18:19:56 +05:00
}, { ephemeral: true });
}
case "credits": {
2022-08-09 23:48:33 +05:00
memberData.money = int;
await memberData.save();
return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, {
user: member.toString(),
amount: int,
2022-08-08 18:19:56 +05:00
}, { ephemeral: true });
}
case "bank": {
2022-08-09 23:48:33 +05:00
memberData.bankSold = int;
await memberData.save();
return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, {
user: member.toString(),
amount: int,
2022-08-08 18:19:56 +05:00
}, { ephemeral: true });
}
}
}
}
module.exports = Set;