mirror of
https://github.com/AsgardEternal/squad-js-map-vote.git
synced 2025-01-24 00:13:52 -06:00
fix: format choices not showing vote count
This commit is contained in:
parent
b62be4d978
commit
c14cb3b585
34
mapvote.js
34
mapvote.js
@ -207,9 +207,10 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
this.setSeedingMode = this.setSeedingMode.bind(this);
|
this.setSeedingMode = this.setSeedingMode.bind(this);
|
||||||
this.logVoteToDiscord = this.logVoteToDiscord.bind(this);
|
this.logVoteToDiscord = this.logVoteToDiscord.bind(this);
|
||||||
this.timeframeOptionOverrider = this.timeframeOptionOverrider.bind(this);
|
this.timeframeOptionOverrider = this.timeframeOptionOverrider.bind(this);
|
||||||
this.savePersistentData = this.savePersistentData.bind(this)
|
this.savePersistentData = this.savePersistentData.bind(this);
|
||||||
this.restorePersistentData = this.restorePersistentData.bind(this)
|
this.restorePersistentData = this.restorePersistentData.bind(this);
|
||||||
this.endVotingGently = this.endVotingGently.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.broadcast = async (msg) => { await this.server.rcon.broadcast(msg); };
|
||||||
this.warn = async (steamid, msg) => { await this.server.rcon.warn(steamid, 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");
|
await this.warn(steamID, "Ending current vote");
|
||||||
return;
|
return;
|
||||||
case "broadcast":
|
case "broadcast":
|
||||||
|
if (!isAdmin) return;
|
||||||
if (!this.votingEnabled) {
|
if (!this.votingEnabled) {
|
||||||
await this.warn(steamID, "There is no vote running right now");
|
await this.warn(steamID, "There is no vote running right now");
|
||||||
return;
|
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())))
|
&& (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, '')))
|
&& (!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 ] || !(
|
&& (!cls[ 3 ] || !(
|
||||||
this.options.layerLevelBlacklist.find((fl) => this.getLayersFromStringId(fl).map((e) => e.layerid).includes(l.layerid))
|
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))
|
|| this.options.factionsBlacklist.find((f) => [ getTranslation(l.teams[ 0 ]), getTranslation(l.teams[ 1 ]) ].includes(f))
|
||||||
))
|
))
|
||||||
@ -754,6 +756,7 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
async broadcastNominations() {
|
async broadcastNominations() {
|
||||||
if (this.nominations.length > 0 && this.votingEnabled) {
|
if (this.nominations.length > 0 && this.votingEnabled) {
|
||||||
await this.broadcast(this.options.voteBroadcastMessage);
|
await this.broadcast(this.options.voteBroadcastMessage);
|
||||||
|
let allNominationStrings = []
|
||||||
let nominationStrings = [];
|
let nominationStrings = [];
|
||||||
|
|
||||||
for (let choice = 1; choice < this.nominations.length; choice++) {
|
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 (helis > 0) assets.push('Helis');
|
||||||
if (tanks > 0) assets.push('Tanks');
|
if (tanks > 0) assets.push('Tanks');
|
||||||
const vehiclesString = this.options.includeMainAssetsInBroadcast ? ' ' + assets.join('-') : '';
|
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) {
|
if (nominationStrings.length == 3) {
|
||||||
await this.broadcast(nominationStrings.join("\n"));
|
await this.broadcast(nominationStrings.join("\n"));
|
||||||
nominationStrings = [];
|
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"));
|
await this.broadcast(nominationStrings.join("\n"));
|
||||||
|
|
||||||
if (this.firstBroadcast)
|
if (this.firstBroadcast)
|
||||||
await this.logVoteToDiscord(nominationStrings.join("\n"))
|
await this.logVoteToDiscord(allNominationStrings.join("\n"))
|
||||||
this.firstBroadcast = false;
|
this.firstBroadcast = false;
|
||||||
}
|
}
|
||||||
//const winners = this.currentWinners;
|
//const winners = this.currentWinners;
|
||||||
@ -831,7 +838,7 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
// if (tanks > 0) assets.push('Tanks');
|
// if (tanks > 0) assets.push('Tanks');
|
||||||
// const vehiclesString = ' ' + assets.join('-');
|
// const vehiclesString = ' ' + assets.join('-');
|
||||||
// await this.msgDirect(steamID, formatChoice(choice, this.nominations[ choice ], this.tallies[ choice ]));
|
// 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();
|
strMsg.trim();
|
||||||
if (steamID) this.warn(steamID, strMsg)
|
if (steamID) this.warn(steamID, strMsg)
|
||||||
@ -991,17 +998,18 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
|
|
||||||
this.verbose(1, 'Layer list updated');
|
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) {
|
function randomElement(array) {
|
||||||
return array[ Math.floor(Math.random() * array.length) ];
|
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) {
|
function toMils(min) {
|
||||||
return min * 60 * 1000;
|
return min * 60 * 1000;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user