fix: layer blacklist + factions blacklist in custom votes

This commit is contained in:
Davide Fantino 2023-01-25 22:20:49 +01:00
parent 20526e9f65
commit 5fa1bb2575
2 changed files with 19 additions and 3 deletions

View File

@ -231,6 +231,7 @@ Array of timeframes that allows to override options based on local time. See exa
"plugin": "MapVote", "plugin": "MapVote",
"enabled": true, "enabled": true,
"discordClient": "discord", "discordClient": "discord",
"entriesAmount": 6,
"automaticVoteStart": true, "automaticVoteStart": true,
"votingDuration": 0, "votingDuration": 0,
"minPlayersForVote": 30, "minPlayersForVote": 30,

View File

@ -26,6 +26,11 @@ export default class MapVote extends DiscordBasePlugin {
description: "command name to use in chat", description: "command name to use in chat",
default: "!vote" default: "!vote"
}, },
entriesAmount: {
required: false,
description: "Amount of entries generated for automatic votes",
default: 6
},
automaticVoteStart: { automaticVoteStart: {
required: false, required: false,
description: "a map vote will automatically start after a new match if set to true", description: "a map vote will automatically start after a new match if set to true",
@ -527,7 +532,7 @@ export default class MapVote extends DiscordBasePlugin {
let rnd_layers = []; let rnd_layers = [];
const sanitizedLayers = Layers.layers.filter((l) => l.layerid && l.map); const sanitizedLayers = Layers.layers.filter((l) => l.layerid && l.map);
const maxOptions = this.options.showRerollOption ? 5 : 6; const maxOptions = this.options.showRerollOption ? 20 : 21;
const recentlyPlayedMaps = this.objArrToValArr(this.server.layerHistory.slice(0, this.options.numberRecentMapsToExlude), "layer", "map", "name"); const recentlyPlayedMaps = this.objArrToValArr(this.server.layerHistory.slice(0, this.options.numberRecentMapsToExlude), "layer", "map", "name");
this.verbose(1, "Recently played maps: " + recentlyPlayedMaps.join(', '));//recentlyPlayedMaps.filter((l) => l && l.map && l.map.name).map((l) => l.map.name).join(', ')) this.verbose(1, "Recently played maps: " + recentlyPlayedMaps.join(', '));//recentlyPlayedMaps.filter((l) => l && l.map && l.map.name).map((l) => l.map.name).join(', '))
@ -576,6 +581,10 @@ export default class MapVote extends DiscordBasePlugin {
&& (l.gamemode.toLowerCase().startsWith(cls[ 1 ]) || (!cls[ 1 ] && [ 'RAAS', 'AAS', 'INVASION' ].includes(l.gamemode.toUpperCase()))) && (l.gamemode.toLowerCase().startsWith(cls[ 1 ]) || (!cls[ 1 ] && [ 'RAAS', 'AAS', 'INVASION' ].includes(l.gamemode.toUpperCase())))
&& (!cls[ 2 ] || l.version.toLowerCase().startsWith("v" + cls[ 2 ].replace(/v/gi, ''))) && (!cls[ 2 ] || l.version.toLowerCase().startsWith("v" + cls[ 2 ].replace(/v/gi, '')))
&& !(this.options.factionsBlacklist.find((f) => [ getTranslation(l.teams[ 0 ]), getTranslation(l.teams[ 1 ]) ].includes(f))) && !(this.options.factionsBlacklist.find((f) => [ getTranslation(l.teams[ 0 ]), getTranslation(l.teams[ 1 ]) ].includes(f)))
&& (cls[ 3 ] || !(
this.options.layerLevelBlacklist.find((fl) => this.getLayersFromStringId(fl).map((e) => e.layerid).includes(l.layerid))
|| this.options.factionsBlacklist.find((f) => [ getTranslation(l.teams[ 0 ]), getTranslation(l.teams[ 1 ]) ].includes(f))
))
)); ));
let l, maxtries = 10; let l, maxtries = 10;
do l = randomElement(fLayers); while ((rnd_layers.filter(lf => lf.map.name == l.map.name).length > (this.options.allowedSameMapEntries - 1)) && --maxtries >= 0) do l = randomElement(fLayers); while ((rnd_layers.filter(lf => lf.map.name == l.map.name).length > (this.options.allowedSameMapEntries - 1)) && --maxtries >= 0)
@ -882,8 +891,14 @@ export default class MapVote extends DiscordBasePlugin {
this.verbose(1, "Error restoring persistent data", e) this.verbose(1, "Error restoring persistent data", e)
return return
} }
if (bkData.manualRestartSender && bkData.manualRestartSender != "") this.warn(bkData.manualRestartSender,`SquadJS has completed the restart.\nPersistent data restored.`) if (bkData.manualRestartSender && bkData.manualRestartSender != "") {
for (let k in bkData.server) this.server[ k ] = bkData.server[ k ]; (async () => {
await this.warn(bkData.manualRestartSender, `SquadJS has completed the restart.\nPersistent data restored.`)
this.verbose(1, `Restart confirmation sent to SteamID: "${bkData.manualRestartSender}"`)
})()
}
for (let k in bkData.server) this.server[ k ] = bkData.server[ k ];
const maxSecondsDiffierence = 60 const maxSecondsDiffierence = 60
if ((new Date() - new Date(bkData.saveDateTime)) / 1000 > maxSecondsDiffierence) return if ((new Date() - new Date(bkData.saveDateTime)) / 1000 > maxSecondsDiffierence) return