Dont check emojis for all messages, only / commands
This commit is contained in:
parent
56f1a5a952
commit
0d38fdaed2
1 changed files with 39 additions and 38 deletions
77
index.js
77
index.js
|
@ -198,7 +198,6 @@ function findEmoji(message) {
|
||||||
const ext = avatarMatch[2];
|
const ext = avatarMatch[2];
|
||||||
avatarUrl = `${avatarMatch[1]}128`;
|
avatarUrl = `${avatarMatch[1]}128`;
|
||||||
}
|
}
|
||||||
console.log('Avatar url: ', avatarUrl);
|
|
||||||
return {
|
return {
|
||||||
name: mentionedMember.displayName,
|
name: mentionedMember.displayName,
|
||||||
id: mentionedMember.id,
|
id: mentionedMember.id,
|
||||||
|
@ -235,46 +234,48 @@ client.on('message', async message => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageSplit = message.cleanContent.split(' ');
|
if (message.cleanContent[0] === '/') {
|
||||||
const emoji = findEmoji(message);
|
const messageSplit = message.cleanContent.split(' ');
|
||||||
let result = null;
|
const emoji = findEmoji(message);
|
||||||
let count = 0;
|
let result = null;
|
||||||
try {
|
let count = 0;
|
||||||
if (emoji) {
|
try {
|
||||||
let { name } = emoji;
|
if (emoji) {
|
||||||
for (let i = 0; i < messageSplit.length && count < 4; ++i) {
|
let { name } = emoji;
|
||||||
commandParsed = /^([/\\])(\w+)\b/.exec(messageSplit[i]);
|
for (let i = 0; i < messageSplit.length && count < 4; ++i) {
|
||||||
if (commandParsed) {
|
commandParsed = /^([/\\])(\w+)\b/.exec(messageSplit[i]);
|
||||||
const [, direction, command] = commandParsed;
|
if (commandParsed) {
|
||||||
console.log('Got command ', direction, command, direction === '\\' ? 'flipped' : 'not flipped');
|
const [, direction, command] = commandParsed;
|
||||||
if (templates[command]) {
|
console.log('Got command ', direction, command, direction === '\\' ? 'flipped' : 'not flipped');
|
||||||
count++;
|
if (templates[command]) {
|
||||||
name += command;
|
count++;
|
||||||
if (result === null) {
|
name += command;
|
||||||
result = new ImageEx(emoji.url);
|
if (result === null) {
|
||||||
await result.loaded; // eslint-disable-line no-await-in-loop
|
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];
|
} else if (i === 0) return;
|
||||||
all(templateData, template => { // eslint-disable-line no-loop-func
|
}
|
||||||
console.log('Drawing template', template);
|
if (result) {
|
||||||
result = render(template, result, null, direction === '\\');
|
const attachment = await result.toBuffer();
|
||||||
});
|
console.log('Render completed, data:', attachment);
|
||||||
}
|
const messageOptions = {
|
||||||
} else if (i === 0) return;
|
files: [
|
||||||
}
|
{ attachment, name: `${name}.${emoji.ext}` }
|
||||||
if (result) {
|
]
|
||||||
const attachment = await result.toBuffer();
|
};
|
||||||
console.log('Render completed, data:', attachment);
|
await message.channel.send('', messageOptions);
|
||||||
const messageOptions = {
|
}
|
||||||
files: [
|
|
||||||
{ attachment, name: `${name}.${emoji.ext}` }
|
|
||||||
]
|
|
||||||
};
|
|
||||||
await message.channel.send('', messageOptions);
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in a new issue