2020-11-28 16:38:23 +00:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
const { client, logger } = require('../index');
|
|
|
|
const prefix = process.env.BOT_PREFIX || '-';
|
|
|
|
|
|
|
|
module.exports.run = () => {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const { commands } = require('./commandLoader');
|
|
|
|
|
|
|
|
client.on('message', message => {
|
|
|
|
if (message.author?.bot) return;
|
|
|
|
addToDatabase(message.author.id);
|
|
|
|
|
|
|
|
require('./wit').execute(message);
|
|
|
|
try {
|
|
|
|
logger.debug(`${message.author.tag} => ${message.content}`);
|
|
|
|
|
|
|
|
let msgContent = message.content;
|
|
|
|
let usedPrefix;
|
|
|
|
if (msgContent.startsWith(prefix)) usedPrefix = prefix;
|
|
|
|
else if (msgContent.startsWith(`<@${client.user.id}>`)) usedPrefix = `<@${client.user.id}>`;
|
|
|
|
else if (msgContent.startsWith(`<@!${client.user.id}>`)) usedPrefix = `<@!${client.user.id}>`;
|
|
|
|
|
|
|
|
if (!usedPrefix) return require('./69Reply').execute(message);
|
2020-12-27 11:57:38 +00:00
|
|
|
msgContent = msgContent.substr(msgContent.indexOf(usedPrefix) + 1, msgContent.length);
|
2020-11-28 16:38:23 +00:00
|
|
|
if (msgContent.startsWith(' ') && usedPrefix != prefix) msgContent = msgContent.substr(1, msgContent.length);
|
|
|
|
const args = msgContent.split(' ');
|
2020-12-23 12:48:30 +00:00
|
|
|
const cmdName = args.shift()?.toLowerCase();
|
2020-11-28 16:38:23 +00:00
|
|
|
|
|
|
|
const cmd = commands.find(cmd => cmd.meta?.name == cmdName || cmd.meta?.aliases?.indexOf(cmdName) > -1);
|
|
|
|
if (!cmd) return require('./69Reply').execute(message);
|
|
|
|
|
2020-12-27 12:04:08 +00:00
|
|
|
logger.info(`[CMD] ${message.author.id} ${message.author.tag} => ${cmdName} ${args.join(' ')}`);
|
2020-12-23 12:48:30 +00:00
|
|
|
|
2020-11-28 16:38:23 +00:00
|
|
|
if (cmd.meta?.staffOnly && !message.member.permissions.has('ADMINISTRATOR')) {
|
2020-12-23 12:48:30 +00:00
|
|
|
logger.warn(`${message.author.tag} => Refusing to run staff command`);
|
2020-11-28 16:38:23 +00:00
|
|
|
message.channel.send(
|
|
|
|
new Discord.MessageEmbed()
|
|
|
|
.setTitle('You are unworthy')
|
|
|
|
.setDescription('This command can only be used by this server\'s staff.')
|
|
|
|
.setImage('https://media1.tenor.com/images/1056e92668594b262d3338c897ce9bd3/tenor.gif?itemid=7706023')
|
|
|
|
.setColor('ff0000')
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
}
|
2020-12-27 12:57:35 +00:00
|
|
|
else if (cmd.meta?.epicOnly && !message.member.roles.cache.get('718862546395988078')) {
|
|
|
|
logger.warn(`${message.author.tag} => Refusing to run epic only command`);
|
|
|
|
message.channel.send(
|
|
|
|
new Discord.MessageEmbed()
|
|
|
|
.setTitle('You are unworthy')
|
|
|
|
.setDescription('Only epic people can use this command. You are not epic.')
|
|
|
|
.setImage('https://media1.tenor.com/images/1056e92668594b262d3338c897ce9bd3/tenor.gif?itemid=7706023')
|
|
|
|
.setColor('ff0000')
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
}
|
2020-11-28 16:38:23 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
cmd.run(message, args);
|
|
|
|
} catch(e) {
|
|
|
|
console.error(e);
|
|
|
|
message.channel.send(
|
|
|
|
new Discord.MessageEmbed()
|
|
|
|
.setTitle('You broke Obama')
|
|
|
|
.setDescription(`Good job, you broke Obama. Debug info: \`\`\`js\n${e}\`\`\``)
|
|
|
|
.setColor('ff0000')
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
console.error(e);
|
|
|
|
message.channel.send('An error has occurred. fuck');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const karma = require('./karma').karma;
|
|
|
|
const coins = require('./karma').coins;
|
|
|
|
function addToDatabase(id) {
|
|
|
|
if (!id) return;
|
|
|
|
if (typeof karma.get(id) != 'number') karma.set(id, 0);
|
|
|
|
if (typeof coins.get(id) != 'number') coins.set(id, 0);
|
|
|
|
return;
|
|
|
|
}
|