Skip to content

Initial support for multiple words in roles #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions commands/create-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions commands/delete-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
53 changes: 30 additions & 23 deletions commands/edit-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ROLE> <HEX_COLOR>',
enabled: true,
name: 'edit-color',
aliases: [ 'edit' ],
description: 'Edits a role color.',
usage: 'edit-role <ROLE> <HEX_COLOR>',
};

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;
},
};
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"prefix": "kimbap ",
"ignorePrefixes": [ "pg" ]
}
}
4 changes: 2 additions & 2 deletions events/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,4 +29,4 @@ module.exports = async (client, message) => {
}
}
return;
};
};
80 changes: 40 additions & 40 deletions utils/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
archiveMedia,
};
16 changes: 8 additions & 8 deletions utils/Utils.js
Original file line number Diff line number Diff line change
@@ -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,
};
logAndMsg,
getRandomIndex,
errAndMsg,
};