From d629253261d17b030ee3b5c6a4edfd5bd64b603e Mon Sep 17 00:00:00 2001 From: sergelouie6 <49586590+sergelouie6@users.noreply.github.com> Date: Fri, 27 Jan 2023 08:27:32 +0800 Subject: [PATCH 1/4] Include includeMainAssetsInBroadcast Include includeMainAssetsInBroadcast option in the README.MD file --- README.MD | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.MD b/README.MD index 57b7ff6..f352c29 100644 --- a/README.MD +++ b/README.MD @@ -183,6 +183,13 @@ Enables the broadcast at the end of the voting. ```json true ``` +#### includeMainAssetsInBroadcast +###### Description +Shows/Hides Helis and Tanks in the broadcast if they are included in the voting layer. +###### Default +```json +true +``` #### allowedSameMapEntries ###### Description Allowed max NUMBER of times a map could appear in the vote list. @@ -265,6 +272,7 @@ Array of timeframes that allows to override options based on local time. See exa "voteBroadcastMessage": "✯ MAPVOTE ✯\nVote for the next map by writing in chat the corresponding number!", "voteWinnerBroadcastMessage": "✯ MAPVOTE ✯\nThe winning layer is\n\n", "showWinnerBroadcastMessage": true, + "includeMainAssetsInBroadcast" true, "allowedSameMapEntries": 1, "logToDiscord": true, "channelID": "112233445566778899", From b62be4d978b24276b77ff52bab630c99d46f7473 Mon Sep 17 00:00:00 2001 From: Davide Fantino <80767709+fantinodavide@users.noreply.github.com> Date: Mon, 30 Jan 2023 18:34:11 +0100 Subject: [PATCH 2/4] fix: vote end warns --- mapvote.js | 102 +++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/mapvote.js b/mapvote.js index ca3184e..3ad6a33 100644 --- a/mapvote.js +++ b/mapvote.js @@ -372,7 +372,7 @@ export default class MapVote extends DiscordBasePlugin { await this.warn(steamID, "There is no vote running right now"); return; } - this.directMsgNominations(steamID); + await this.directMsgNominations(steamID); return; case "start": //starts the vote again if it was canceled if (!isAdmin) return; @@ -405,8 +405,7 @@ export default class MapVote extends DiscordBasePlugin { await this.warn(steamID, "There is no vote running right now"); return; } - this.endVotingGently(); - await this.warn(steamID, "Ending current vote"); + this.endVotingGently(steamID); return; case "cancelauto": //cancels the current vote and wont set next map to current winnner if (!isAdmin) return; @@ -670,55 +669,64 @@ export default class MapVote extends DiscordBasePlugin { this.broadcastIntervalTask = setInterval(this.broadcastNominations, toMils(this.options.voteBroadcastInterval)); } - async endVotingGently() { + async endVotingGently(steamID = null) { this.endVoting(); + + if (steamID) await this.warn(steamID, "Voting terminated!"); + const winnerLayer = Layers.layers.find((l) => l.layerid == this.updateNextMap()); const fancyWinner = this.formatFancyLayer(winnerLayer); - if (this.showWinnerBroadcastMessage) await this.broadcast(this.options.voteWinnerBroadcastMessage + fancyWinner); - if (!this.options.logToDiscord) return - return await this.sendDiscordMessage({ - embed: { - title: `Vote winner: ${fancyWinner}`, - color: 16761867, - fields: [ - { - name: 'Map', - value: winnerLayer.map.name, - inline: true + console.log("winning layer", winnerLayer, fancyWinner) + + if (this.showWinnerBroadcastMessage) this.broadcast(this.options.voteWinnerBroadcastMessage + fancyWinner); + + if (this.options.logToDiscord) { + await this.sendDiscordMessage({ + embed: { + title: `Vote winner: ${fancyWinner}`, + color: 16761867, + fields: [ + { + name: 'Map', + value: winnerLayer.map.name, + inline: true + }, + { + name: 'Gamemode', + value: winnerLayer.gamemode, + inline: true + }, + { + name: 'Version', + value: winnerLayer.version, + inline: true + }, + { + name: 'LayerID', + value: winnerLayer.layerid, + inline: false + }, + { + name: 'Team 1', + value: winnerLayer.teams[ 0 ].faction, + inline: true + }, + { + name: 'Team 2', + value: winnerLayer.teams[ 1 ].faction, + inline: true + }, + ], + image: { + url: `https://squad-data.nyc3.cdn.digitaloceanspaces.com/main/${winnerLayer.layerid}.jpg` }, - { - name: 'Gamemode', - value: winnerLayer.gamemode, - inline: true - }, - { - name: 'Version', - value: winnerLayer.version, - inline: true - }, - { - name: 'LayerID', - value: winnerLayer.layerid, - inline: false - }, - { - name: 'Team 1', - value: winnerLayer.teams[ 0 ].faction, - inline: true - }, - { - name: 'Team 2', - value: winnerLayer.teams[ 1 ].faction, - inline: true - }, - ], - image: { - url: `https://squad-data.nyc3.cdn.digitaloceanspaces.com/main/${winnerLayer.layerid}.jpg` }, - }, - timestamp: (new Date()).toISOString() - }); + timestamp: (new Date()).toISOString() + }); + } + + return true; } endVoting() { @@ -823,7 +831,7 @@ export default class MapVote extends DiscordBasePlugin { // if (tanks > 0) assets.push('Tanks'); // const vehiclesString = ' ' + assets.join('-'); // await this.msgDirect(steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ])); - strMsg += (steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ])) + `H:${helis}-T:${tanks}` + "\n"; + strMsg += (steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ])) + "\n"; } strMsg.trim(); if (steamID) this.warn(steamID, strMsg) From c14cb3b585c07727e56049d30504504f437538ec Mon Sep 17 00:00:00 2001 From: Davide Fantino <80767709+fantinodavide@users.noreply.github.com> Date: Tue, 31 Jan 2023 00:57:56 +0100 Subject: [PATCH 3/4] fix: format choices not showing vote count --- mapvote.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/mapvote.js b/mapvote.js index 3ad6a33..12e87fd 100644 --- a/mapvote.js +++ b/mapvote.js @@ -207,9 +207,10 @@ export default class MapVote extends DiscordBasePlugin { this.setSeedingMode = this.setSeedingMode.bind(this); this.logVoteToDiscord = this.logVoteToDiscord.bind(this); this.timeframeOptionOverrider = this.timeframeOptionOverrider.bind(this); - this.savePersistentData = this.savePersistentData.bind(this) - this.restorePersistentData = this.restorePersistentData.bind(this) - this.endVotingGently = this.endVotingGently.bind(this) + this.savePersistentData = this.savePersistentData.bind(this); + this.restorePersistentData = this.restorePersistentData.bind(this); + this.endVotingGently = this.endVotingGently.bind(this); + this.formatChoice = this.formatChoice.bind(this); this.broadcast = async (msg) => { await this.server.rcon.broadcast(msg); }; this.warn = async (steamid, msg) => { await this.server.rcon.warn(steamid, msg); }; @@ -419,6 +420,7 @@ export default class MapVote extends DiscordBasePlugin { await this.warn(steamID, "Ending current vote"); return; case "broadcast": + if (!isAdmin) return; if (!this.votingEnabled) { await this.warn(steamID, "There is no vote running right now"); return; @@ -587,7 +589,7 @@ export default class MapVote extends DiscordBasePlugin { && (l.gamemode.toLowerCase().startsWith(cls[ 1 ]) || (!cls[ 1 ] && this.options.gamemodeWhitelist.includes(l.gamemode.toUpperCase()))) && (!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))) - && (cls[ 3 ] || !( + && (!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)) )) @@ -671,7 +673,7 @@ export default class MapVote extends DiscordBasePlugin { async endVotingGently(steamID = null) { this.endVoting(); - + if (steamID) await this.warn(steamID, "Voting terminated!"); const winnerLayer = Layers.layers.find((l) => l.layerid == this.updateNextMap()); @@ -754,6 +756,7 @@ export default class MapVote extends DiscordBasePlugin { async broadcastNominations() { if (this.nominations.length > 0 && this.votingEnabled) { await this.broadcast(this.options.voteBroadcastMessage); + let allNominationStrings = [] let nominationStrings = []; for (let choice = 1; choice < this.nominations.length; choice++) { @@ -766,18 +769,22 @@ export default class MapVote extends DiscordBasePlugin { if (helis > 0) assets.push('Helis'); if (tanks > 0) assets.push('Tanks'); const vehiclesString = this.options.includeMainAssetsInBroadcast ? ' ' + assets.join('-') : ''; - nominationStrings.push(formatChoice(choice, vLayer.map.name + ' ' + vLayer.gamemode + ' ' + this.factionStrings[ choice ] + vehiclesString, this.tallies[ choice ], (this.options.hideVotesCount || this.firstBroadcast))); + + const formattedChoide = this.formatChoice(choice, vLayer.map.name + ' ' + vLayer.gamemode + ' ' + this.factionStrings[ choice ] + vehiclesString, this.tallies[ choice ], (this.options.hideVotesCount || this.firstBroadcast)) + nominationStrings.push(formattedChoide); + allNominationStrings.push(formattedChoide); + if (nominationStrings.length == 3) { await this.broadcast(nominationStrings.join("\n")); nominationStrings = []; } } - if (this.nominations[ 0 ]) nominationStrings.push(formatChoice(0, this.nominations[ 0 ], this.tallies[ 0 ], (this.options.hideVotesCount || this.firstBroadcast))) + if (this.nominations[ 0 ]) nominationStrings.push(this.formatChoice(0, this.nominations[ 0 ], this.tallies[ 0 ], (this.options.hideVotesCount || this.firstBroadcast))) await this.broadcast(nominationStrings.join("\n")); if (this.firstBroadcast) - await this.logVoteToDiscord(nominationStrings.join("\n")) + await this.logVoteToDiscord(allNominationStrings.join("\n")) this.firstBroadcast = false; } //const winners = this.currentWinners; @@ -831,7 +838,7 @@ export default class MapVote extends DiscordBasePlugin { // if (tanks > 0) assets.push('Tanks'); // const vehiclesString = ' ' + assets.join('-'); // await this.msgDirect(steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ])); - strMsg += (steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ])) + "\n"; + strMsg += (steamID, this.formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ])) + "\n"; } strMsg.trim(); if (steamID) this.warn(steamID, strMsg) @@ -991,17 +998,18 @@ export default class MapVote extends DiscordBasePlugin { this.verbose(1, 'Layer list updated'); } + + + formatChoice(choiceIndex, mapString, currentVotes, hideVoteCount) { + return `${choiceIndex}➤ ${mapString} ` + (!hideVoteCount ? `(${currentVotes})` : ""); + // return `${choiceIndex + 1}❱ ${mapString} (${currentVotes} votes)` + } } function randomElement(array) { return array[ Math.floor(Math.random() * array.length) ]; } -function formatChoice(choiceIndex, mapString, currentVotes, firstBroadcast) { - return `${choiceIndex}➤ ${mapString} ` + (!firstBroadcast ? `(${currentVotes})` : ""); - // return `${choiceIndex + 1}❱ ${mapString} (${currentVotes} votes)` -} - function toMils(min) { return min * 60 * 1000; } From 269588c6f7439fc673a9cfdd24efdbd188259d48 Mon Sep 17 00:00:00 2001 From: Davide Fantino <80767709+fantinodavide@users.noreply.github.com> Date: Tue, 7 Feb 2023 01:07:20 +0100 Subject: [PATCH 4/4] fix: blacklist with custom votes --- mapvote.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mapvote.js b/mapvote.js index 12e87fd..32d126b 100644 --- a/mapvote.js +++ b/mapvote.js @@ -588,8 +588,8 @@ export default class MapVote extends DiscordBasePlugin { (cls[ 0 ] == "*" || l.layerid.toLowerCase().startsWith(cls[ 0 ])) && (l.gamemode.toLowerCase().startsWith(cls[ 1 ]) || (!cls[ 1 ] && this.options.gamemodeWhitelist.includes(l.gamemode.toUpperCase()))) && (!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))) - && (!cls[ 3 ] || !( + // && !(this.options.factionsBlacklist.find((f) => [ getTranslation(l.teams[ 0 ]), getTranslation(l.teams[ 1 ]) ].includes(f))) + && (cls[ 2 ] || !( 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)) ))