added more discord commands support + fix trusted

This commit is contained in:
ChomeNS 2022-11-23 18:10:45 +07:00
parent 9564b45570
commit 8b912f4f9b
10 changed files with 110 additions and 95 deletions

View file

@ -5,5 +5,6 @@
"Music queue added",
"Added *netmsg",
"Fixed hashing",
"You can now *music list [directory]"
"You can now *music list [directory]",
"Added even more Discord commands support"
]

View file

@ -2,17 +2,13 @@
module.exports = {
name: 'ayunsudo',
alias: [],
description: 'Sudo everyone on Ayunboom!',
description: 'Sudos everyone on Ayunboom!',
trusted: 1,
usage: '<hash> <c:|command>',
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.core.run(`essentials:sudo * ${args.slice(1).join(' ')}`);
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
bot.core.run(`essentials:sudo * ${args.join(' ')}`);
} else {
throw new Error('You\'re not in the trusted role!');
}
bot.core.run(`essentials:sudo * ${args.join(' ')}`);
},
};

View file

@ -31,38 +31,34 @@ module.exports = {
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
if (args[0] === 'true' || args[0] === 'on') {
bot.visibility = true;
bot.chat('/essentials:vanish disable');
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription('The bot\'s visibility is now visible');
channeldc.send({embeds: [Embed]});
} else if (args[0] === 'false' || args[0] === 'off') {
bot.visibility = false;
bot.chat('/essentials:vanish enable');
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription('The bot\'s visibility is now invisible');
channeldc.send({embeds: [Embed]});
} else if (!args[0]) {
bot.visibility = !bot.visibility;
const visibleOrInvisible = bot.visibility ? 'visible' : 'invisible';
const enableOrDisable = bot.visibility ? 'disable' : 'enable';
bot.chat(`/essentials:vanish ${enableOrDisable}`);
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription(`The bot\'s visibility is now ${visibleOrInvisible}`);
channeldc.send({embeds: [Embed]});
} else {
throw new SyntaxError('Invalid argument');
}
if (args[0] === 'true' || args[0] === 'on') {
bot.visibility = true;
bot.chat('/essentials:vanish disable');
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription('The bot\'s visibility is now visible');
channeldc.send({embeds: [Embed]});
} else if (args[0] === 'false' || args[0] === 'off') {
bot.visibility = false;
bot.chat('/essentials:vanish enable');
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription('The bot\'s visibility is now invisible');
channeldc.send({embeds: [Embed]});
} else if (!args[0]) {
bot.visibility = !bot.visibility;
const visibleOrInvisible = bot.visibility ? 'visible' : 'invisible';
const enableOrDisable = bot.visibility ? 'disable' : 'enable';
bot.chat(`/essentials:vanish ${enableOrDisable}`);
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Bot\'s Visibility')
.setDescription(`The bot\'s visibility is now ${visibleOrInvisible}`);
channeldc.send({embeds: [Embed]});
} else {
throw new Error('You\'re not in the trusted role!');
throw new SyntaxError('Invalid argument');
}
},
};

View file

@ -5,7 +5,12 @@ module.exports = {
alias: ['ccq'],
usage: '',
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
execute: function(bot) {
if (bot.queue[0]) {
bot.chatQueue = [];
}
},
discordExecute: function(bot) {
if (bot.queue[0]) {
bot.chatQueue = [];
}

View file

@ -86,37 +86,32 @@ module.exports = {
},
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], bot);
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloop')
.setDescription(`Removed cloop \`${args[1]}\``);
channeldc.send({embeds: [Embed]});
} else if (args[0] === 'removeall') {
clear(bot);
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloop')
.setDescription('Removed all looped commands');
channeldc.send({embeds: [Embed]});
} else {
throw new Error('Invalid argument');
}
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], bot);
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cloop')
.setDescription(`Removed cloop \`${args[1]}\``);
channeldc.send({embeds: [Embed]});
} else if (args[0] === 'removeall') {
clear(bot);
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!');
throw new Error('Invalid argument');
}
},
};

View file

