mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-27 09:35:35 -05:00
121 lines
4 KiB
JavaScript
121 lines
4 KiB
JavaScript
/* eslint-disable max-len */
|
|
const {MessageEmbed} = require('discord.js');
|
|
function add(command, interval, bot) {
|
|
const id = setInterval(() => bot.core.run(command), interval);
|
|
|
|
bot.cloops.push({id, interval, command});
|
|
}
|
|
function remove(item) {
|
|
clearInterval(bot.cloops[item].id);
|
|
|
|
bot.cloops.splice(item, 1);
|
|
}
|
|
function clear() {
|
|
for (const interval of bot.cloops) clearInterval(interval.id);
|
|
|
|
bot.cloops = [];
|
|
}
|
|
function list(bot, discord, channeldc) {
|
|
const message = [];
|
|
|
|
if (discord) {
|
|
for (const [id, cloop] of Object.entries(bot.cloops)) {
|
|
message.push(id);
|
|
message.push(' > ');
|
|
message.push(`\`${cloop.command}\``);
|
|
message.push(' - ');
|
|
message.push(cloop.interval);
|
|
message.push('\n');
|
|
}
|
|
|
|
message.pop();
|
|
|
|
const Embed = new MessageEmbed()
|
|
.setColor('#FFFF00')
|
|
.setTitle('Cloops')
|
|
.setDescription(message.join(''));
|
|
channeldc.send({embeds: [Embed]});
|
|
return;
|
|
}
|
|
|
|
message.push({text: 'Cloops:', color: 'green'});
|
|
message.push('\n');
|
|
|
|
for (const [id, cloop] of Object.entries(bot.cloops)) {
|
|
message.push({text: id, color: 'aqua'});
|
|
message.push({text: ' > ', color: 'gold'});
|
|
message.push({text: cloop.command, color: 'green'});
|
|
message.push({text: ' - ', color: 'gold'});
|
|
message.push({text: cloop.interval, color: 'green'});
|
|
message.push('\n');
|
|
}
|
|
|
|
message.pop();
|
|
|
|
bot.tellraw('@a', message);
|
|
}
|
|
module.exports = {
|
|
name: 'cloop',
|
|
alias: [],
|
|
description: 'Loop commands',
|
|
usage: '<hash> <add|remove|removeall|list> <interval|index> <command>',
|
|
trusted: 1,
|
|
execute: function(bot, username, usernameraw, sender, prefix, args) {
|
|
if (!bot.cloops) bot.cloops = [];
|
|
|
|
if (args[0] === bot.hash) {
|
|
if (args[1] === 'add' && args[3]) {
|
|
if (!Number(args[2]) && Number(args[2]) !== 0) throw new SyntaxError('Invalid interval');
|
|
add(args.slice(3).join(' '), args[2], bot);
|
|
bot.tellraw('@a', [{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'}]);
|
|
} else if (args[1] === 'list') {
|
|
list(bot);
|
|
} else if (args[1] === 'remove') {
|
|
remove(args[2]);
|
|
bot.tellraw('@a', [{text: 'Removed cloop '}, {text: args[2], color: 'aqua'}]);
|
|
} else if (args[1] === 'removeall') {
|
|
clear();
|
|
bot.tellraw('@a', [{text: 'Removed all looped commands', color: 'white'}]);
|
|
} else {
|
|
throw new SyntaxError('Invalid argument');
|
|
}
|
|
} else {
|
|
throw new Error('Invalid hash');
|
|
}
|
|
},
|
|
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
|
|
if (!bot.cloops) bot.cloops = [];
|
|
|
|
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
|
|
if (args[0] === 'add' && args[2]) {
|
|
if (!Number(args[1]) && Number(args[1]) !== 0) throw new SyntaxError('Invalid interval');
|
|
add(args.slice(2).join(' '), args[1], bot);
|
|
const Embed = new MessageEmbed()
|
|
.setColor('#FFFF00')
|
|
.setTitle('Cloop')
|
|
.setDescription(`Added cloop \`${args.slice(2).join(' ')}\` with interval ${args[1]} to the cloops`);
|
|
channeldc.send({embeds: [Embed]});
|
|
} else if (args[0] === 'list') {
|
|
list(bot, true, channeldc);
|
|
} else if (args[0] === 'remove') {
|
|
remove(args[1]);
|
|
const Embed = new MessageEmbed()
|
|
.setColor('#FFFF00')
|
|
.setTitle('Cloop')
|
|
.setDescription(`Removed cloop \`${args[1]}\``);
|
|
channeldc.send({embeds: [Embed]});
|
|
} else if (args[0] === 'removeall') {
|
|
clear();
|
|
const Embed = new MessageEmbed()
|
|
.setColor('#FFFF00')
|
|
.setTitle('Cloop')
|
|
.setDescription('Removed all looped commands');
|
|
channeldc.send({embeds: [Embed]});
|
|
} else {
|
|
throw new Error('Invalid argument');
|
|
}
|
|
} else {
|
|
throw new Error('You\'re not in the trusted role!');
|
|
}
|
|
},
|
|
};
|