2021-08-26 18:35:42 -07:00

48 lines
1.4 KiB
JavaScript

var commands = module.exports = [
{
name: "ping",
description: "Test command",
exec: m => m.say("pong")
},
{
name: "owo",
description: "owo",
exec: m => {
let owo = Math.round(Math.random()) ? 'O' : 'o';
let n = Math.min(Number(query) || 9, 1998);
for (let i = 0; i < n; i++) owo += ['o','w','O','W'][Math.floor(Math.random() * 4)];
owo += owo = Math.round(Math.random()) ? 'O' : 'o';
m.say(owo);
}
}
];
client.on("messageCreate", async message => {
try {
let args = message.content.split(' ');
message.query = args.slice(1).join(' ');
message.say = message.channel.send.bind(message.channel);
if (!message.guild) message.guild = client.guilds.resolve(config.guild);
if (!message.member) message.member = await message.guild.members.fetch(message.author.id);
for (let command of commands) {
if ((()=>{
if (!command.matcher) command.matcher = command.name.toLowerCase();
if (typeof command.matcher == "string") return command.name == '!' + args[0].toLowerCase();
if (typeof command.matcher == "function") return command.matcher(message);
if (command.matcher instanceof RegExp) return message.content.test(command.matcher);
})()) {
if (command.admin && !message.member?.roles.cache.has(config.admin_role)) return void message.react('🚫');
await command.exec(message);
break;
}
}
} catch (error) {
console.error("command failure,", error.stack);
message.react("⚠");
}
});