Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vending Machine Blacklisting #396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 91 additions & 1 deletion src/commands/market.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"abandonedCabins": "Abandoned Cabins",
"abandonedMilitaryBase": "Abandoned Military Base",
"abandonedSupermarket": "Abandoned Supermarket",
"add": "Add",
"addPlayerCap": "ADD PLAYER",
"addSwitchCap": "ADD SWITCH",
"afkCap": "AFK",
Expand All @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand All @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions src/structures/MapMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/util/CreateInstanceFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = (client, guild) => {
buy: [],
sell: []
},
marketBlacklist: [],
teamChatColors: {},
blacklist: {
discordIds: [],
Expand Down Expand Up @@ -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'] = [];
Expand Down
Loading