From ad3417c82723758a3e9849d7bbd0b9e7c8c4d988 Mon Sep 17 00:00:00 2001 From: Miikka Virtanen Date: Thu, 18 May 2017 05:28:11 +0300 Subject: [PATCH] Add useNicknames config option to use mod nicknames in replies. Post log lists in chunks to avoid hitting the message length limit. --- src/index.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 11c7bb7..b4a9d93 100644 --- a/src/index.js +++ b/src/index.js @@ -226,7 +226,8 @@ function reply(msg, text, anonymous = false) { modUsername = (mainRole ? mainRole.name : 'Moderator'); logModUsername = `(Anonymous) (${msg.author.username}) ${mainRole ? mainRole.name : 'Moderator'}`; } else { - modUsername = (mainRole ? `(${mainRole.name}) ${msg.author.username}` : msg.author.username); + const name = (config.useNicknames ? msg.member.nick || msg.author.username : msg.author.username); + modUsername = (mainRole ? `(${mainRole.name}) ${name}` : name); logModUsername = modUsername; } @@ -390,7 +391,19 @@ bot.registerCommand('logs', (msg, args) => { return `\`${formattedDate}\`: <${info.url}>`; }).join('\n'); - msg.channel.createMessage(message); + // Send list of logs in chunks of 15 lines per message + const lines = message.split('\n'); + const chunks = []; + const chunkSize = 15; + + for (let i = 0; i < lines.length; i += chunkSize) { + chunks.push(lines.slice(i, i + chunkSize).join('\n')); + } + + let root = Promise.resolve(); + chunks.forEach(chunk => { + root = root.then(() => msg.channel.createMessage(chunk)); + }); }); }