added end command

This commit is contained in:
Davide Fantino 2022-10-25 19:51:05 +02:00
parent 3445b92e03
commit 7422a4f06d
2 changed files with 22 additions and 7 deletions

View File

@ -12,6 +12,7 @@ The `MapVote` plugin for squad js based on the original version https://github.c
- `!vote start` - Starts a vote with 6 layers, random modes
- `!vote cancel` - Cancels current round of voting
- `!vote cancelauto` - Cancel scheduled automatic start of vote
- `!vote end` - Gently ends the current vote and announces the winner layer
- `!vote restart` - Restarts voting with 6 random maps and modes
- `!vote broadcast` - Broadcasts current voting results - happens every 7m automatically

View File

@ -166,6 +166,7 @@ export default class MapVote extends DiscordBasePlugin {
this.or_options = { ...this.options };
this.autovotestart = null;
this.lastMapUpdate = new Date();
this.timeout_ps = []
this.onNewGame = this.onNewGame.bind(this);
this.onPlayerDisconnected = this.onPlayerDisconnected.bind(this);
@ -204,6 +205,7 @@ export default class MapVote extends DiscordBasePlugin {
}
async onNewGame() {
for (let x of this.timeout_ps) clearTimeout(this.timeout_ps.pop())
setTimeout(async () => {
this.endVoting();
this.trackedVotes = {};
@ -356,6 +358,16 @@ export default class MapVote extends DiscordBasePlugin {
this.endVoting();
await this.warn(steamID, "Ending current vote");
return;
case "end": //gently ends the current vote and announces the winner layer
if (!isAdmin) return;
if (!this.votingEnabled) {
await this.warn(steamID, "There is no vote running right now");
return;
}
this.endVotingGently();
await this.warn(steamID, "Ending current vote");
return;
case "cancelauto": //cancels the current vote and wont set next map to current winnner
if (!isAdmin) return;
@ -485,11 +497,11 @@ export default class MapVote extends DiscordBasePlugin {
this.options.gamemodeWhitelist.includes(l.gamemode.toUpperCase()) &&
![ this.server.currentLayer ? this.server.currentLayer.map.name : null, ...recentlyPlayedMaps ].includes(l.map.name) &&
(
(this.options.layerFilteringMode.toLowerCase() == "blacklist" && !this.options.layerLevelBlacklist.find((fl) => this.getLayersFromStringId(fl).map((e)=>e.layerid).includes(l.layerid))) ||
(this.options.layerFilteringMode.toLowerCase() == "blacklist" && !this.options.layerLevelBlacklist.find((fl) => this.getLayersFromStringId(fl).map((e) => e.layerid).includes(l.layerid))) ||
(
this.options.layerFilteringMode.toLowerCase() == "whitelist"
&& this.options.layerLevelWhitelist.find((fl) => this.getLayersFromStringId(fl).map((e)=>e.layerid).includes(l.layerid))
&& !(this.options.applyBlacklistToWhitelist && this.options.layerLevelBlacklist.find((fl) => this.getLayersFromStringId(fl).map((e)=>e.layerid).includes(l.layerid)))
&& this.options.layerLevelWhitelist.find((fl) => this.getLayersFromStringId(fl).map((e) => e.layerid).includes(l.layerid))
&& !(this.options.applyBlacklistToWhitelist && this.options.layerLevelBlacklist.find((fl) => this.getLayersFromStringId(fl).map((e) => e.layerid).includes(l.layerid)))
)
)
);
@ -581,10 +593,7 @@ export default class MapVote extends DiscordBasePlugin {
return;
}
if (this.options.votingDuration > 0) setTimeout(() => {
this.endVoting();
this.broadcast(this.options.voteWinnerBroadcastMessage + this.formatFancyLayer(Layers.layers.find((l) => l.layerid == this.updateNextMap())));
}, this.options.votingDuration * 60 * 1000)
if (this.options.votingDuration > 0) this.timeout_ps.push(setTimeout(this.endVotingGently, this.options.votingDuration * 60 * 1000))
// these need to be reset after reenabling voting
this.trackedVotes = {};
@ -598,6 +607,11 @@ export default class MapVote extends DiscordBasePlugin {
this.broadcastIntervalTask = setInterval(this.broadcastNominations, toMils(this.options.voteBroadcastInterval));
}
endVotingGently() {
this.endVoting();
this.broadcast(this.options.voteWinnerBroadcastMessage + this.formatFancyLayer(Layers.layers.find((l) => l.layerid == this.updateNextMap())));
}
endVoting() {
this.votingEnabled = false;
clearInterval(this.broadcastIntervalTask);