|
| 1 | +/* |
| 2 | + Copyright (C) 2023 Alexander Emanuelsson (alexemanuelol) |
| 3 | +
|
| 4 | + This program is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation, either version 3 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | +
|
| 9 | + This program is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | +
|
| 17 | + https://github.com/alexemanuelol/rustplusplus |
| 18 | +
|
| 19 | +*/ |
| 20 | + |
| 21 | +const Builder = require('@discordjs/builders'); |
| 22 | + |
| 23 | +const DiscordEmbeds = require('../discordTools/discordEmbeds.js'); |
| 24 | + |
| 25 | +module.exports = { |
| 26 | + name: 'despawn', |
| 27 | + |
| 28 | + getData(client, guildId) { |
| 29 | + return new Builder.SlashCommandBuilder() |
| 30 | + .setName('despawn') |
| 31 | + .setDescription(client.intlGet(guildId, 'commandsStackDesc')) |
| 32 | + .addStringOption(option => option |
| 33 | + .setName('name') |
| 34 | + .setDescription(client.intlGet(guildId, 'theNameOfTheItem')) |
| 35 | + .setRequired(false)) |
| 36 | + .addStringOption(option => option |
| 37 | + .setName('id') |
| 38 | + .setDescription(client.intlGet(guildId, 'theIdOfTheItem')) |
| 39 | + .setRequired(false)); |
| 40 | + }, |
| 41 | + |
| 42 | + async execute(client, interaction) { |
| 43 | + const guildId = interaction.guildId; |
| 44 | + |
| 45 | + const verifyId = Math.floor(100000 + Math.random() * 900000); |
| 46 | + client.logInteraction(interaction, verifyId, 'slashCommand'); |
| 47 | + |
| 48 | + if (!await client.validatePermissions(interaction)) return; |
| 49 | + await interaction.deferReply({ ephemeral: true }); |
| 50 | + |
| 51 | + const despawnItemName = interaction.options.getString('name'); |
| 52 | + const despawnItemId = interaction.options.getString('id'); |
| 53 | + |
| 54 | + let itemId = null; |
| 55 | + if (despawnItemName !== null) { |
| 56 | + const item = client.items.getClosestItemIdByName(despawnItemName) |
| 57 | + if (item === undefined) { |
| 58 | + const str = client.intlGet(guildId, 'noItemWithNameFound', { |
| 59 | + name: despawnItemName |
| 60 | + }); |
| 61 | + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str)); |
| 62 | + client.log(client.intlGet(guildId, 'warningCap'), str); |
| 63 | + return; |
| 64 | + } |
| 65 | + else { |
| 66 | + itemId = item; |
| 67 | + } |
| 68 | + } |
| 69 | + else if (despawnItemId !== null) { |
| 70 | + if (client.items.itemExist(despawnItemId)) { |
| 71 | + itemId = despawnItemId; |
| 72 | + } |
| 73 | + else { |
| 74 | + const str = client.intlGet(guildId, 'noItemWithIdFound', { |
| 75 | + id: despawnItemId |
| 76 | + }); |
| 77 | + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str)); |
| 78 | + client.log(client.intlGet(guildId, 'warningCap'), str); |
| 79 | + return; |
| 80 | + } |
| 81 | + } |
| 82 | + else if (despawnItemName === null && despawnItemId === null) { |
| 83 | + const str = client.intlGet(guildId, 'noNameIdGiven'); |
| 84 | + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str)); |
| 85 | + client.log(client.intlGet(guildId, 'warningCap'), str); |
| 86 | + return; |
| 87 | + } |
| 88 | + const itemName = client.items.getName(itemId); |
| 89 | + |
| 90 | + const despawnDetails = client.rustlabs.getDespawnDetailsById(itemId); |
| 91 | + if (despawnDetails === null) { |
| 92 | + const str = client.intlGet(guildId, 'couldNotFindDespawnDetails', { |
| 93 | + name: itemName |
| 94 | + }); |
| 95 | + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str)); |
| 96 | + client.log(client.intlGet(guildId, 'warningCap'), str); |
| 97 | + return; |
| 98 | + } |
| 99 | + |
| 100 | + const despawnTime = despawnDetails[2].timeString; |
| 101 | + |
| 102 | + client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, 'slashCommandValueChange', { |
| 103 | + id: `${verifyId}`, |
| 104 | + value: `${despawnItemName} ${despawnItemId}` |
| 105 | + })); |
| 106 | + |
| 107 | + const str = client.intlGet(guildId, 'despawnTimeOfItem', { |
| 108 | + item: itemName, |
| 109 | + time: despawnTime |
| 110 | + }); |
| 111 | + |
| 112 | + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(0, str)); |
| 113 | + client.log(client.intlGet(null, 'infoCap'), str); |
| 114 | + }, |
| 115 | +}; |
0 commit comments