2020-07-17 16:08:27 +00:00
|
|
|
const { Wit } = require('node-wit');
|
|
|
|
const { Message } = require('discord.js');
|
2020-11-28 16:38:23 +00:00
|
|
|
const { logger } = require('..');
|
|
|
|
if (!process.env.WIT_TOKEN) return logger.warn(`No wit.ai token found, disabling AI features`);
|
|
|
|
const client = new Wit({accessToken: process.env.WIT_TOKEN});
|
2020-07-17 16:08:27 +00:00
|
|
|
|
|
|
|
function random(low, high) {
|
|
|
|
low = Math.ceil(low);
|
|
|
|
high = Math.floor(high);
|
|
|
|
high = high + 1;
|
|
|
|
rndm = Math.random();
|
|
|
|
return Math.floor(rndm * (high - low) + low);
|
|
|
|
}
|
|
|
|
|
2020-11-28 16:38:23 +00:00
|
|
|
// The database karma is stored in
|
|
|
|
const karmaDB = require('./karma').karma;
|
|
|
|
const coinsDB = require('./karma').coins;
|
2020-07-17 16:08:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Message} message
|
|
|
|
*/
|
2021-02-18 14:22:32 +00:00
|
|
|
module.exports.execute = async (message) => {
|
2020-07-17 16:08:27 +00:00
|
|
|
if (!message.content) return;
|
|
|
|
if (message.content.length > 280) return randomAward();
|
|
|
|
|
|
|
|
// Send the message to wit.ai
|
|
|
|
client.message(message.content)
|
|
|
|
.then(response => {
|
2021-02-10 13:21:09 +00:00
|
|
|
if (message.deleted) return;
|
2020-07-17 16:08:27 +00:00
|
|
|
let action = response.intents[0];
|
|
|
|
|
|
|
|
// "Execute" the intent.
|
|
|
|
if (!action) return randomAward();
|
|
|
|
switch(action.name) {
|
|
|
|
case 'awardspam':
|
|
|
|
// Disabled for "karma balancing reasons"
|
2020-12-30 15:24:31 +00:00
|
|
|
randomAward(1.1);
|
2020-07-17 16:08:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Spam a fuckton of awards
|
2021-02-18 14:22:32 +00:00
|
|
|
['731564182079799306', '719181283393142786', '731192828415443116', '731192829262692372', '731192942080950333', '731508866273247252', '716021350883393566']
|
|
|
|
.forEach(async id => await message.react(id));
|
2020-07-17 16:08:27 +00:00
|
|
|
break;
|
|
|
|
case 'upvote':
|
|
|
|
message.react('719181283393142786');
|
|
|
|
karmaDB.inc(message.author.id);
|
|
|
|
break;
|
|
|
|
case 'downvote':
|
|
|
|
message.react('719181283774955540');
|
|
|
|
karmaDB.dec(message.author.id);
|
|
|
|
break;
|
2020-12-30 15:24:31 +00:00
|
|
|
case 'bruh':
|
|
|
|
message.react('730882526259707997');
|
|
|
|
break;
|
2020-07-17 16:08:27 +00:00
|
|
|
default:
|
2020-12-30 15:24:31 +00:00
|
|
|
randomAward(1);
|
2020-07-17 16:08:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
2021-02-18 14:22:32 +00:00
|
|
|
message.channel.send(`Wit.ai error:\n\`\`\`js\n${error}\`\`\``);
|
2020-07-17 16:08:27 +00:00
|
|
|
});
|
2020-12-30 15:24:31 +00:00
|
|
|
function randomAward(multiplier) {
|
|
|
|
if (!multiplier) multiplier = 1;
|
2020-07-17 16:08:27 +00:00
|
|
|
// Randomly decide if the message should get a random "award" or yeet an obamium on it
|
|
|
|
if (message.content.toLowerCase().indexOf('obamium') > -1 || message.content.toLowerCase().indexOf('obama') > -1) {
|
|
|
|
return message.react('716021350883393566').catch();
|
|
|
|
}
|
2020-12-30 15:24:31 +00:00
|
|
|
const randomNum = (random(0, 10000) / 100) * multiplier;
|
2020-11-28 16:38:23 +00:00
|
|
|
if (randomNum > 99.9) {message.react('731508866273247252').catch(); coinsDB.set(message.author.id, (coinsDB.get(message.author.id) + 2500))} // Argentinum
|
2020-07-17 16:08:27 +00:00
|
|
|
else if (randomNum > 99.5) {message.react('731192942080950333').catch(); coinsDB.set(message.author.id, (coinsDB.get(message.author.id) + 700)) } // Platinum
|
2020-11-28 16:38:23 +00:00
|
|
|
else if (randomNum > 99) {message.react('731192829262692372').catch(); coinsDB.set(message.author.id, (coinsDB.get(message.author.id) + 100)) } // Gold
|
2020-07-17 16:08:27 +00:00
|
|
|
else if (randomNum > 98) {message.react('731192828415443116').catch(); coinsDB.set(message.author.id, (coinsDB.get(message.author.id) + 0)) } // Silver
|
|
|
|
require('./karma').updateRoles(message.author.id);
|
|
|
|
}
|
2020-11-28 16:38:23 +00:00
|
|
|
}
|