@ -1,11 +1,15 @@
/* eslint-disable max-len */
const cowsay = require('cowsay2');
const cows = require('cowsay2/cows');
const {MessageEmbed} = require('discord.js');
module.exports = {
name: 'cowsay',
alias: [],
description: 'Moo',
usage: '<cow|list> <message>',
usage: [
'<cow> <message>',
'<list (not support on Discord)>',
],
trusted: 0,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
if (args[0]==='list') {
@ -27,7 +31,14 @@ module.exports = {
bot.tellraw(selector, message);
} else {
bot.tellraw(selector, {text: `${cowsay.say(args.slice(1).join(' '), {cow: cows[args[0]]})}`});
bot.tellraw(selector, {text: cowsay.say(args.slice(1).join(' '), {cow: cows[args[0]]})});
}
},
execute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Cowsay')
.setDescription(cowsay.say(args.slice(1).join(' '), {cow: cows[args[0]]}));
channeldc.send({embeds: [Embed]});
},
};

View file

@ -20,15 +20,9 @@ module.exports = {
usage: '<hash>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
crash(bot);
crash(bot);
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
crash(bot);
} else {
throw new Error('You\'re not in the trusted role!');
}
crash(bot);
},
};

View file

@ -6,15 +6,9 @@ module.exports = {
usage: '<hash>',
trusted: 1,
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
bot.end('end command');
bot.end('end command');
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) {
if (message.member.roles.cache.some((role) => role.name === 'Trusted')) {
bot.end('end command');
} else {
throw new Error('You\'re not in the trusted role!');
}
bot.end('end command');
},
};

View file

@ -1,6 +1,7 @@
/* eslint-disable max-len */
const util = require('util');
const {stylize} = require('../util/colors/minecraft');
const {MessageEmbed} = require('discord.js');
module.exports = {
name: 'servereval',
alias: [],
@ -9,9 +10,24 @@ module.exports = {
usage: '<ownerhash> <code>',
execute: function(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
try {
bot.tellraw(selector, {text: `${util.inspect(eval(args.slice(1).join(' ')), {stylize: stylize})}`.substring(0, 32000)});
bot.tellraw(selector, {text: util.inspect(eval(args.slice(1).join(' ')), {stylize}).substring(0, 32766)});
} catch (err) {
bot.tellraw(selector, {text: `${util.inspect(err).replaceAll('runner', 'chayapak1')}`, color: 'red'});
bot.tellraw(selector, {text: util.inspect(err).replaceAll('runner', 'chayapak1'), color: 'red'});
}
},
discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
try {
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Output')
.setDescription(util.inspect(eval(args.join(' ')), {stylize}));
channeldc.send({embeds: [Embed]});
} catch (err) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`${util.inspect(err).replaceAll('runner', 'chayapak1')}\`\`\``);
channeldc.send({embeds: [Embed]});
}
},
};

View file

@ -15,23 +15,30 @@ function inject(bot, dcclient, config) {
bot.command_handler.reload();
let raw;
let command;
message.content ? raw = message.content.substring(prefix.length) : raw = message.substring(prefix.length);
const discord = message.content ? true : false;
discord ? raw = message.content.substring(prefix.length) :
raw = message.substring(prefix.length);
const [commandName, ...args] = raw.split(' ');
command = bot.command_handler.commands.find((command) => command.name === commandName.toLowerCase());
try {
const alias = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()));
if (alias) command = bot.command_handler.commands.find((command) => command.alias.includes(commandName.toLowerCase()));
if (prefix === '*' && message.endsWith('*') && message !== '*') return;
if (!command) throw new Error(`Unknown command: "${commandName}"`);
if (command.trusted === 1) {
if (args[0] !== hash) throw new Error('Invalid hash');
} else if (command.trusted === 2) {
if (args[0] !== ownerhash) throw new Error('Invalid OwnerHash');
if (command.name !== 'validate' && command.trusted === 1) {
if (discord && !message.member?.roles?.cache?.some((role) => role.name === 'Trusted')) throw new Error('You\'re not in the trusted role!');
else if (!discord && args[0] !== hash) throw new Error(`Invalid hash`);
} else if (command.name !== 'validate' && command.trusted === 2) {
if (discord && !message.member?.roles?.cache?.some((role) => role.name === 'Trusted')) throw new Error('You\'re not in the trusted role!');
else if (!discord && args[0] !== hash) throw new Error(`Invalid OwnerHash`);
}
if (prefix === config.discord.prefix) {
if (typeof command.discordExecute === 'undefined') throw new Error('This command is not yet supported on discord!');
if (!command.discordExecute) throw new Error('This command is not yet supported on discord!');
command.discordExecute(bot, username, usernameraw, sender, prefix, args, channeldc, message, config);
} else {
command.execute(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector);