fixes and optimizations

This commit is contained in:
Davide Fantino 2022-09-20 23:21:05 +02:00
parent 67a1decc63
commit b20d45baeb
2 changed files with 31 additions and 23 deletions

View File

@ -118,6 +118,13 @@ The ID of the channel to log votes to.
```json ```json
"112233445566778899" "112233445566778899"
``` ```
#### timezone
###### Description
Timezone relative to UTC time. 0 for UTC, 2 for CEST (UTC+2), -1 (UTC-1)
###### Default
```json
0
```
#### timeFrames #### timeFrames
###### Description ###### Description
Array of timeframes that allows to override options based on local time. See example configuration Array of timeframes that allows to override options based on local time. See example configuration
@ -131,7 +138,6 @@ 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>
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" ]
@ -157,12 +163,12 @@ Array of timeframes that allows to override options based on local time. See exa
"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",
"timezone": 2,
"timeFrames": [ "timeFrames": [
{ {
"name": "follow layer rotation list", "name": "follow layer rotation list",
"start": "12:00", "start": "12:00",
"end": "18:00", "end": "18:00",
"timezone": 2,
"overrides": { "overrides": {
"automaticVoteStart": false "automaticVoteStart": false
} }
@ -170,7 +176,6 @@ 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",
"timezone": -1,
"overrides": { "overrides": {
"voteBroadcastMessage": "Late night games? Vote your favourite map!" "voteBroadcastMessage": "Late night games? Vote your favourite map!"
} }

View File

@ -96,6 +96,11 @@ export default class MapVote extends DiscordBasePlugin {
default: '', default: '',
example: '112233445566778899' example: '112233445566778899'
}, },
timezone: {
required: false,
description: "Timezone relative to UTC time. 0 for UTC, 2 for CEST (UTC+2), -1 (UTC-1) ",
default: 0
},
timeFrames: { timeFrames: {
required: false, required: false,
description: 'Array of timeframes to override options', description: 'Array of timeframes to override options',
@ -142,7 +147,10 @@ export default class MapVote extends DiscordBasePlugin {
this.server.on('NEW_GAME', this.onNewGame); this.server.on('NEW_GAME', this.onNewGame);
this.server.on('CHAT_MESSAGE', this.onChatMessage); this.server.on('CHAT_MESSAGE', this.onChatMessage);
this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected); this.server.on('PLAYER_DISCONNECTED', this.onPlayerDisconnected);
this.server.on('PLAYER_CONNECTED', () => { setTimeout(this.setSeedingMode, 5000) }); setTimeout(() => {
this.verbose(1, 'Enabled late listeners.');
this.server.on('PLAYER_CONNECTED', this.setSeedingMode);
}, 10 * 1000) // wait 10 seconds to be sure to have an updated player list
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();
@ -178,25 +186,11 @@ export default class MapVote extends DiscordBasePlugin {
} }
async timeframeOptionOverrider() { async timeframeOptionOverrider() {
const orOpt = { ...this.or_options }; const orOpt = { ...this.or_options };
const utcDelay = parseFloat(this.options.timezone);
let tfFilter = function (tf, key, arr) {
const utcDelay = tf.timezone ? parseFloat(tf.timezone) : 0;
const timeNow = new Date(0, 0, 0, new Date().getUTCHours() + utcDelay, new Date().getUTCMinutes()); 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()}`) this.verbose(1, `Current time (UTC+${utcDelay}) ${timeNow.toLocaleTimeString().split(':').splice(0, 2).join(':')}`)
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 tfStart = new Date(0, 0, 0, ...tfStartSplit)
const tfStart2 = new Date(0, 0, 0, 0, 0)
const tfEnd = new Date(0, 0, 0, ...tfEndSplit)
const tfEnd2 = new Date(0, 0, 0, 24, 0)
return (tfStart <= timeNow && timeNow < tfEnd) || (tfStart > tfEnd && ((tfStart <= timeNow && timeNow < tfEnd2) || (tfStart2 <= timeNow && timeNow < tfEnd)))
}
tfFilter = tfFilter.bind(this);
const activeTimeframes = orOpt.timeFrames.filter(tfFilter); const activeTimeframes = orOpt.timeFrames.filter(tfFilter);
let logTimeframe = "Active Time Frames: "; let logTimeframe = "Active Time Frames: ";
let activeTfIds = []; let activeTfIds = [];
this.options = { ...this.or_options }; this.options = { ...this.or_options };
@ -208,8 +202,17 @@ export default class MapVote extends DiscordBasePlugin {
} }
} }
this.verbose(1, logTimeframe + activeTfIds.join(', ')); this.verbose(1, logTimeframe + activeTfIds.join(', '));
// this.verbose(1, `Current UTC time: ${timeNow.getHours()}:${timeNow.getMinutes()}`)
function tfFilter(tf, key, arr) {
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 tfStart = new Date(0, 0, 0, ...tfStartSplit)
const tfStart2 = new Date(0, 0, 0, 0, 0)
const tfEnd = new Date(0, 0, 0, ...tfEndSplit)
const tfEnd2 = new Date(0, 0, 0, 24, 0)
return (tfStart <= timeNow && timeNow < tfEnd) || (tfStart > tfEnd && ((tfStart <= timeNow && timeNow < tfEnd2) || (tfStart2 <= timeNow && timeNow < tfEnd)))
}
} }
async checkUpdates(callback) { async checkUpdates(callback) {
const versionN = "1.0.0" const versionN = "1.0.0"