timeframe untested implementation (no override)

This commit is contained in:
Davide Fantino 2022-09-18 00:38:06 +02:00
parent 753825fabe
commit 64648657f1
2 changed files with 45 additions and 3 deletions

View File

@ -124,6 +124,7 @@ The ID of the channel to log votes to..
"plugin": "MapVote", "plugin": "MapVote",
"enabled": true, "enabled": true,
"discordClient": "discord", "discordClient": "discord",
"automaticVoteStart": true,
"minPlayersForVote": 30, "minPlayersForVote": 30,
"voteWaitTimeFromMatchStart": 10, "voteWaitTimeFromMatchStart": 10,
"voteBroadcastInterval": 7, "voteBroadcastInterval": 7,
@ -135,6 +136,22 @@ The ID of the channel to log votes to..
"showRerollOption": false, "showRerollOption": false,
"voteBroadcastMessage": "✯ MAPVOTE ✯ Vote for the next map by writing in chat the corresponding number!", "voteBroadcastMessage": "✯ MAPVOTE ✯ Vote for the next map by writing in chat the corresponding number!",
"logToDiscord": true, "logToDiscord": true,
"channelID": "112233445566778899" "channelID": "112233445566778899",
"timeframes": [
{
"start": "12:00",
"end": "18:00",
"overrides": {
"automaticVoteStart": false
} }
},
{
"start": "22:00",
"end": "02:00",
"overrides": {
"voteBroadcastMessage": "Late night games? Vote your favourite map!"
}
}
]
}z
``` ```

View File

@ -6,6 +6,7 @@ import DiscordBasePlugin from './discord-base-plugin.js';
import fs from "fs"; import fs from "fs";
import { Layers } from "../layers/index.js" import { Layers } from "../layers/index.js"
import axios from "axios" import axios from "axios"
import { time } from 'console';
export default class MapVote extends DiscordBasePlugin { export default class MapVote extends DiscordBasePlugin {
static get description() { static get description() {
@ -94,6 +95,11 @@ export default class MapVote extends DiscordBasePlugin {
description: 'The ID of the channel to log votes to.', description: 'The ID of the channel to log votes to.',
default: '', default: '',
example: '112233445566778899' example: '112233445566778899'
},
timeFrames: {
required: false,
description: 'Array of timeframes to override options',
default: []
} }
}; };
} }
@ -115,6 +121,7 @@ export default class MapVote extends DiscordBasePlugin {
cmdLayers: [], cmdLayers: [],
bypassRaasFilter: false bypassRaasFilter: false
}; };
this.or_options = { ...this.options };
this.onNewGame = this.onNewGame.bind(this); this.onNewGame = this.onNewGame.bind(this);
this.onPlayerDisconnected = this.onPlayerDisconnected.bind(this); this.onPlayerDisconnected = this.onPlayerDisconnected.bind(this);
@ -123,6 +130,7 @@ export default class MapVote extends DiscordBasePlugin {
this.beginVoting = this.beginVoting.bind(this); this.beginVoting = this.beginVoting.bind(this);
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.broadcast = (msg) => { this.server.rcon.broadcast(msg); }; this.broadcast = (msg) => { this.server.rcon.broadcast(msg); };
this.warn = (steamid, msg) => { this.server.rcon.warn(steamid, msg); }; this.warn = (steamid, msg) => { this.server.rcon.warn(steamid, msg); };
@ -137,7 +145,8 @@ export default class MapVote extends DiscordBasePlugin {
this.verbose(1, 'Map vote was mounted.'); this.verbose(1, 'Map vote was mounted.');
this.verbose(1, "Blacklisted Layers/Levels: " + this.options.layerLevelBlacklist.join(', ')) this.verbose(1, "Blacklisted Layers/Levels: " + this.options.layerLevelBlacklist.join(', '))
// await this.checkUpdates(); // await this.checkUpdates();
// console.log("mapvote removeEventListener", this.server) this.timeframeOptionOverrider();
setInterval(this.timeframeOptionOverrider, 5 * 60 * 1000)
} }
async unmount() { async unmount() {
@ -166,6 +175,22 @@ export default class MapVote extends DiscordBasePlugin {
this.clearVote(); this.clearVote();
this.updateNextMap(); this.updateNextMap();
} }
async timeframeOptionOverrider() {
const timeNow = new Date(0, 0, 0, new Date().getHours(), new Date().getMinutes());
const activeTimeframes = this.or_options.timeframes.filter((tf) => tf.start);
console.log(activeTimeframes)
function tfFilter(tf) {
const tfStartSplit = tf.start.split(':').forEach((e, k, a) => a[ k ] = parseInt(e))
const tfEndSplit = tf.end.split(':').forEach((e, k, a) => a[ k ] = parseInt(e))
const tfStart = new Date(0, 0, 0, ...tfStartSplit)
const tfStart2 = new Date(0, 0, 0, 0, 0)
const tfEnd = new Date(0, 0, 0, ...tfEndSplit)
return (tfStart <= timeNow && timeNow < tfEnd) || (tfStart > tfEnd && tfStart2 <= timeNow && timeNow < tfEnd)
}
}
async checkUpdates(callback) { async checkUpdates(callback) {
const versionN = "1.0.0" const versionN = "1.0.0"
let releasesUrl = "https://api.github.com/repos/fantinodavide/squad-js-map-vote/releases"; let releasesUrl = "https://api.github.com/repos/fantinodavide/squad-js-map-vote/releases";