{"size": 2146, "ext": "js", "max_stars_repo_path": "commands/developer/reject.js", "max_stars_repo_name": "ItsCryptic/Arthur", "max_stars_repo_stars_event_min_datetime": "2017-09-02T04:09:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-05T04:27:07.000Z", "max_issues_repo_path": "commands/developer/reject.js", "max_issues_repo_name": "ItsCryptic/Arthur", "max_issues_repo_issues_event_min_datetime": "2018-01-08T00:42:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-13T07:22:42.000Z", "max_forks_repo_path": "commands/developer/reject.js", "max_forks_repo_name": "ItsCryptic/Arthur", "max_forks_repo_forks_event_min_datetime": "2018-04-07T21:00:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-27T13:02:29.000Z"}
{"max_stars_count": 61, "max_issues_count": 15, "max_forks_count": 27, "avg_line_length": 47.6888888889, "max_line_length": 226, "alphanum_fraction": 0.7041006524}
const { trello } = require('../misc/suggest');

exports.run = async (message, args, suffix) => {
	if (message.channel.id !== message.client.config.trello.channel) return message.channel.send('Wrong channel.');
	if (!args[0]) return message.channel.send('Please speciify which suggestion message to reject.');

	let suggestionMsg = await message.channel.messages.fetch(args[0]).catch(() => {});
	if (!suggestionMsg) return message.channel.send('Could not fetch message.');
	if (suggestionMsg.author.id !== message.client.user.id || !suggestionMsg.embeds[0] || !suggestionMsg.embeds[0].footer || !suggestionMsg.embeds[0].footer.text || !suggestionMsg.embeds[0].footer.text.startsWith('Suggested by'))
		return message.channel.send('Message is not a suggestion message.');

	let cardURLSplit = suggestionMsg.embeds[0].url.split('/');
	let cardID = cardURLSplit[cardURLSplit.length - 1];
	let splitText = suggestionMsg.embeds[0].footer.text.split(' | ');
	let suggesterID = splitText[splitText.length - 1];

	trello.updateCard(cardID, 'closed', true).catch(err => {
		message.channel.send('Card update failed, error logged');
		message.client.errorLog('Error updating trello card for reject command', err);
	}).then(() => {
		message.noDelete = true;

		let rejectionMessage = `Your suggestion of "${suggestionMsg.embeds[0].title}" has been rejected. `;
		if (args[1]) rejectionMessage += `Provided reason: ${suffix.slice(args[0].length + 1)}`;
		else rejectionMessage += 'No reason was provided.';
		rejectionMessage += '\nIf you\'d like to discuss this further, feel free to reply to this message.';

		suggestionMsg.embeds[0].color = 0xf56942;
		suggestionMsg.embeds[0].title = 'Rejected: ' + suggestionMsg.embeds[0].title;
		suggestionMsg.edit({ embed: suggestionMsg.embeds[0] }).catch(() => {});

		message.client.commands.get('send').run(message, [ suggesterID, 'aa'], suggesterID + ' ' + rejectionMessage, message.client).then(() => {
			message.channel.send('Suggestion rejected.');
		}).catch(() => {
			message.channel.send('Message send failed.');
		});
	});
};

exports.config = {
	enabled: true,
	permLevel: 9,
	category: 'developer'
};
