diff --git a/src/commands/market.js b/src/commands/market.js index cbad557c..5a14a3c8 100644 --- a/src/commands/market.js +++ b/src/commands/market.js @@ -1,5 +1,6 @@ /* Copyright (C) 2022 Alexander Emanuelsson (alexemanuelol) + Copyright (C) 2022 René Renken (faithix) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -89,7 +90,22 @@ module.exports = { .setRequired(false))) .addSubcommand(subcommand => subcommand .setName('list') - .setDescription(client.intlGet(guildId, 'commandsMarketListDesc'))); + .setDescription(client.intlGet(guildId, 'commandsMarketListDesc'))) + .addSubcommand(subcommand => subcommand + .setName('blacklist') + .setDescription(client.intlGet(guildId, 'commandsMarketBlaclistDesc')) + .addStringOption(option => option + .setName('choice') + .setDescription(client.intlGet(guildId, 'commandsAddOrRemove')) + .setRequired(true) + .addChoices( + { name: client.intlGet(guildId, 'add'), value: 'add' }, + { name: client.intlGet(guildId, 'remove'), value: 'remove' }, + { name: client.intlGet(guildId, 'show'), value: 'show' })) + .addStringOption(option => option + .setName('name') + .setDescription(client.intlGet(guildId, 'theNameOfTheVendingMachine')) + .setRequired(false))); }, async execute(client, interaction) { @@ -406,6 +422,80 @@ module.exports = { client.intlGet(interaction.guildId, 'showingSubscriptionList')); } break; + case 'blacklist': { + const choice = interaction.options.getString('choice'); + const name = interaction.options.getString('name'); + + if (choice === 'add' && name !== null) { + if (instance.marketBlacklist.includes(name)) { + const str = client.intlGet(interaction.guildId, 'alreadyBlacklisted', { + name: name + }); + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str)); + rustplus.log(client.intlGet(interaction.guildId, 'warningCap'), str); + } + else { + instance.marketBlacklist.push(name); + client.setInstance(interaction.guildId, instance); + + const str = client.intlGet(interaction.guildId, 'justBlacklisted', { + name: name + }); + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(0, str)); + rustplus.log(client.intlGet(interaction.guildId, 'infoCap'), str); + } + } + else if (choice === 'remove' && name !== null) { + if (instance.marketBlacklist.includes(name)) { + instance.marketBlacklist = instance.marketBlacklist.filter(e => e !== name); + client.setInstance(interaction.guildId, instance); + + const str = client.intlGet(interaction.guildId, 'removedBlacklist', { + name: name + }); + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(0, str)); + rustplus.log(client.intlGet(interaction.guildId, 'infoCap'), str); + } + else { + const str = client.intlGet(interaction.guildId, 'notExistInBlacklist', { + name: name + }); + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str)); + rustplus.log(client.intlGet(interaction.guildId, 'warningCap'), str); + } + } + else if (choice === 'show') { + let names = ''; + for (const name of instance.marketBlacklist) { + names += `\`${name}\`\n`; + } + + await client.interactionEditReply(interaction, { + embeds: [DiscordEmbeds.getEmbed({ + color: Constants.COLOR_DEFAULT, + title: client.intlGet(interaction.guildId, 'blacklist'), + footer: { text: instance.serverList[rustplus.serverId].title }, + description: names === '' ? '\u200B' : names + })], + ephemeral: true + }); + + rustplus.log(client.intlGet(interaction.guildId, 'infoCap'), + client.intlGet(interaction.guildId, 'showingBlacklist')); + } + else if (choice === null || name === null) { + const str = client.intlGet(interaction.guildId, 'noNameGiven'); + await client.interactionEditReply(interaction, DiscordEmbeds.getActionInfoEmbed(1, str)); + rustplus.log(client.intlGet(interaction.guildId, 'warningCap'), str); + return; + } + + client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, 'slashCommandValueChange', { + id: `${verifyId}`, + value: `blacklist, ${choice}, ${name}` + })); + } break; + default: { } break; diff --git a/src/languages/en.json b/src/languages/en.json index b523dcd1..66b89671 100644 --- a/src/languages/en.json +++ b/src/languages/en.json @@ -3,6 +3,7 @@ "abandonedCabins": "Abandoned Cabins", "abandonedMilitaryBase": "Abandoned Military Base", "abandonedSupermarket": "Abandoned Supermarket", + "add": "Add", "addPlayerCap": "ADD PLAYER", "addSwitchCap": "ADD SWITCH", "afkCap": "AFK", @@ -16,6 +17,7 @@ "aliases": "Aliases", "all": "all", "allTeammatesAreDead": "All your teammates are dead.", + "alreadyBlacklisted": "Vending Machine {name} is already blacklisted.", "alreadySubscribedToItem": "Already subscribed to item {name}.", "ampersand": "Ampersand", "andMorePlayers": "... and {number} more players.", @@ -167,6 +169,7 @@ "commandSyntaxUptime": "uptime", "commandSyntaxWipe": "wipe", "commandSyntaxWood": "wood", + "commandsAddOrRemove": "Add or Remove a Vending Machine.", "commandsAlarmDesc": "Operations on Smart Alarms.", "commandsAlarmEditDesc": "Edit the properties of a Smart Alarm.", "commandsAlarmEditIdDesc": "The ID of the Smart Alarm.", @@ -208,6 +211,7 @@ "commandsMapDesc": "Get the currently connected server map image.", "commandsMapMarkersDesc": "Get the map including markers.", "commandsMapMonumentsDesc": "Get the map including monument names.", + "commandsMarketBlaclistDesc": "Add or Remove a Vending Machine Name to the Blacklist.", "commandsMarketDesc": "Operations for In-Game Vending Machines.", "commandsMarketListDesc": "Display the subscription list.", "commandsMarketOrderDesc": "The order type.", @@ -428,6 +432,7 @@ "itemAvailableInVendingMachine": "{items} just became available in a Vending Machine at [{location}].", "itemAvailableNotifyInGameSetting": "When an item from the subscription list becomes available in a Vending Machine, notify In-Game?", "junkyard": "Junkyard", + "justBlacklisted": "Vending Machine {name} just got blacklisted.", "justSubscribedToItem": "Just subscribed to item {name}.", "languageCode": "Language code: {code}", "languageLangNotSupported": "The language {language} is not supported.", @@ -499,6 +504,7 @@ "noItemFound": "Item could not be found in any Vending Machines...", "noItemWithIdFound": "No item with id {id} could be found.", "noItemWithNameFound": "No item with name {name} could be found.", + "noNameGiven": "No 'name' was given.", "noNameIdGiven": "No 'name' or 'id' was given.", "noOneIsAfk": "No one is AFK.", "noOneIsOffline": "No one is offline.", @@ -518,6 +524,7 @@ "notAValidOrderType": "{order} is not a valid order type.", "notActive": "Not active.", "notConnectedToRustServer": "Not currently connected to a rust server.", + "notExistInBlacklist": "Vending Machine {name} does not exist in blacklist.", "notExistInSubscription": "Item {name} does not exist in subscription list.", "notFoundCap": "NOT FOUND", "notPartOfRole": "You are not part of the {role} role, therefore you can't run bot commands.", @@ -584,6 +591,8 @@ "recycleCap": "RECYCLE", "recycler": "Recycler", "remain": "left", + "remove": "Remove", + "removedBlacklist": "Vending Machine {name} got removed from the blacklist.", "removePlayerCap": "REMOVE PLAYER", "removeSwitchCap": "REMOVE SWITCH", "removedSubscribeItem": "Item {name} have been removed from subscription.", @@ -634,6 +643,7 @@ "shouldSmartAlarmNotifyNotConnectedSetting": "Should Smart Alarms notify even if they are not setup on the connected rust server?", "shouldSmartAlarmsNotifyInGameSetting": "Should Smart Alarms notify In-Game?", "shouldSmartSwitchNotifyInGameWhenChangedFromDiscord": "Should Smart Switches and Smart Switch Groups notify In-Game when they are changed from discord?", + "show": "Show", "showingBlacklist": "Showing the blacklist.", "showingSubscriptionList": "Showing the subscription list.", "shredder": "Shredder", @@ -689,6 +699,7 @@ "theIdOfTheItem": "The id of the item.", "theNameOfTheItem": "The name of the item.", "theNameOfThePlayer": "The name of the player.", + "theNameOfTheVendingMachine": "The name of the vending machine.", "three": "Three", "tilde": "Tilde", "time": "Time", diff --git a/src/structures/MapMarkers.js b/src/structures/MapMarkers.js index 9726689e..0e7a2c4d 100644 --- a/src/structures/MapMarkers.js +++ b/src/structures/MapMarkers.js @@ -242,7 +242,16 @@ class MapMarkers { return remainingMarkersOfType; } - + isVendingMachineBlacklisted(marker) { + if (marker.type !== this.types.VendingMachine) return false; + + const instance = this.client.getInstance(this.rustplus.guildId); + const marketBlacklist = instance.marketBlacklist; + + return marketBlacklist.some(blacklist => + marker.name.toLowerCase().includes(blacklist.toLowerCase()) + ); + } /* Update event map markers */ @@ -300,7 +309,7 @@ class MapMarkers { marker.location = pos; - if (!this.rustplus.isFirstPoll) { + if (!this.rustplus.isFirstPoll && !this.isVendingMachineBlacklisted(marker)) { if (!this.knownVendingMachines.some(e => e.x === marker.x && e.y === marker.y)) { this.rustplus.sendEvent( this.rustplus.notificationSettings.vendingMachineDetectedSetting, diff --git a/src/util/CreateInstanceFile.js b/src/util/CreateInstanceFile.js index 3ad0f1dc..2f7d071a 100644 --- a/src/util/CreateInstanceFile.js +++ b/src/util/CreateInstanceFile.js @@ -62,6 +62,7 @@ module.exports = (client, guild) => { buy: [], sell: [] }, + marketBlacklist: [], teamChatColors: {}, blacklist: { discordIds: [], @@ -174,6 +175,7 @@ module.exports = (client, guild) => { buy: [], sell: [] } + if (!instance.hasOwnProperty('marketBlacklist')) instance.marketBlacklist = []; if (!instance.marketSubscriptionList.hasOwnProperty('all')) instance.marketSubscriptionList['all'] = []; if (!instance.marketSubscriptionList.hasOwnProperty('buy')) instance.marketSubscriptionList['buy'] = []; if (!instance.marketSubscriptionList.hasOwnProperty('sell')) instance.marketSubscriptionList['sell'] = [];