forked from LukeSkywalker92/TeleFrame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (56 loc) · 2.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const {AddonBase} = require(`${__dirname}/../../js/addonInterface`);
class ClassExampleAutoControl extends AddonBase {
constructor(config) {
super(config);
// when the renderer is ready start the auto control timer
this.registerListener('renderer-ready', () => {
setTimeout(() => this.autoControl(), 25000)
this.logger.info('Started auto control timer');
});
}
/**
* returns a random integer between min and max
* @param {number} min
* @param {number} max
* @return {number} the ranom number
*/
randomIntegerBetween(min, max) {
return Math.floor(min + Math.random()*(max + 1 - min))
}
/**
* Send pause, then randomly the commands previous or next and also messages at start and end
*/
autoControl() {
//this.logger.warn(`Now I'm taking over :-)`);
this.sendEvent('messageBox', {
html: `<p><small>${this.name} said:</small><br>Now I'm taking over \u{1F608}</p>`,
position: 'top-end',
timer: 1800000,
background: 'rgba(255,255,255, 0.6)',
allowOutsideClick: false
});
this.logger.info(`Send event: pause`);
this.sendEvent('pause');
this.changedImages = 0;
const autoTimer = setInterval(() => {
let cmd = (this.randomIntegerBetween(0, 1) ? 'next' : 'previous');
this.logger.info(`Send event: ${cmd}`);
this.sendEvent(cmd, this.randomIntegerBetween(1500, 2000));
if (++this.changedImages > this.randomIntegerBetween(4, 9)) {
clearTimeout(autoTimer);
// restart autoControl after 17 - 23 seconds
setTimeout(() => this.autoControl(), this.randomIntegerBetween(17000, 23000));
//this.logger.warn(`Now you ...`);
this.sendEvent('messageBox', {
html: `<p><small>${this.name} said:</small><br>Now you \u{1F60E}</p>`,
timer: 3500
});
this.sendEvent('play');
}
}, this.randomIntegerBetween(3000, 5000));
}
};
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {
module.exports = ClassExampleAutoControl;
}