mirror of
https://github.com/AsgardEternal/squad-js-map-vote.git
synced 2025-01-23 20:43:52 -06:00
commit
1a39f7370c
@ -183,6 +183,13 @@ Enables the broadcast at the end of the voting.
|
|||||||
```json
|
```json
|
||||||
true
|
true
|
||||||
```
|
```
|
||||||
|
#### includeMainAssetsInBroadcast
|
||||||
|
###### Description
|
||||||
|
Shows/Hides Helis and Tanks in the broadcast if they are included in the voting layer.
|
||||||
|
###### Default
|
||||||
|
```json
|
||||||
|
true
|
||||||
|
```
|
||||||
#### allowedSameMapEntries
|
#### allowedSameMapEntries
|
||||||
###### Description
|
###### Description
|
||||||
Allowed max NUMBER of times a map could appear in the vote list.
|
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!",
|
"voteBroadcastMessage": "✯ MAPVOTE ✯\nVote for the next map by writing in chat the corresponding number!",
|
||||||
"voteWinnerBroadcastMessage": "✯ MAPVOTE ✯\nThe winning layer is\n\n",
|
"voteWinnerBroadcastMessage": "✯ MAPVOTE ✯\nThe winning layer is\n\n",
|
||||||
"showWinnerBroadcastMessage": true,
|
"showWinnerBroadcastMessage": true,
|
||||||
|
"includeMainAssetsInBroadcast" true,
|
||||||
"allowedSameMapEntries": 1,
|
"allowedSameMapEntries": 1,
|
||||||
"logToDiscord": true,
|
"logToDiscord": true,
|
||||||
"channelID": "112233445566778899",
|
"channelID": "112233445566778899",
|
||||||
|
136
mapvote.js
136
mapvote.js
@ -212,9 +212,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); };
|
||||||
@ -376,7 +377,7 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
await this.warn(steamID, "There is no vote running right now");
|
await this.warn(steamID, "There is no vote running right now");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.directMsgNominations(steamID);
|
await this.directMsgNominations(steamID);
|
||||||
return;
|
return;
|
||||||
case "start": //starts the vote again if it was canceled
|
case "start": //starts the vote again if it was canceled
|
||||||
if (!isAdmin) return;
|
if (!isAdmin) return;
|
||||||
@ -409,8 +410,7 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
await this.warn(steamID, "There is no vote running right now");
|
await this.warn(steamID, "There is no vote running right now");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.endVotingGently();
|
this.endVotingGently(steamID);
|
||||||
await this.warn(steamID, "Ending current vote");
|
|
||||||
return;
|
return;
|
||||||
case "cancelauto": //cancels the current vote and wont set next map to current winnner
|
case "cancelauto": //cancels the current vote and wont set next map to current winnner
|
||||||
if (!isAdmin) return;
|
if (!isAdmin) return;
|
||||||
@ -424,6 +424,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;
|
||||||
@ -591,8 +592,8 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
(cls[ 0 ] == "*" || l.layerid.toLowerCase().startsWith(cls[ 0 ]))
|
(cls[ 0 ] == "*" || l.layerid.toLowerCase().startsWith(cls[ 0 ]))
|
||||||
&& (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[ 2 ] || !(
|
||||||
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))
|
||||||
))
|
))
|
||||||
@ -674,55 +675,64 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
this.broadcastIntervalTask = setInterval(this.broadcastNominations, toMils(this.options.voteBroadcastInterval));
|
this.broadcastIntervalTask = setInterval(this.broadcastNominations, toMils(this.options.voteBroadcastInterval));
|
||||||
}
|
}
|
||||||
|
|
||||||
async endVotingGently() {
|
async endVotingGently(steamID = null) {
|
||||||
this.endVoting();
|
this.endVoting();
|
||||||
|
|
||||||
|
if (steamID) await this.warn(steamID, "Voting terminated!");
|
||||||
|
|
||||||
const winnerLayer = Layers.layers.find((l) => l.layerid == this.updateNextMap());
|
const winnerLayer = Layers.layers.find((l) => l.layerid == this.updateNextMap());
|
||||||
const fancyWinner = this.formatFancyLayer(winnerLayer);
|
const fancyWinner = this.formatFancyLayer(winnerLayer);
|
||||||
if (this.showWinnerBroadcastMessage) await this.broadcast(this.options.voteWinnerBroadcastMessage + fancyWinner);
|
|
||||||
|
|
||||||
if (!this.options.logToDiscord) return
|
console.log("winning layer", winnerLayer, fancyWinner)
|
||||||
return await this.sendDiscordMessage({
|
|
||||||
embed: {
|
if (this.showWinnerBroadcastMessage) this.broadcast(this.options.voteWinnerBroadcastMessage + fancyWinner);
|
||||||
title: `Vote winner: ${fancyWinner}`,
|
|
||||||
color: 16761867,
|
if (this.options.logToDiscord) {
|
||||||
fields: [
|
await this.sendDiscordMessage({
|
||||||
{
|
embed: {
|
||||||
name: 'Map',
|
title: `Vote winner: ${fancyWinner}`,
|
||||||
value: winnerLayer.map.name,
|
color: 16761867,
|
||||||
inline: true
|
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() {
|
endVoting() {
|
||||||
@ -750,6 +760,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++) {
|
||||||
@ -762,18 +773,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;
|
||||||
@ -827,7 +842,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 ])) + `H:${helis}-T:${tanks}` + "\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)
|
||||||
@ -989,17 +1004,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