Add timer core

This commit is contained in:
Minz committed 2023-11-07 14:19:36 +01:00
1 parent f022dcbba9
commit 7f020dd179
2 files changed
+30

No files matched your search

+15
View File
@@ -36,4 +36,19 @@ for (const file of eventFiles) {
}
}
client.on(Events.ClientReady, () => {
//setup timers
const timersPath = path.join(__dirname, 'timers');
const timerFiles = fs.readdirSync(timersPath).filter(file => file.endsWith('.js'));
for (const file of timerFiles) {
const filePath = path.join(timersPath, file);
const timer = require(filePath);
console.log(`Started Timer ${timer.name}`);
let timerInstance = setInterval(() => {
timer.tick(client, timer);
}, timer.timeout);
timer.instance = timerInstance;
}
});
client.login(token);
+15
View File
@@ -0,0 +1,15 @@
module.exports = {
timeout: 1000,
global: true,
name: 'Test timer every 1 sec',
data: {
i: 0
},
async tick(client, timer) {
console.log(`Test timer ticked ${timer.data.i}`);
timer.data.i++;
if(timer.data.i >= 5) {
clearInterval(timer.instance);
}
},
};