From a82d6cff820f945e870bc2ab28791bacda8e4af7 Mon Sep 17 00:00:00 2001 From: mudkipscience Date: Wed, 11 Mar 2020 21:46:13 +1100 Subject: [PATCH] Synced changes --- changes.txt | 5 ++++- src/commands/inspirobot.js | 2 +- src/commands/ship.js | 37 +++++++++++++++++++++++++++++++++++++ src/modules/functions.js | 16 ++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/commands/ship.js diff --git a/changes.txt b/changes.txt index e3ed03b..20d4a91 100644 --- a/changes.txt +++ b/changes.txt @@ -3,4 +3,7 @@ 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 \ No newline at end of file +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/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/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: {}};