diff --git a/bot/modules/price.js b/bot/modules/price.js index d59e904..5e843cf 100644 --- a/bot/modules/price.js +++ b/bot/modules/price.js @@ -512,7 +512,8 @@ exports.price = { let currency = words.length > 0 ? words[0].toUpperCase() : options.defaultCurrency; let amount = words.length > 1 ? parseFloat(words[1], 10) : 1; - let showHelp = isNaN(amount) || Object.keys(options.currencies).indexOf(currency) === -1; + let showHelp = !suffix; + //let showHelp = isNaN(amount) || Object.keys(options.currencies).indexOf(currency) === -1; // store the last retrieved rate let cachedRates = {}; let command = '!price'; diff --git a/bot/modules/purge.js b/bot/modules/purge.js deleted file mode 100644 index 32c64ec..0000000 --- a/bot/modules/purge.js +++ /dev/null @@ -1,43 +0,0 @@ -let hasPerms = require('../helpers.js').hasPerms; -let inPrivate = require('../helpers.js').inPrivate; -exports.commands = [ - 'purge' // command that is in this file, every command needs it own export as shown below -]; - -exports.purge = { - usage: '', - description: 'Deletes Messages', - process: function(bot, msg, suffix) { - if (inPrivate(msg)) { - msg.channel.send("You Cant Purge Message In DM's!"); - return; - } - if (hasPerms(msg)) { - let newamount = 0; - if (!suffix) { - newamount = 2; - } else { - let amount = Number(suffix); - let adding = 1; - newamount = amount + adding; - } - let messagecount = newamount.toString(); - msg.channel - .fetchMessages({ - limit: messagecount - }) - .then(messages => { - msg.channel.bulkDelete(messages); - // Logging the number of messages deleted on both the channel and console. - msg.channel.send('Deletion of messages successful. \n Total messages deleted including command: ' + newamount).then(message => message.delete(5000)); - console.log('Deletion of messages successful. \n Total messages deleted including command: ' + newamount); - }) - .catch(err => { - console.log('Error while doing Bulk Delete'); - console.log(err); - }); - } else { - msg.channel.send('only moderators can use this command!').then(message => message.delete(5000)); - } - } -}; diff --git a/bot/modules/rolesetter.js b/bot/modules/rolesetter.js deleted file mode 100644 index 5f40478..0000000 --- a/bot/modules/rolesetter.js +++ /dev/null @@ -1,129 +0,0 @@ -//let config = require('config'); -//let botconfig = config.get('bot'); -//let rolelist = config.get('rolelist'); -//let inPrivate = require('../helpers.js').inPrivate; -// -//exports.commands = [ -// 'addrole', // command that is in this file, every command needs it own export as shown below -// 'delrole', -// 'roles' -//]; -// -//exports.addrole = { -// usage: '', -// description: 'Adds you to specified role', -// process: function(bot, msg, suffix) { -// // Provide shortened syntax for the sake of code cleanliness -// let send = msgTxt => msg.channel.send(msgTxt); -// // Checks if the user has messaged the bot via Direct Message -// if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.'); -// -// // Here the bot, msg and suffix is avaible, this function can be async if needed. -// // Make sure to eliminate case sensitivity, do this here to only perform the sweep once. -// let newrole = msg.guild.roles.find(role => role.name.toLowerCase() === suffix.toLowerCase()); -// // Baserole is assumed to already be case accurate as it's handled in the config itself. -// let baserole = msg.guild.roles.find(item => item.name === rolelist.baserole); -// -// let rolecmd = botconfig.prefix + 'roles'; -// -// // Checks if the user included a role in their message -// if (!suffix) return send('Please specify a role. Type ' + rolecmd + ' to see which you may add yourself!'); -// // Checks if there is a matching role found on the server -// if (!newrole) return send('The role specified `' + suffix + '` does not exist on this server!'); -// // Checks that the allowed roles and base role against the matched role's name, since this eliminates case sensitivity issues -// if (!rolelist.allowedroles.includes(newrole.name) && !rolelist.baserole.includes(newrole.name)) return send("That role isn't one you can add yourself to! Type " + rolecmd + ' command to find out which ones are allowed.'); -// // Use the matched name to check against the member's existing roles -// if (msg.member.roles.find(item => item.name === newrole.name)) return send('It seems you already have the ' + newrole.name + ' role'); -// -// // Assuming all these factors succeed, add the role -// msg.member.addRole(newrole).then(send(msg.member + ' has been added to the ' + newrole.name + ' role!')); -// -// // Check if a baserole is actually set -// if (!rolelist.baserole) return; -// // Confirm that the role exists on the server and if not then be sure to send a nag message -// if (!baserole) return send('The base role of ' + rolelist.baserole + ' has been set in config but is missing from the server'); -// // Checks if the new role being added is the same as the baserole, then skips the messages below if this is the case. -// if (newrole == baserole) return; -// // Confirm if the user has the baserole already, including if it was added just now -// if (msg.member.roles.find(item => item.name === baserole.name)) return; -// // Add the base role and avoid spamming the user by only mentioning them in the previous message -// msg.member.addRole(baserole).then(send('We also added the base ' + rolelist.baserole + ' role for you!')); -// } -//}; -//exports.delrole = { -// usage: '', -// description: 'Deletes the specified role from your account', -// process: function(bot, msg, suffix) { -// // Provide shortened syntax for the sake of code cleanliness -// let send = msgTxt => msg.channel.send(msgTxt); -// // Checks if the user has messaged the bot via Direct Message -// if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.'); -// // Here in the bot, msg and suffix are available, this function can be async if needed. -// // Make sure to eliminate case sensitivity, do this here to only perform the sweep once. -// let oldrole = msg.guild.roles.find(role => role.name.toLowerCase() === suffix.toLowerCase()); -// let rolecmd = botconfig.prefix + 'roles'; -// // Checks if the user included a role in their message -// if (!suffix) return send('Please specify a role. Type ' + rolecmd + ' to see which you may remove yourself!'); -// // Checks if there is a matching role found on the server -// if (!oldrole) return send('The role specified `' + suffix + '` does not exist on this server!'); -// // Checks that the allowed roles against the matched role's name, since this eliminates case sensitivity issues -// if (!rolelist.allowedroles.includes(oldrole.name)) return send("That role isn't one you can remove yourself! If you need it removed, please ask a moderator!"); -// // Use the matched name to check against the member's existing roles -// if (!msg.member.roles.find(item => item.name === oldrole.name)) return send("It seems you don't actually have the " + oldrole.name + ' role! Mission accomplished!'); -// -// // Assuming all these factors succeed, add the role -// msg.member.removeRole(oldrole).then(send(msg.member + ' has been removed from the ' + oldrole.name + ' role!')); -// } -//}; -//exports.roles = { -// usage: '', -// description: 'displays roles you can give yourself', -// process: function(bot, msg, suffix) { -// let send = msgTxt => msg.channel.send(msgTxt); -// if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.'); -// else { -// // Here in the bot, msg and suffix are available, this function can be async if needed. -// send({ -// embed: { -// color: 3447003, -// title: 'Wunderbot', -// description: 'You have accessed the rolebot function of Wunderbot!', -// fields: [ -// { -// name: 'List of roles', -// value: buildRoleString(rolelist.allowedroles) + '`' + rolelist.baserole + '`', -// inline: false -// }, -// { -// name: 'How to add a role to yourself', -// value: '!addrole (role) - Adds a specified role to yourself.\n!addrole International would add the International role.', -// inline: false -// }, -// { -// name: 'How to remove a role from yourself', -// value: '!delrole (role) - Removed a specified role from yourself.\n!delrole International would remove the International role.', -// inline: false -// }, -// { -// name: 'NOTE', -// value: 'The LBRY-Curious role will be auto-added when you chose any of the available roles', -// inline: false -// } -// ], -// footer: { -// icon_url: msg.author.avatarURL, -// text: 'Requested by: ' + JSON.stringify(msg.author.username) -// } -// } -// }); -// } -// } -//}; -// -//function buildRoleString(roles) { -// let str = ''; -// for (let i = 0; i < roles.length; i++) { -// str += '`' + roles[i] + '`' + '\n'; -// } -// return str; -//} diff --git a/bot/modules/speech.js b/bot/modules/speech.js deleted file mode 100644 index 47ead69..0000000 --- a/bot/modules/speech.js +++ /dev/null @@ -1,240 +0,0 @@ -let request = require('request'); -let wget = require('wget'); -let config = require('config'); -let hasSpeechBotChannels = require('../helpers.js').hasSpeechBotChannels; -let inPrivate = require('../helpers.js').inPrivate; -let ChannelID = config.get('speechbot').mainchannel; -//debug output "true/false" outputs same error as slack message in console if set to true -//if set to false console will be left blank like normal -//some have more info on file details of error -let FullDebug = 'true'; -//outputs response from speech, very bulk reply -let ResponseDebug = 'false'; - -exports.commands = [ - 'speech' // command that is in this file, every command needs it own export as shown below -]; - -exports.speech = { - usage: '', - description: 'gets top claim from spee.ch, coming soon post to spee.ch', - process: function(bot, msg, suffix) { - if (!hasSpeechBotChannels(msg) && !inPrivate(msg)) { - msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to speech bot.'); - return; - } - - let command = '!speech'; - words = suffix - .trim() - .split(' ') - .filter(function(n) { - return n !== ''; - }); - let imagename = words[0]; - - //check if image name is help, if it is then do help message - if (imagename == 'help') { - doHelp(bot, msg, suffix); - return; - } else { - //check if imagename is defined if not do error - if (imagename === undefined) { - if (FullDebug === 'true') { - let message = '`no name provided`'; - console.log('no name provided'); - msg.channel.send(message); - doHelp(bot, msg, suffix); - return; - } else { - let message = '`no name provided`'; - msg.channel.send(message); - doHelp(bot, msg, suffix); - return; - } - } - - //set second word to url - let filepath = words[1]; - - //check if a url is provided if none do help message - if (filepath === undefined) { - if (FullDebug === 'true') { - let message = '`no url provided, fetching image from:`\n' + 'https://spee.ch/' + imagename; - console.log('no url provided'); - msg.channel.send(message); - return; - } else { - let message = '`no url provided, fetching image from:`\n' + 'https://spee.ch/' + imagename; - msg.channel.send(message); - return; - } - } - - //prepare url for other uses - //we will just set filepath to url to be safe - let url = filepath; - //parse first 4 letters of url should be http - let linkvalid = url.slice(0, 4); - - //check of url provided begins with http in not throw error and help message - if (linkvalid !== 'http') { - if (FullDebug === 'true') { - let message = '`error not a valid url, please start with http or https`'; - console.log('invalid url provided: ' + filepath); - msg.channel.send(message); - return; - } else { - let message = '`error not a valid url, please start with http or https`'; - msg.channel.send(message); - return; - } - } - - //function to check if url is an image - let isUriImage = function(uri) { - //make sure we remove any nasty GET params - uri = uri.split('?')[0]; - //moving on, split the uri into parts that had dots before them - let parts = uri.split('.'); - //get the last part ( should be the extension ) - let extension = parts[parts.length - 1]; - //define some image types to test against - let imageTypes = ['jpg', 'jpeg', 'tiff', 'png', 'gif', 'bmp']; - //check if the extension matches anything in the list. if it does set true if not set false - return imageTypes.indexOf(extension) !== -1; - }; - - //check if url is an image if its not throw error and help message - if (isUriImage(url) === false) { - if (FullDebug === 'true') { - let message = '`error not a valid image url, be sure the link includes a file type`'; - console.log('invalid url provided: ' + url); - msg.channel.send(message); - return; - } else { - let message = '`error not a valid image url, be sure the link includes a file type`'; - msg.channel.send(message); - return; - } - } - //set third word to nsfw, with it being an optional functionality - let eighteen = words[2]; - - //check is NSFW if yes or no sets proper value if none - if (eighteen === '' || eighteen === 'none' || eighteen === undefined || eighteen === null || eighteen === 'no' || eighteen === 'false' || eighteen === false || eighteen === 'n') { - eighteen = 'no'; - } else { - eighteen = 'yes'; - } - - //prepare url for wget - //parse the filename to use to save file - filepath = url.split('/').pop(); - //set proper directory for downloading image - let outputFile = 'speech-uploads/' + filepath; - //set download directory to current working directory - let dir = process.cwd(); - //set full path to directory for speech uploading - let fullpath = dir + '\\speech-uploads\\' + filepath; - - //download url via wget - let download = wget.download(url, outputFile); - //check if url is reachable if not throw error - download.on('error', function(err) { - if (FullDebug === 'true') { - console.log('error could not reach: ' + url + ' : ' + err); - let message = '`error url could not be reached`'; - msg.channel.send(message); - } else { - let message = '`error url could not be reached`'; - msg.channel.send(message); - } - }); - - download.on('end', output => { - //if no errors and file ready -> do the request - output && doSteps(bot, imagename, url, eighteen); - }); - } - - //send help message - function doHelp(bot, msg, suffix) { - msg.channel.send({ - embed: { - title: '', - description: - '**!speech ``** : *displays top claim on speech* \n\n\n' + - '**COMING SOON POSTING TO SPEECH** \n\n' + - '**!speech ` `** : *Uploads Image URL to Spee.ch* \n' + - '**NOTE : dont include spaces in name (NSFW is optional true/false, if left blank will default to false)** \n' + - 'EXAMPLE : `!speech my-image-name https://url/to/image.png false`', - color: 7976557, - author: { - name: 'Speech Bot Help', - icon_url: 'https://spee.ch/2/pinkylbryheart.png' - } - } - }); - } - - //send post request to speech - function doSteps(bot, imagename, url, eighteen) { - request.post( - //url to send post request - 'https://spee.ch/api/publish', - //json payload - { - json: { - name: imagename, - file: fullpath, - nsfw: eighteen - } - }, - //get response from server - function(error, response, body) { - //output response if ResponseDebug set to true - if (ResponseDebug === 'true') { - console.log(response); - console.log(error); - console.log(body.success); - console.log(body.message); - } - - //check speech response for file path error, if found throw internal error! - if (body.message === 'no files found in request') { - if (FullDebug === 'true') { - console.log('no file found: ' + fullpath); - let message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists'; - msg.channel.send(message); - return; - } else { - let message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists'; - msg.channel.send(message); - return; - } - } - - //check speech response for filename error, if found throw internal error! - if (body.message === 'no name field found in request') { - if (FullDebug === 'true') { - console.log('no name field found: ' + imagename); - let message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists'; - msg.channel.send(message); - return; - } else { - let message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists'; - msg.channel.send(message); - return; - } - } - - //if no errors post this message - let message = 'uploading... \n "name":"' + imagename + '",\n "URL": "' + url + '",\n "nsfw":"' + eighteen + '"\n to spee.ch'; - console.log('uploading... \n "name":"' + imagename + '",\n "file name": "' + filepath + '",\n "url":"' + url + '"\n "path":"' + fullpath + '"\n "nsfw": "' + eighteen + '"'); - msg.channel.send(message); - } - ); - } - } -};