JaBa/commands/Owner/debug.js

196 lines
6 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Debug extends BaseCommand {
/**
*
* @param {import("../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("debug")
.setDescription(client.translate("owner/debug:DESCRIPTION"))
.setDMPermission(false)
.addSubcommand(subcommand => subcommand.setName("set")
.setDescription(client.translate("owner/debug:SET"))
.addStringOption(option => option.setName("type")
.setDescription(client.translate("owner/debug:TYPE"))
.setRequired(true)
.addChoices(
{ 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" },
{ name: client.translate("common:REP"), value: "rep" },
))
2022-08-08 18:19:56 +05:00
.addUserOption(option => option.setName("user")
.setDescription(client.translate("common:USER"))
.setRequired(true))
.addIntegerOption(option => option.setName("int")
.setDescription(client.translate("common:INT"))
.setRequired(true)),
)
.addSubcommand(subcommand => subcommand.setName("add")
.setDescription(client.translate("owner/debug:ADD"))
.addStringOption(option => option.setName("type")
.setDescription(client.translate("owner/debug:TYPE"))
.setRequired(true)
.addChoices(
{ 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" },
{ name: client.translate("common:REP"), value: "rep" },
))
.addUserOption(option => option.setName("user")
.setDescription(client.translate("common:USER"))
.setRequired(true))
.addIntegerOption(option => option.setName("int")
.setDescription(client.translate("owner/debug:INT"))
.setRequired(true)),
),
aliases: [],
dirname: __dirname,
ownerOnly: true,
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {Array} data
*/
2022-10-03 20:24:49 +05:00
async execute(client, interaction) {
2022-08-08 18:19:56 +05:00
const command = interaction.options.getSubcommand();
2022-08-08 18:19:56 +05:00
if (command === "set") {
const type = interaction.options.getString("type");
2022-08-03 21:13:22 +05:00
const 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-08-09 23:48:33 +05:00
const userData = await client.findOrCreateUser({
id: member.id,
2022-08-09 23:48:33 +05:00
});
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
});
const int = interaction.options.getInteger("int");
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()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { 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()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { 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()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { 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()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { ephemeral: true });
}
case "rep": {
2022-08-09 23:48:33 +05:00
userData.rep = int;
await userData.save();
return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { ephemeral: true });
}
}
} else {
const type = interaction.options.getString("type");
const member = interaction.options.getMember("target");
2022-08-08 18:19:56 +05:00
if (member.user.bot) return interaction.error("misc:BOT_USER", null, { ephemeral: true });
2022-08-09 23:48:33 +05:00
const userData = await client.findOrCreateUser({
id: member.id,
2022-08-09 23:48:33 +05:00
});
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
});
const int = interaction.options.getInteger("int");
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()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { 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()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { 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()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { 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()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { ephemeral: true });
}
case "rep": {
2022-08-09 23:48:33 +05:00
userData.rep += int;
await userData.save();
return interaction.success(`owner/debug:SUCCESS_${type.toUpperCase()}`, {
2022-08-08 18:19:56 +05:00
username: member.toString(),
amount: int,
}, { ephemeral: true });
}
}
}
}
}
module.exports = Debug;