feat: personalizable list entry format

This commit is contained in:
Davide Fantino 2023-02-28 23:54:37 +01:00
parent de3d3aa497
commit c1d5ba2bb0
2 changed files with 31 additions and 26 deletions

View File

@ -36,6 +36,13 @@ The command name to use in chat.
``` ```
!vote !vote
``` ```
#### entryFormat
###### Description
The format of an entry in the voting list.
###### Default
```json
"{map_name} {gamemode} {map_version} {factions} ({main_assets})"
```
#### entriesAmount #### entriesAmount
###### Description ###### Description
Amount of entries generated for automatic votes. Amount of entries generated for automatic votes.
@ -183,13 +190,6 @@ 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.
@ -262,6 +262,7 @@ Can be used to prevent situation when insignificant number of players decide wha
"enabled": true, "enabled": true,
"discordClient": "discord", "discordClient": "discord",
"entriesAmount": 6, "entriesAmount": 6,
"entryFormat": "{map_name} {gamemode} {map_version} {factions} ({main_assets})",
"automaticVoteStart": true, "automaticVoteStart": true,
"votingDuration": 0, "votingDuration": 0,
"minPlayersForVote": 30, "minPlayersForVote": 30,
@ -281,7 +282,6 @@ Can be used to prevent situation when insignificant number of players decide wha
"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",

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"
}, },
entryFormat: {
required: false,
description: "The format of an entry in the voting list",
default: '{map_name} {gamemode} {map_version} {factions} ({main_assets})'
},
entriesAmount: { entriesAmount: {
required: false, required: false,
description: "Amount of entries generated for automatic votes", description: "Amount of entries generated for automatic votes",
@ -161,20 +166,15 @@ export default class MapVote extends DiscordBasePlugin {
description: "Timezone relative to UTC time. 0 for UTC, 2 for CEST (UTC+2), -1 (UTC-1) ", description: "Timezone relative to UTC time. 0 for UTC, 2 for CEST (UTC+2), -1 (UTC-1) ",
default: 0 default: 0
}, },
includeMainAssetsInBroadcast: { minimumVotesToAcceptResult: {
required: false, required: false,
description: "Shows/Hides Helis and Tanks in the broadcast if they are included in the voting layer", description: "Minimum votes per map to accept result.",
default: true default: 1
}, },
timeFrames: { timeFrames: {
required: false, required: false,
description: 'Array of timeframes to override options', description: 'Array of timeframes to override options',
default: [] default: []
},
minimumVotesToAcceptResult: {
required: false,
description: "Minimum votes per map to accept result.",
default: 1
} }
}; };
} }
@ -327,7 +327,7 @@ export default class MapVote extends DiscordBasePlugin {
} }
} else this.verbose(1, "Bad data (currentLayer). Seeding mode for current layer skipped to prevent errors."); } else this.verbose(1, "Bad data (currentLayer). Seeding mode for current layer skipped to prevent errors.");
if (+this.layerHistory[ 0 ].time - +(new Date()) > 30 * 1000) { if (+(new Date()) - +this.layerHistory[ 0 ].time > 30 * 1000) {
if (this.server.nextLayer) { if (this.server.nextLayer) {
const nextMaps = seedingMaps.filter((l) => (!this.server.currentLayer || l.layerid != this.server.currentLayer.layerid)) const nextMaps = seedingMaps.filter((l) => (!this.server.currentLayer || l.layerid != this.server.currentLayer.layerid))
let rndMap2; let rndMap2;
@ -771,15 +771,8 @@ export default class MapVote extends DiscordBasePlugin {
for (let choice = 1; choice < this.nominations.length; choice++) { for (let choice = 1; choice < this.nominations.length; choice++) {
choice = Number(choice); choice = Number(choice);
let vLayer = Layers.layers.find(e => e.layerid == this.nominations[ choice ]); let vLayer = Layers.layers.find(e => e.layerid == this.nominations[ choice ]);
// const allVecs = vLayer.teams[0].vehicles.concat(vLayer.teams[1].vehicles);
const helis = vLayer.teams[ 0 ].numberOfHelicopters + vLayer.teams[ 1 ].numberOfHelicopters
const tanks = vLayer.teams[ 0 ].numberOfTanks + vLayer.teams[ 1 ].numberOfTanks
let assets = [];
if (helis > 0) assets.push('Helis');
if (tanks > 0) assets.push('Tanks');
const vehiclesString = this.options.includeMainAssetsInBroadcast ? ' ' + assets.join('-') : '';
const formattedChoide = this.formatChoice(choice, vLayer.map.name + ' ' + vLayer.gamemode + ' ' + this.factionStrings[ choice ] + vehiclesString, this.tallies[ choice ], (this.options.hideVotesCount || this.firstBroadcast)) const formattedChoide = this.formatChoice(choice, this.formatFancyLayer(vLayer), this.tallies[ choice ], (this.options.hideVotesCount || this.firstBroadcast))
nominationStrings.push(formattedChoide); nominationStrings.push(formattedChoide);
allNominationStrings.push(formattedChoide); allNominationStrings.push(formattedChoide);
@ -813,7 +806,19 @@ export default class MapVote extends DiscordBasePlugin {
} }
const factionString = getTranslation(layer.teams[ 0 ]) + "-" + getTranslation(layer.teams[ 1 ]); const factionString = getTranslation(layer.teams[ 0 ]) + "-" + getTranslation(layer.teams[ 1 ]);
return layer.map.name + ' ' + layer.gamemode + ' ' + factionString const helis = layer.teams[ 0 ].numberOfHelicopters + layer.teams[ 1 ].numberOfHelicopters
const tanks = layer.teams[ 0 ].numberOfTanks + layer.teams[ 1 ].numberOfTanks
let assets = [];
if (helis > 0) assets.push('Helis');
if (tanks > 0) assets.push('Tanks');
const vehiclesString = assets.join('-');
return this.options.entryFormat
.replace(/\{map_name\}/i, layer.map.name)
.replace(/\{gamemode\}/i, layer.gamemode)
.replace(/\{map_version\}/i, layer.version)
.replace(/\{factions\}/i, factionString)
.replace(/\{main_assets\}/i, vehiclesString)
function getTranslation(t) { function getTranslation(t) {
if (translations[ t.faction ]) return translations[ t.faction ] if (translations[ t.faction ]) return translations[ t.faction ]