diff --git a/commands/cloop.js b/commands/cloop.js index 0ecf102..d57917e 100644 --- a/commands/cloop.js +++ b/commands/cloop.js @@ -1,5 +1,4 @@ /* eslint-disable max-len */ -bot.cloops = []; function add(command, interval, bot) { const id = setInterval(() => bot.core.run(command), interval); @@ -41,15 +40,12 @@ module.exports = { usage: ' ', trusted: 1, execute: function(bot, username, usernameraw, sender, prefix, args) { + if (!bot.cloops) bot.cloops = []; + if (args[1]==='add') { if (args[0]===bot.hash) { - if (typeof args[3]!=='undefined') { - // bot.cloopnumbers++; - // bot.clooparr.push(args.slice(3).join(' ')); - // eval(`bot.command${bot.cloopnumbers} = args.slice(3).join(' ')`); - // eval(`bot.interval${bot.cloopnumbers} = args[2]`); - // eval(`bot.cloop${bot.cloopnumbers} = setInterval(() => { bot.core.run(bot.command${bot.cloopnumbers}) }, bot.interval${bot.cloopnumbers})`); - // eval(`bot.core.run('minecraft:tellraw @a ["",{"text":"Added command ","color":"white"},{"text":"' + bot.command${bot.cloopnumbers} + '","color":"aqua"},{"text":" with interval ","color":"white"},{"text":"' + bot.interval${bot.cloopnumbers} + '","color":"green"},{"text":" to the cloops","color":"white"}]')`); + if (args[3]) { + if (!Number(args[2])) throw new SyntaxError('Invalid interval'); add(args.slice(3).join(' '), args[2], bot); bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Added command ', color: 'white'}, {text: `${args.slice(3).join(' ')}`, color: 'aqua'}, {text: ' with interval ', color: 'white'}, {text: `${args[2]}`, color: 'green'}, {text: ' to the cloops', color: 'white'}])); } @@ -60,10 +56,6 @@ module.exports = { } if (args[1]==='list') { if (args[0]===bot.hash) { - // bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: 'Cloops:'}])); - // bot.clooparr.forEach((item, index) => { - // bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: `${index}`, color: 'aqua'}, {text: ' > ', color: 'gold'}, {text: `${item}`, color: 'green'}])); - // }); list(bot); } else { throw new Error('Invalid hash'); @@ -72,10 +64,6 @@ module.exports = { } if (args[1]==='remove') { if (args[0]===bot.hash) { - // eval(`if (typeof bot.cloop${Number(args[2])}==='undefined'){ throw new Error('Invalid index') }`); - // bot.clooparr.shift(Number(args[2])); - // eval(`clearInterval(bot.cloop${Number(args[2])})`); - // bot.cloopnumbers - 1; remove(args[2]); bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: 'Removed cloop '}, {text: args[2], color: 'aqua'}])); } else { @@ -85,11 +73,6 @@ module.exports = { } if (args[1]==='removeall') { if (args[0]===bot.hash) { - // for (let i = 0; i <= bot.cloopnumbers; i++) { - // bot.clooparr.shift(i); - // eval(`clearInterval(bot.cloop${i})`); - // } - // bot.cloopnumbers = -1; clear(); bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: 'Removed all looped commands', color: 'white'}])); } else {