utcTime option to timezone option

This commit is contained in:
Davide Fantino 2022-09-20 21:29:46 +02:00
parent 1bcb5e5bdf
commit 66c5245e37
2 changed files with 12 additions and 7 deletions

View File

@ -131,7 +131,7 @@ Array of timeframes that allows to override options based on local time. See exa
name: "friendly name", // a friendly name visible in the logs name: "friendly name", // a friendly name visible in the logs
start: "12:00", // timeframe start time <hour>:<minutes> start: "12:00", // timeframe start time <hour>:<minutes>
end: "18:00", // timeframe end time <hour>:<minutes> end: "18:00", // timeframe end time <hour>:<minutes>
utcTime: false, // true: use UTC time; false: use LOCAL time timezone: 0, // Timezone relative to UTC time. 0 for UTC, 2 for CEST (UTC+2), -1 (UTC-1)
overrides: { // options to override overrides: { // options to override
automaticVoteStart: false, automaticVoteStart: false,
layerLevelBlacklist: [ "Anvil", "Chora" ] layerLevelBlacklist: [ "Anvil", "Chora" ]
@ -162,7 +162,7 @@ Array of timeframes that allows to override options based on local time. See exa
"name": "follow layer rotation list", "name": "follow layer rotation list",
"start": "12:00", "start": "12:00",
"end": "18:00", "end": "18:00",
"utcTime": true, "timezone": +2,
"overrides": { "overrides": {
"automaticVoteStart": false "automaticVoteStart": false
} }
@ -170,7 +170,7 @@ Array of timeframes that allows to override options based on local time. See exa
{ {
"start": "22:00", "start": "22:00",
"end": "02:00", "end": "02:00",
"utcTime": false, "timezone": -1,
"overrides": { "overrides": {
"voteBroadcastMessage": "Late night games? Vote your favourite map!" "voteBroadcastMessage": "Late night games? Vote your favourite map!"
} }

View File

@ -107,6 +107,8 @@ export default class MapVote extends DiscordBasePlugin {
constructor(server, options, connectors) { constructor(server, options, connectors) {
super(server, options, connectors); super(server, options, connectors);
this.options.timeFrames.forEach((e, key, arr) => { arr[ key ].id = key + 1 });
this.voteRules = {}; //data object holding vote configs this.voteRules = {}; //data object holding vote configs
this.nominations = []; //layer strings for the current vote choices this.nominations = []; //layer strings for the current vote choices
this.trackedVotes = {}; //player votes, keyed by steam id this.trackedVotes = {}; //player votes, keyed by steam id
@ -175,7 +177,9 @@ export default class MapVote extends DiscordBasePlugin {
this.updateNextMap(); this.updateNextMap();
} }
async timeframeOptionOverrider() { async timeframeOptionOverrider() {
const activeTimeframes = this.or_options.timeFrames.filter(tfFilter);
const orOpt = { ...this.or_options };
const activeTimeframes = orOpt.timeFrames.filter(tfFilter);
let logTimeframe = "Active Time Frames: "; let logTimeframe = "Active Time Frames: ";
let activeTfIds = []; let activeTfIds = [];
@ -190,16 +194,17 @@ export default class MapVote extends DiscordBasePlugin {
this.verbose(1, logTimeframe + activeTfIds.join(', ')); this.verbose(1, logTimeframe + activeTfIds.join(', '));
function tfFilter(tf, key, arr) { function tfFilter(tf, key, arr) {
const timeNow = tf.utcTime ? new Date(0, 0, 0, new Date().getUTCHours(), new Date().getUTCMinutes()) : new Date(0, 0, 0, new Date().getHours(), new Date().getMinutes()); const utcDelay = tf.timezone ? parseFloat(tf.timezone) : 0;
const timeNow = new Date(0, 0, 0, new Date().getUTCHours() + utcDelay, new Date().getUTCMinutes());
this.verbose(1, `Current time (UTC+${utcDelay}) ${timeNow.getHours()}:${timeNow.getMinutes()}`)
arr[ key ].id = key + 1;
const tfStartSplit = [ parseInt(tf.start.split(':')[ 0 ]), parseInt(tf.start.split(':')[ 1 ]) ]; const tfStartSplit = [ parseInt(tf.start.split(':')[ 0 ]), parseInt(tf.start.split(':')[ 1 ]) ];
const tfEndSplit = [ parseInt(tf.end.split(':')[ 0 ]), parseInt(tf.end.split(':')[ 1 ]) ]; const tfEndSplit = [ parseInt(tf.end.split(':')[ 0 ]), parseInt(tf.end.split(':')[ 1 ]) ];
const tfStart = new Date(0, 0, 0, ...tfStartSplit) const tfStart = new Date(0, 0, 0, ...tfStartSplit)
const tfStart2 = new Date(0, 0, 0, 0, 0) const tfStart2 = new Date(0, 0, 0, 0, 0)
const tfEnd = new Date(0, 0, 0, ...tfEndSplit) const tfEnd = new Date(0, 0, 0, ...tfEndSplit)
return (tfStart <= timeNow && timeNow < tfEnd) || (tfStart > tfEnd && tfStart2 <= timeNow && timeNow < tfEnd) return (tfStart <= timeNow && timeNow < tfEnd) || (tfStart > tfEnd && ((tfStart <= timeNow || tfStart2 <= timeNow) && timeNow < tfEnd))
} }
} }
async checkUpdates(callback) { async checkUpdates(callback) {