So i tried to made a discord bot, with discord-js.commando and commander.js as argument parser..
the command looks like this
!notif <command> [options]
!notif add alarm -b 2pm //will invoke heart('username').CreateEvent
!notif list //will show list of added CreateEvent
!notif cancel [alarm_id]
so in example if i invoke
!notif add alarm
it will create a heart with the name of the user who invoke that command, and create an event with random number on the end of name (alarm_123)
the first time i invoke it will tell user "alarm_9 added" the first time it is called, it is work just fine, but the second time i call it, it will create 2 events instead of SUPPOSED only 1;
the second time will output like this
"Alarm_11 added"
"Alarm_13 added"
the third time will output like this
"Alarm_14 added"
"Alarm_15 added"
"Alarm_16 added"
so when i check with !notif list it will show that i have more than expected events, incremented everytime i invoke the event
i already put a some kind of guard clause above CREATEEVENT, just to be sure if heart with that name is exist
add(options) {
if (!heartbeats.heart(author.username)) {
this.heart = heartbeats.createHeart(2000, author.username);
msg.reply(`${this.heart.name} is created`);
}
....... // rest of code that CreateEvent
msg.reply('${alarmName} added'}
}
my commander.js parser looks like this, it seems everytime it is invoked, it parses the last command or whatever i dunno, but it parses
const argument = require('commander');
run(args, fake) {
if (fake === true) args.unshift('', ''); //since commander.js are intended for CLI i need to unshift the parser, so it works with discord,
argument
.version('0.0.1')
.command('add <alarmName>')
.option('-b, --before [time] <n>', 'before time')
.option('-a, --after [time] <n>', 'after time')
.action((alarmName, options) => {
this.add(options); //
});
argument
.command('list')
.description('List added notification')
.action(() => {
});
argument
.command('cancel <objectName>')
.description('Cancel current notification')
.action((objectName) => {
heartbeats.heart(this._options.owner).killEvent(objectName);
console.log(`${objectName} is killed!`); //the second time it is called it will give 2 times output
});
argument
.command('info')
.action(() => {
});
argument.parse(args);
return argument;
}
the question to this problem, should i create a child process for every user that invoke those so they have isolated space on their own ? or which way are the best ?... please light me up. ive been tried finding npm package that fit for my goals, most of packages are deprecated or not exactly fit, only heartbeats that seems to work, i need some kind of timer/interval manager, that can be killed, added to list, also since commander.js are intended for CLI i need to unshift the parser, so it works with discord,