diff --git a/commands/create-role.js b/commands/create-role.js index 6a31857..1232e38 100644 --- a/commands/create-role.js +++ b/commands/create-role.js @@ -21,14 +21,20 @@ module.exports = { Utils.errAndMsg(message.channel, 'Invalid arguments.'); } else { try { + let name = args[0]; + let color = args[1] + if (args.length > 2) { + name = args.slice(1, -1).reduce( (str, val) => str + ' ' + val, args[0]); + color = args[args.length - 1] + } const role = await guild.createRole({ - name: args[0], - color: args[1], + name: name, + color: color, }); - Utils.logAndMsg(message.channel, `Created new role with name ${role.name} and color ${role.color}`); + Utils.logAndMsg(message.channel, `Created new role with name \`${role.name}\` and color \`${role.color}\``); } catch (err) { console.error(err); - message.channel.send(`Couldn't create role ${args[0]} because: ${err}`); + message.channel.send(`Couldn't create role \`${args[0]}\` because: ${err}`); } } return; diff --git a/commands/delete-role.js b/commands/delete-role.js index 33552a7..b17f871 100644 --- a/commands/delete-role.js +++ b/commands/delete-role.js @@ -21,11 +21,16 @@ module.exports = { Utils.errAndMsg(message.channel, 'Invalid arguments.'); } else { try { - const deleted = await guild.roles.find(role => role.name === args[0]).delete(); - Utils.logAndMsg(message.channel, `Deleted role ${deleted.name}`); + let name = args[0]; + if (args.length > 1) { + name = args.slice(1).reduce( (str, val) => str + ' ' + val, args[0]); + } + + const deleted = await guild.roles.find(role => role.name === name).delete(); + Utils.logAndMsg(message.channel, `Deleted role \`${deleted.name}\``); } catch (err) { console.error(err); - message.channel.send(`Couldn't delete role ${args[0]} because: ${err}`); + message.channel.send(`Couldn't delete role \`${args[0]}\` because: ${err}`); } } return; diff --git a/commands/edit-role.js b/commands/edit-role.js index 0201831..885ef7f 100644 --- a/commands/edit-role.js +++ b/commands/edit-role.js @@ -3,32 +3,39 @@ const Utils = require('../utils/Utils.js'); const { HELP, HELP_SHORT } = require('../assets/flags.json'); const configuration = { - enabled: true, - name: 'edit-color', - aliases: [ 'edit' ], - description: 'Edits a role color.', - usage: 'edit-role ', + enabled: true, + name: 'edit-color', + aliases: [ 'edit' ], + description: 'Edits a role color.', + usage: 'edit-role ', }; module.exports = { - conf: configuration, + conf: configuration, - run: async (client, message, args) => { - const guild = message.guild; + run: async (client, message, args) => { + const guild = message.guild; - if (args[0] === HELP || args[0] === HELP_SHORT || args.length < 2 || !guild) { - helpEmbed(message, configuration); - Utils.errAndMsg(message.channel, 'Invalid arguments.'); - } else { - try { - const role = guild.roles.find(role => role.name === args[0]); - await role.setColor(args[1]); - Utils.logAndMsg(message.channel, `Updated role ${args[0]}'s color to ${role.color}`); - } catch (err) { - console.error(err); - message.channel.send(`Couldn't update role ${args[0]}'s color because: ${err}`); - } - } - return; - }, + if (args[0] === HELP || args[0] === HELP_SHORT || args.length < 2 || !guild) { + helpEmbed(message, configuration); + Utils.errAndMsg(message.channel, 'Invalid arguments.'); + } else { + try { + let name = args[0]; + let color = args[1] + if (args.length > 2) { + name = args.slice(1, -1).reduce( (str, val) => str + ' ' + val, args[0]); + color = args[args.length - 1] + } + + const role = guild.roles.find(role => role.name === name); + await role.setColor(color); + Utils.logAndMsg(message.channel, `Updated role \`${args[0]}\`'s color to \`${role.color}\``); + } catch (err) { + console.error(err); + message.channel.send(`Couldn't update role \`${args[0]}\`'s color because: ${err}`); + } + } + return; + }, }; diff --git a/config.json b/config.json index de2b982..86f4078 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { "prefix": "kimbap ", "ignorePrefixes": [ "pg" ] -} \ No newline at end of file +} diff --git a/events/message.js b/events/message.js index b2da861..a1b8762 100644 --- a/events/message.js +++ b/events/message.js @@ -12,7 +12,7 @@ module.exports = async (client, message) => { } else { const args = message.content.slice(client.config.prefix.length).trim().split(/ +/g); const command = args.shift().toLowerCase(); - console.log(args, command); + // console.log(args, command); let commandToRun = null; @@ -29,4 +29,4 @@ module.exports = async (client, message) => { } } return; -}; \ No newline at end of file +}; diff --git a/utils/Actions.js b/utils/Actions.js index 44ca5e9..5a03f08 100644 --- a/utils/Actions.js +++ b/utils/Actions.js @@ -2,47 +2,47 @@ const Attachment = require('discord.js').Attachment; const UrlValidator = require('./UrlValidator.js'); archiveMedia = (message) => { - console.log(message); - const guild = message.guild; - if (!guild) return; + // :wconsole.log(message); + const guild = message.guild; + if (!guild) return; - const embeds = message.embeds; - const attachments = message.attachments; - if (embeds) { - embeds.forEach((embed) => { - const ytMatch = UrlValidator.matchYTUrl(embed.url); - const igMatch = UrlValidator.matchIGUrl(embed.url); - const spMatch = UrlValidator.matchSpotifyUrl(embed.url); - const vlMatch = UrlValidator.matchVLiveUrl(embed.url); - if (ytMatch) { - const ytChannel = guild.channels.find(ch => ch.name === 'youtube-links'); - if (ytChannel) ytChannel.send(ytMatch[0]); - } else if (igMatch) { - const igChannel = guild.channels.find(ch => ch.name === 'instagram-links'); - if (igChannel) igChannel.send(igMatch[0]); - } else if (spMatch) { - const spChannel = guild.channels.find(ch => ch.name === 'spotify-links'); - if (spChannel) spChannel.send(spMatch[0]); - } else if (vlMatch) { - const vliveChannel = guild.channels.find(ch => ch.name === 'vlive-links'); - if (vliveChannel) vliveChannel.send(vlMatch[0]); - } else if (embed.type === 'link') { - const linkChannel = guild.channels.find(ch => ch.name === 'general-links'); - if (linkChannel) linkChannel.send(embed.url); - } else if (embed.type !== 'rich') { - const mediaChannel = guild.channels.find(ch => ch.name === 'media'); - if (mediaChannel) mediaChannel.send(embed.url); - } - }); - } - if (attachments) { - attachments.forEach((attachment) => { - const mediaChannel = guild.channels.find(ch => ch.name === 'attachments'); - if (mediaChannel) mediaChannel.send(new Attachment(attachment.url)); - }); - } + const embeds = message.embeds; + const attachments = message.attachments; + if (embeds) { + embeds.forEach((embed) => { + const ytMatch = UrlValidator.matchYTUrl(embed.url); + const igMatch = UrlValidator.matchIGUrl(embed.url); + const spMatch = UrlValidator.matchSpotifyUrl(embed.url); + const vlMatch = UrlValidator.matchVLiveUrl(embed.url); + if (ytMatch) { + const ytChannel = guild.channels.find(ch => ch.name === 'youtube-links'); + if (ytChannel) ytChannel.send(ytMatch[0]); + } else if (igMatch) { + const igChannel = guild.channels.find(ch => ch.name === 'instagram-links'); + if (igChannel) igChannel.send(igMatch[0]); + } else if (spMatch) { + const spChannel = guild.channels.find(ch => ch.name === 'spotify-links'); + if (spChannel) spChannel.send(spMatch[0]); + } else if (vlMatch) { + const vliveChannel = guild.channels.find(ch => ch.name === 'vlive-links'); + if (vliveChannel) vliveChannel.send(vlMatch[0]); + } else if (embed.type === 'link') { + const linkChannel = guild.channels.find(ch => ch.name === 'general-links'); + if (linkChannel) linkChannel.send(embed.url); + } else if (embed.type !== 'rich') { + const mediaChannel = guild.channels.find(ch => ch.name === 'media'); + if (mediaChannel) mediaChannel.send(embed.url); + } + }); + } + if (attachments) { + attachments.forEach((attachment) => { + const mediaChannel = guild.channels.find(ch => ch.name === 'attachments'); + if (mediaChannel) mediaChannel.send(new Attachment(attachment.url)); + }); + } }; module.exports = { - archiveMedia, -}; \ No newline at end of file + archiveMedia, +}; diff --git a/utils/Utils.js b/utils/Utils.js index 16612c4..5c99fe3 100644 --- a/utils/Utils.js +++ b/utils/Utils.js @@ -1,18 +1,18 @@ const errorPhrases = require('../assets/errorPhrases.json'); logAndMsg = (channel, msg) => { - console.log(msg); - channel.send(msg); + // console.log(msg); + channel.send(msg); }; getRandomIndex = (arr) => Math.floor(Math.random() * arr.length); errAndMsg = (channel, err) => { - console.error(err); - channel.send(`${errorPhrases[getRandomIndex(errorPhrases)]} ${err}`); + console.error(err); + channel.send(`${errorPhrases[getRandomIndex(errorPhrases)]} ${err}`); }; module.exports = { - logAndMsg, - getRandomIndex, - errAndMsg, -}; \ No newline at end of file + logAndMsg, + getRandomIndex, + errAndMsg, +};