From 0d38fdaed2892fe90bac9ebf3f6d8af4176cbdbb Mon Sep 17 00:00:00 2001 From: CBenni Date: Thu, 4 Jan 2018 21:47:26 +0100 Subject: [PATCH] Dont check emojis for all messages, only / commands --- index.js | 77 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/index.js b/index.js index b71180b..9a8eb31 100644 --- a/index.js +++ b/index.js @@ -198,7 +198,6 @@ function findEmoji(message) { const ext = avatarMatch[2]; avatarUrl = `${avatarMatch[1]}128`; } - console.log('Avatar url: ', avatarUrl); return { name: mentionedMember.displayName, id: mentionedMember.id, @@ -235,46 +234,48 @@ client.on('message', async message => { } } - const messageSplit = message.cleanContent.split(' '); - const emoji = findEmoji(message); - let result = null; - let count = 0; - try { - if (emoji) { - let { name } = emoji; - for (let i = 0; i < messageSplit.length && count < 4; ++i) { - commandParsed = /^([/\\])(\w+)\b/.exec(messageSplit[i]); - if (commandParsed) { - const [, direction, command] = commandParsed; - console.log('Got command ', direction, command, direction === '\\' ? 'flipped' : 'not flipped'); - if (templates[command]) { - count++; - name += command; - if (result === null) { - result = new ImageEx(emoji.url); - await result.loaded; // eslint-disable-line no-await-in-loop + if (message.cleanContent[0] === '/') { + const messageSplit = message.cleanContent.split(' '); + const emoji = findEmoji(message); + let result = null; + let count = 0; + try { + if (emoji) { + let { name } = emoji; + for (let i = 0; i < messageSplit.length && count < 4; ++i) { + commandParsed = /^([/\\])(\w+)\b/.exec(messageSplit[i]); + if (commandParsed) { + const [, direction, command] = commandParsed; + console.log('Got command ', direction, command, direction === '\\' ? 'flipped' : 'not flipped'); + if (templates[command]) { + count++; + name += command; + if (result === null) { + result = new ImageEx(emoji.url); + await result.loaded; // eslint-disable-line no-await-in-loop + } + const templateData = templates[command]; + all(templateData, template => { // eslint-disable-line no-loop-func + console.log('Drawing template', template); + result = render(template, result, null, direction === '\\'); + }); } - const templateData = templates[command]; - all(templateData, template => { // eslint-disable-line no-loop-func - console.log('Drawing template', template); - result = render(template, result, null, direction === '\\'); - }); - } - } else if (i === 0) return; - } - if (result) { - const attachment = await result.toBuffer(); - console.log('Render completed, data:', attachment); - const messageOptions = { - files: [ - { attachment, name: `${name}.${emoji.ext}` } - ] - }; - await message.channel.send('', messageOptions); + } else if (i === 0) return; + } + if (result) { + const attachment = await result.toBuffer(); + console.log('Render completed, data:', attachment); + const messageOptions = { + files: [ + { attachment, name: `${name}.${emoji.ext}` } + ] + }; + await message.channel.send('', messageOptions); + } } + } catch (err) { + console.error(err); } - } catch (err) { - console.error(err); } });