cloop discord support

This commit is contained in:
ChomeNS 2022-10-20 08:14:29 +07:00
parent 3780245861
commit 333b524f84

View file

@ -1,4 +1,5 @@
/* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
function add(command, interval, bot) {
const id = setInterval(() => bot.core.run(command), interval);
@ -14,9 +15,29 @@ function clear() {
bot.cloops = [];
}
function list(bot) {
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');
@ -81,4 +102,58 @@ module.exports = {
return;
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (!bot.cloops) bot.cloops = [];
if (args[0]==='add') {
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
if (args[2]) {
if (!Number(args[1])) 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 {
throw new Error('You\'re not in the trusted role!');
}
return;
}
if (args[0]==='list') {
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
list(bot, true, channeldc);
} else {
throw new Error('You\'re not in the trusted role!');
}
return;
}
if (args[0]==='remove') {
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
remove(args[1]);
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloop')
.setDescription(`Removed cloop \`${args[1]}\``);
channeldc.send({embeds: [Embed]});
} else {
throw new Error('You\'re not in the trusted role!');
}
return;
}
if (args[0]==='removeall') {
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
clear();
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloop')
.setDescription('Removed all looped commands');
channeldc.send({embeds: [Embed]});
} else {
throw new Error('You\'re not in the trusted role!');
}
return;
}
},
};