83 lines
3.5 KiB
JavaScript
83 lines
3.5 KiB
JavaScript
const { Wit } = require('node-wit');
|
|
const { Message } = require('discord.js');
|
|
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});
|
|
|
|
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);
|
|
}
|
|
|
|
// The database karma is stored in
|
|
const karmaDB = require('./karma').karma;
|
|
const coinsDB = require('./karma').coins;
|
|
|
|
/**
|
|
* @param {Message} message
|
|
*/
|
|
module.exports.execute = function(message) {
|
|
if (!message.content) return;
|
|
if (message.content.length > 280) return randomAward();
|
|
|
|
// Send the message to wit.ai
|
|
client.message(message.content)
|
|
.then(response => {
|
|
if (message.deleted) return;
|
|
let action = response.intents[0];
|
|
|
|
// "Execute" the intent.
|
|
if (!action) return randomAward();
|
|
switch(action.name) {
|
|
case 'awardspam':
|
|
// Disabled for "karma balancing reasons"
|
|
randomAward(1.1);
|
|
return;
|
|
|
|
// Spam a fuckton of awards
|
|
message.react('731564182079799306').then(() => {
|
|
message.react('719181283393142786').catch().then(() => {
|
|
message.react('731192828415443116').catch().then(() => {
|
|
message.react('731192829262692372').catch().then(() => {
|
|
message.react('731192942080950333').catch().then(() => {
|
|
message.react('731508866273247252').catch().then(() => {
|
|
message.react('716021350883393566').catch();
|
|
})})})})})});
|
|
break;
|
|
case 'upvote':
|
|
message.react('719181283393142786');
|
|
karmaDB.inc(message.author.id);
|
|
break;
|
|
case 'downvote':
|
|
message.react('719181283774955540');
|
|
karmaDB.dec(message.author.id);
|
|
break;
|
|
case 'bruh':
|
|
message.react('730882526259707997');
|
|
break;
|
|
default:
|
|
randomAward(1);
|
|
break;
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
message.channel.send('Wit.ai error:\n' + error);
|
|
});
|
|
function randomAward(multiplier) {
|
|
if (!multiplier) multiplier = 1;
|
|
// 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();
|
|
}
|
|
const randomNum = (random(0, 10000) / 100) * multiplier;
|
|
if (randomNum > 99.9) {message.react('731508866273247252').catch(); coinsDB.set(message.author.id, (coinsDB.get(message.author.id) + 2500))} // Argentinum
|
|
else if (randomNum > 99.5) {message.react('731192942080950333').catch(); coinsDB.set(message.author.id, (coinsDB.get(message.author.id) + 700)) } // Platinum
|
|
else if (randomNum > 99) {message.react('731192829262692372').catch(); coinsDB.set(message.author.id, (coinsDB.get(message.author.id) + 100)) } // Gold
|
|
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);
|
|
}
|
|
} |