From 853b934607249ead1887e94a34eba79d037fc7be Mon Sep 17 00:00:00 2001 From: Olly Nicholass Date: Fri, 15 Jan 2021 11:18:49 +0000 Subject: [PATCH] feat(*): Add trim helper function --- helpers.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/helpers.js b/helpers.js index 19acdcf..b432cdb 100644 --- a/helpers.js +++ b/helpers.js @@ -16,4 +16,18 @@ module.exports = { message.channel.send('There was a problem, sorry!'); } }, + // Trim a string to a specific character length + trim: function (Discord, logger, string, max) { + try { + if (string.length > max) { + return `${string.slice(0, max - 3)}...`; + } + else { + return string; + } + } catch (error) { + logger.error('Failed to trim selection', error); + message.channel.send('There was a problem, sorry!'); + } + } };