mirror of
https://github.com/AsgardEternal/squad-js-map-vote.git
synced 2025-01-23 20:43:52 -06:00
added end command
This commit is contained in:
parent
3445b92e03
commit
7422a4f06d
@ -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 start` - Starts a vote with 6 layers, random modes
|
||||||
- `!vote cancel` - Cancels current round of voting
|
- `!vote cancel` - Cancels current round of voting
|
||||||
- `!vote cancelauto` - Cancel scheduled automatic start of vote
|
- `!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 restart` - Restarts voting with 6 random maps and modes
|
||||||
- `!vote broadcast` - Broadcasts current voting results - happens every 7m automatically
|
- `!vote broadcast` - Broadcasts current voting results - happens every 7m automatically
|
||||||
|
|
||||||
|
28
mapvote.js
28
mapvote.js
@ -166,6 +166,7 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
this.or_options = { ...this.options };
|
this.or_options = { ...this.options };
|
||||||
this.autovotestart = null;
|
this.autovotestart = null;
|
||||||
this.lastMapUpdate = new Date();
|
this.lastMapUpdate = new Date();
|
||||||
|
this.timeout_ps = []
|
||||||
|
|
||||||
this.onNewGame = this.onNewGame.bind(this);
|
this.onNewGame = this.onNewGame.bind(this);
|
||||||
this.onPlayerDisconnected = this.onPlayerDisconnected.bind(this);
|
this.onPlayerDisconnected = this.onPlayerDisconnected.bind(this);
|
||||||
@ -204,6 +205,7 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onNewGame() {
|
async onNewGame() {
|
||||||
|
for (let x of this.timeout_ps) clearTimeout(this.timeout_ps.pop())
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
this.endVoting();
|
this.endVoting();
|
||||||
this.trackedVotes = {};
|
this.trackedVotes = {};
|
||||||
@ -356,6 +358,16 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
this.endVoting();
|
this.endVoting();
|
||||||
await this.warn(steamID, "Ending current vote");
|
await this.warn(steamID, "Ending current vote");
|
||||||
return;
|
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
|
case "cancelauto": //cancels the current vote and wont set next map to current winnner
|
||||||
if (!isAdmin) return;
|
if (!isAdmin) return;
|
||||||
|
|
||||||
@ -485,11 +497,11 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
this.options.gamemodeWhitelist.includes(l.gamemode.toUpperCase()) &&
|
this.options.gamemodeWhitelist.includes(l.gamemode.toUpperCase()) &&
|
||||||
![ this.server.currentLayer ? this.server.currentLayer.map.name : null, ...recentlyPlayedMaps ].includes(l.map.name) &&
|
![ 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.layerFilteringMode.toLowerCase() == "whitelist"
|
||||||
&& this.options.layerLevelWhitelist.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)))
|
&& !(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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.votingDuration > 0) setTimeout(() => {
|
if (this.options.votingDuration > 0) this.timeout_ps.push(setTimeout(this.endVotingGently, this.options.votingDuration * 60 * 1000))
|
||||||
this.endVoting();
|
|
||||||
this.broadcast(this.options.voteWinnerBroadcastMessage + this.formatFancyLayer(Layers.layers.find((l) => l.layerid == this.updateNextMap())));
|
|
||||||
}, this.options.votingDuration * 60 * 1000)
|
|
||||||
|
|
||||||
// these need to be reset after reenabling voting
|
// these need to be reset after reenabling voting
|
||||||
this.trackedVotes = {};
|
this.trackedVotes = {};
|
||||||
@ -598,6 +607,11 @@ export default class MapVote extends DiscordBasePlugin {
|
|||||||
this.broadcastIntervalTask = setInterval(this.broadcastNominations, toMils(this.options.voteBroadcastInterval));
|
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() {
|
endVoting() {
|
||||||
this.votingEnabled = false;
|
this.votingEnabled = false;
|
||||||
clearInterval(this.broadcastIntervalTask);
|
clearInterval(this.broadcastIntervalTask);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user