From 5d8a81523f658d8fab2d8f1e8044cbb8d9e97831 Mon Sep 17 00:00:00 2001 From: MrTech999 <48654513+MrTech999@users.noreply.github.com> Date: Wed, 11 Mar 2020 20:47:06 +0000 Subject: [PATCH] Added yodish. --- changes.txt | 8 ++++++++ index.js | 28 +++++++++++++++------------- src/commands/catfact.js | 8 +++++++- src/commands/dogfact.js | 8 +++++++- src/commands/help.js | 21 +++++++++++++-------- src/commands/inspirobot.js | 2 +- src/commands/ship.js | 37 +++++++++++++++++++++++++++++++++++++ src/commands/userinfo.js | 7 ------- src/commands/yoda.js | 31 +++++++++++++++++++++++++++++++ src/modules/functions.js | 16 ++++++++++++++++ version.json | 2 +- 11 files changed, 136 insertions(+), 32 deletions(-) create mode 100644 src/commands/ship.js create mode 100644 src/commands/yoda.js diff --git a/changes.txt b/changes.txt index daa5b88..f7f1849 100644 --- a/changes.txt +++ b/changes.txt @@ -1,2 +1,10 @@ +Added a yodish command (terry) Links to avatars now lead to the original file size Bots now get a bot badge in the userinfo command +Added dogfact and catfact command (terry) +index.js now has better logging of when things fail to load/initialize (terry) +added `dice`, rolls a 6 sided die (terry) +Help command changed, the amount of commands in each category and overall is now displayed +added `inspire` as an alias for inspirobot +ship command +added find by mention to functions \ No newline at end of file diff --git a/index.js b/index.js index 6adb8b7..4e535ee 100644 --- a/index.js +++ b/index.js @@ -9,35 +9,35 @@ const client = new Discord.Client(); try { client.config = require('./config'); } catch (err) { - console.log('Could not load config.js. \n', err); + console.log('Could not load config.js: \n', err); process.exit(); } try{ client.version = require('./version.json'); } catch (err) { - console.log('Could not load version.json. \n', err); + console.log('Could not load version.json: \n', err); process.exit(); } try{ client.logger = require('./src/modules/Logger'); } catch (err) { - console.log('Could not load Logger.js. \n', err); + console.log('Could not load Logger.js: \n', err); process.exit(); } try{ require("./src/modules/functions")(client); } catch (err) { - console.log('Could not load functions.js. \n', err); + console.log('Could not load functions.js: \n', err); process.exit(); } try{ client.logger.setClient(client); } catch (err) { - console.log('Logger failed to initialize. \n', err); + console.log('Logger failed to initialize: \n', err); process.exit(1); } @@ -45,34 +45,36 @@ if(process.env['USER'] != 'container') { client.devmode = true; } else { client.devmode = false; - const dblapi = new DBL(client.config.dblkey, client); + if(client.config.dblkey.length == 0) { + const dblapi = new DBL(client.config.dblkey, client); + } } try{ client.commands = new Enmap(); } catch (err) { - console.log('Failed to create the commands map. \n', err); + console.log('Failed to create the commands database: \n', err); process.exit(); } try{ client.aliases = new Enmap(); } catch (err) { - console.log('Failed to create the aliases map. \n', err); + console.log('Failed to create the aliases database: \n', err); process.exit(); } try{ client.settings = new Enmap({name: 'settings'}); } catch (err) { - console.log('Failed to initialize the settings database. \n', err); + console.log('Failed to initialize the settings database: \n', err); process.exit(); } try{ client.blacklist = new Enmap({name: 'blacklist'}); } catch (err) { - console.log('Failed to initialize the blacklist database. \n', err); + console.log('Failed to initialize the blacklist database: \n', err); process.exit(1); } @@ -108,7 +110,7 @@ const init = async () => { client.levelCache[thisLevel.name] = thisLevel.level; }; } catch (err) { - console.log('Level cache failed to initialize. \n', err); + console.log('Level cache failed to initialize: \n', err); process.exit(); } @@ -119,12 +121,12 @@ const init = async () => { client.login(client.config.token); }; } catch (err) { - console.log('Unable to login to Discord. \n', err); + console.log('Could not login to Discord: \n', err); process.exit(1); } }; init(); } catch (err) { - console.log('Initialization failed. \n', err); + console.log('Initialization failed: \n', err); process.exit(1); } diff --git a/src/commands/catfact.js b/src/commands/catfact.js index 4944b43..8beb770 100644 --- a/src/commands/catfact.js +++ b/src/commands/catfact.js @@ -1,10 +1,16 @@ const request = require("request"); exports.run = async (bot, message, args) => { + message.channel.startTyping(); + try{ request({ uri: "https://catfact.ninja/facts", json: true }, (error, response, body) => { - if (error) throw new Error(error); message.channel.send(`**Did you know?**\n ${body.data[0].fact}`); + message.channel.startTyping(); }); +} catch(err) { + message.channel.send(`<:error:466995152976871434> API error: ${err}`); + message.channel.stopTyping(); +}; }; exports.conf = { diff --git a/src/commands/dogfact.js b/src/commands/dogfact.js index dc6bf7c..cd89858 100644 --- a/src/commands/dogfact.js +++ b/src/commands/dogfact.js @@ -1,10 +1,16 @@ const request = require("request"); exports.run = async (bot, message, args) => { + message.channel.startTyping(); + try{ request({ uri: "https://dog-api.kinduff.com/api/facts", json: true }, (error, response, body) => { - if (error) throw new Error(error); + message.channel.stopTyping(); message.channel.send(`**Did you know?**\n ${body.facts[0]}`); }); +} catch(err) { + message.channel.send(`<:error:466995152976871434> API error: ${err}`); + message.channel.stopTyping(); +}; }; exports.conf = { diff --git a/src/commands/help.js b/src/commands/help.js index 9ccb578..beeda6d 100644 --- a/src/commands/help.js +++ b/src/commands/help.js @@ -4,6 +4,7 @@ exports.run = (client, message, args, level) => { var ran = false; var output = ""; + var commands = 0; var prefix; var currentCategory; @@ -14,7 +15,7 @@ exports.run = (client, message, args, level) => { }; if(!args[0]) { - embed.setTitle("Command list"); + embed.setTitle(`Commands [${client.commands.size}]`); embed.setDescription(`⁣For more information on a specific command use \`${prefix}help \`\nFor the full command list use \`${prefix}help all\`\n`); const myCommands = message.guild ? client.commands.filter( @@ -37,16 +38,18 @@ exports.run = (client, message, args, level) => { const cat = c.help.category.toProperCase(); if (currentCategory !== cat) { if(ran == true) { - embed.addField(currentCategory + ":", output.slice(0, -6)) + embed.addField(currentCategory + ` [${commands}]`, output.slice(0, -2)) output = ""; + commands = 0; } currentCategory = cat; ran = true } - output += `\`${prefix}${c.help.name}\`**,** `; + output += `\`${prefix}${c.help.name}\`, `; + commands = commands + 1; }); - embed.addField(currentCategory + ":", output.slice(0, -6)); + embed.addField(currentCategory + ` [${commands}]`, output.slice(0, -2)); embed.addField( "Invite me", @@ -65,7 +68,7 @@ exports.run = (client, message, args, level) => { }; if(args[0].toLowerCase() == "all") { - embed.setTitle("Command list"); + embed.setTitle(`Commands [${client.commands.size}]`); embed.setDescription(`⁣For more information on a specific command use \`${prefix}help \`\nFor the full command list use \`${prefix}help all\`\n`); const myCommands = client.commands @@ -84,16 +87,18 @@ exports.run = (client, message, args, level) => { const cat = c.help.category.toProperCase(); if (currentCategory !== cat) { if(ran == true) { - embed.addField(currentCategory + ":", output.slice(0, -6)) + embed.addField(currentCategory + ` [${commands}]`, output.slice(0, -2)) output = ""; + commands = 0; } currentCategory = cat; ran = true } - output += `\`${prefix}${c.help.name}\`**,** `; + output += `\`${prefix}${c.help.name}\`, `; + commands = commands + 1; }); - embed.addField(currentCategory + ":", output.slice(0, -6)); + embed.addField(currentCategory + ` [${commands}]`, output.slice(0, -2)); embed.addField( "Invite me", diff --git a/src/commands/inspirobot.js b/src/commands/inspirobot.js index 6a26ee7..5ba4e0a 100644 --- a/src/commands/inspirobot.js +++ b/src/commands/inspirobot.js @@ -20,7 +20,7 @@ exports.run = async (client, message) => { exports.conf = { enabled: true, guildOnly: false, - aliases: [], + aliases: ["inspire"], permLevel: "User", requiredPerms: [] }; diff --git a/src/commands/ship.js b/src/commands/ship.js new file mode 100644 index 0000000..cd187b9 --- /dev/null +++ b/src/commands/ship.js @@ -0,0 +1,37 @@ +const request = require('request') +exports.run = async (client, message, args) => { + message.channel.startTyping(); + + var user = client.getUserFromMention(args[0]) + var user2 = client.getUserFromMention(args[1]) + + var secondLength = Math.floor(user2.username.length / 2); + + var first = user.username.substr(0, user.username.length / 2) + var second = user2.username.substr(secondLength, user2.username.length / 2) + + try { + var attachment = new Discord.MessageAttachment(`https://api.alexflipnote.dev/ship?user=${user.avatarURL({format: "png"})}&user2=${user2.avatarURL({format: "png"})}`) + message.channel.send(`Your ship name is **${first+second}!**`, attachment) + message.channel.stopTyping(); + } catch(err) { + message.channel.send(`<:error:466995152976871434> API error: ${err}`); + message.channel.stopTyping(); + }; +}; + +exports.conf = { + enabled: true, + guildOnly: false, + aliases: [], + permLevel: "User", + requiredPerms: [] +}; + +exports.help = { + name: "ship", + category: "Fun", + description: "Ship two people together <3", + usage: "ship name name2" +}; + diff --git a/src/commands/userinfo.js b/src/commands/userinfo.js index f84b40a..8d7008b 100644 --- a/src/commands/userinfo.js +++ b/src/commands/userinfo.js @@ -50,13 +50,6 @@ exports.run = (client, message, args) => { if(badges.length > 0) { badges += "\n" } - - createdTimestamp = user.user.createdTimestamp; - var date = new Date(createdTimestamp * 1000); - var hours = date.getHours(); - var minutes = "0" + date.getMinutes(); - var seconds = "o" + date.getSeconds(); - console.log(date) user.roles.cache.forEach((role) => { roles = roles + role.name + "`, `" diff --git a/src/commands/yoda.js b/src/commands/yoda.js new file mode 100644 index 0000000..aae6af0 --- /dev/null +++ b/src/commands/yoda.js @@ -0,0 +1,31 @@ +const request = require('request') +exports.run = async (client, message, args) => { + const speech = args.join(' '); + if (!args[0]) { + return message.channel.send(`<:error:466995152976871434> Please include text for me to convert to yodish. Yes.`) + } + try { + const { text } = request({ uri: `http://yoda-api.appspot.com/api/v1/yodish?text=${encodeURIComponent(speech.toLowerCase())}`, json: true }, (error, response, body) => { + message.channel.send(JSON.parse(text).yodish) + }); + } catch(err) { + message.channel.send(`<:error:466995152976871434> API error: ${err}`); + message.channel.stopTyping(); + } + +} + +exports.conf = { + enabled: true, + guildOnly: false, + aliases: ["yoda","yodasay"], + permLevel: "User", + requiredPerms: [] + }; + + exports.help = { + name: "yodish", + category: "Fun", + description: "Turns any text you input into yodish. Yes.", + usage: "yodish " + }; \ No newline at end of file diff --git a/src/modules/functions.js b/src/modules/functions.js index 85ec48d..98cf223 100644 --- a/src/modules/functions.js +++ b/src/modules/functions.js @@ -133,6 +133,22 @@ module.exports = client => { return a; }; + // USER OBJECT FROM MENTION + client.getUserFromMention = mention => { + if (!mention) return; + + if (mention.startsWith('<@') && mention.endsWith('>')) { + mention = mention.slice(2, -1); + + if (mention.startsWith('!')) { + mention = mention.slice(1); + } + + return client.users.cache.get(mention); + } + } + + // MUSIC client.music = {guilds: {}}; diff --git a/version.json b/version.json index b6a4488..3e289f1 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "number": "1.1.0", + "number": "1.2.0", "changelog": "**1.1.0 CHANGELOG:**\n> • Added `~softban`, bans and unbans a user to clear messages\n> • Added `~emoji`, enlarges custom emojis\n> • Added `~inspirobot`, generates an inspirational quote\n> • `~serverinfo` has been changed to be more consistent, and also now displays boosts and if the server is partnered and stuff\n> • `~userinfo` has been changed to be more consistent, also added some stuff\n> • `~about` has been changed, added a thumbnail and removed the description\n> • `~colour` has been changed, it can now generate colours from text\n> • `~hackban` no longer has its own embed\n> • `~eval` now logs to hastebin if output is too large\n> • role names are no longer case sensitive\n> • `~echo` renamed `~say`\n> • Users with the ADMINISTRATOR permission now automatically recieve woomy admin\n> • Fixed `~flip`, `~purge`, `~bohemian_rhapsody` and `~creeper`\n> • Guild join/leave messages no longer include the guild name\n> • Some emojis have been changed\n> • Woomy now supports discord.js v12\n> • Files have been restructured\n> • Logger now logs error stack\n> • Restart now exits with code 0" }