mirror of
https://github.com/AsgardEternal/squad-js-map-vote.git
synced 2025-01-23 20:43:52 -06:00
fix: format choices not showing vote count
This commit is contained in:
parent
b62be4d978
commit
c14cb3b585
36
mapvote.js
36
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user