From 8f61ca29ffc55833a3d6ff1a64d25780bf144981 Mon Sep 17 00:00:00 2001
From: "google-labs-jules[bot]"
<161369871+google-labs-jules[bot]@users.noreply.github.com>
Date: Mon, 15 Jun 2026 11:49:47 +0000
Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20token=20extracti?=
=?UTF-8?q?on=20to=20reduce=20array=20allocations?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In message parsing code, chained calls like `.trim().split(' ').filter(...)`
allocate multiple intermediate arrays and iterate over the data multiple times,
leading to O(N) operations.
Replaced this pattern with `.match(/\S+/g) || []` to perform a single-pass regex
match, avoiding intermediate allocations and improving performance when parsing commands.
Also replaced `msg.content.split(' ')[0]` with `(msg.content.match(/\S+/g) || [''])[0]`
in `bot/bot.js`.
Co-authored-by: DerUntote <8378077+DerUntote@users.noreply.github.com>
---
.jules/bolt.md | 3 +
bot/bot.js | 128 +++++++++++++++++------------------
bot/modules/bot-uptime.js | 20 +++---
bot/modules/dogeTipper.js | 7 +-
bot/modules/exampleTipper.js | 8 +--
bot/modules/ftcTipper.js | 7 +-
bot/modules/helpTipper.js | 32 ++++++---
bot/modules/lbcTipper.js | 7 +-
bot/modules/protonTipper.js | 7 +-
bot/modules/pxcTipper.js | 7 +-
bot/modules/rvnTipper.js | 7 +-
bot/modules/ufoTipper.js | 7 +-
bot/modules/vtlTipper.js | 7 +-
bot/plugins.js | 2 +-
14 files changed, 111 insertions(+), 138 deletions(-)
diff --git a/.jules/bolt.md b/.jules/bolt.md
index e79ba97..a1ffaeb 100644
--- a/.jules/bolt.md
+++ b/.jules/bolt.md
@@ -1,3 +1,6 @@
## 2024-05-17 - O(N) lookup optimizations for Discord.js
**Learning:** Found two O(N) operations in bot.js and module Tipper scripts when looking up members or guild count.
**Action:** Replaced `bot.guilds.array().length` with `bot.guilds.size` (O(1)) and `message.guild.members.find('id', recipient)` with `message.guild.members.get(recipient)` (O(1)).
+## 2024-05-17 - Efficient Token Extraction Pattern
+**Learning:** In string parsing, `msg.content.trim().split(' ').filter(...)` allocates intermediate arrays and requires O(N) operations, which is slower than using regex matching for non-whitespace characters.
+**Action:** Use `.match(/\S+/g) || []` for token extraction to avoid intermediate array allocations and improve parsing performance. Note: Use `(match || [''])[0]` to safely provide an empty string fallback when chaining methods like `.substring()`.
diff --git a/bot/bot.js b/bot/bot.js
index da72836..c129ccc 100644
--- a/bot/bot.js
+++ b/bot/bot.js
@@ -12,25 +12,27 @@ config = config.get('bot');
var aliases;
// check if any aliases are defined
try {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
aliases = require('./alias.json');
- console.log('[' + time + ' PST][' + pm2Name + '] ' + Object.keys(aliases).length + ' aliases Loaded!');
+ console.log(
+ '[' +
+ time +
+ ' PST][' +
+ pm2Name +
+ '] ' +
+ Object.keys(aliases).length +
+ ' aliases Loaded!',
+ );
} catch (e) {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
console.log('[' + time + ' PST][' + pm2Name + '] No aliases defined');
}
var commands = {};
var bot = new Discord.Client();
-bot.on('ready', function() {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+bot.on('ready', function () {
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
console.log(
'[' +
time +
@@ -40,21 +42,19 @@ bot.on('ready', function() {
bot.user.username +
'Logged in! Serving in ' +
bot.guilds.size + // ⚡ Bolt: O(1) property lookup vs O(N) array creation
- ' servers'
+ ' servers',
+ );
+ bot.channels.get(logChannel).send(
+ '[' +
+ time +
+ ' PST][' +
+ pm2Name +
+ '] ' +
+ bot.user.username +
+ 'Logged in! Serving in ' +
+ bot.guilds.size + // ⚡ Bolt: O(1) property lookup vs O(N) array creation
+ ' servers',
);
- bot.channels
- .get(logChannel)
- .send(
- '[' +
- time +
- ' PST][' +
- pm2Name +
- '] ' +
- bot.user.username +
- 'Logged in! Serving in ' +
- bot.guilds.size + // ⚡ Bolt: O(1) property lookup vs O(N) array creation
- ' servers'
- );
require('./plugins.js').init();
console.log(
'[' +
@@ -63,7 +63,7 @@ bot.on('ready', function() {
pm2Name +
'] type ' +
config.prefix +
- 'tiphelp in Discord for a commands list.'
+ 'tiphelp in Discord for a commands list.',
);
bot.channels
.get(logChannel)
@@ -74,10 +74,19 @@ bot.on('ready', function() {
pm2Name +
'] type ' +
config.prefix +
- 'tiphelp in Discord for a commands list.'
+ 'tiphelp in Discord for a commands list.',
);
bot.user.setActivity(config.prefix + 'Intialized!');
- var text = ['tiprvn', 'tipdoge', 'tiplbc', 'tipufo', 'tipproton', 'tippxc', 'tipftc', 'tiphelp'];
+ var text = [
+ 'tiprvn',
+ 'tipdoge',
+ 'tiplbc',
+ 'tipufo',
+ 'tipproton',
+ 'tippxc',
+ 'tipftc',
+ 'tiphelp',
+ ];
var counter = 0;
setInterval(change, 10000);
@@ -90,10 +99,8 @@ bot.on('ready', function() {
}
});
-process.on('uncaughtException', err => {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+process.on('uncaughtException', (err) => {
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
console.log('[' + time + ' PST][' + pm2Name + '] uncaughtException: ' + err);
bot.channels
.get(logChannel)
@@ -101,10 +108,8 @@ process.on('uncaughtException', err => {
process.exit(1); //exit node.js with an error
});
-process.on('unhandledRejection', err => {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+process.on('unhandledRejection', (err) => {
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
console.log('[' + time + ' PST][' + pm2Name + '] unhandledRejection: ' + err);
bot.channels
.get(logChannel)
@@ -112,18 +117,14 @@ process.on('unhandledRejection', err => {
process.exit(1); //exit node.js with an error
});
-bot.on('disconnected', function() {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+bot.on('disconnected', function () {
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
console.log('[' + time + ' PST][' + pm2Name + '] Disconnected!');
process.exit(1); //exit node.js with an error
});
-bot.on('error', function(error) {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+bot.on('error', function (error) {
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
console.log('[' + time + ' PST][' + pm2Name + '] error: ' + error);
process.exit(1); //exit node.js with an error
});
@@ -139,29 +140,32 @@ function checkMessageForCommand(msg, isEdit) {
) {
msg.author
.send('Please set your Discord Presence to Online to talk to the bot!')
- .catch(function(error) {
+ .catch(function (error) {
msg.channel
.send(
msg.author +
- ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members'
+ ', Please enable Direct Messages from server members to communicate fully with our bot, it is located in the user setting area under Privacy & Safety tab, select the option allow direct messages from server members',
)
.then(
msg.channel.send(
- 'Please set your Discord Presence to Online to talk to the Bot!'
- )
+ 'Please set your Discord Presence to Online to talk to the Bot!',
+ ),
);
return;
});
}
- var cmdTxt = msg.content.split(' ')[0].substring(config.prefix.length);
+ // ⚡ Bolt: Use regex match to avoid intermediate array allocation from split
+ var cmdTxt = (msg.content.match(/\S+/g) || [''])[0].substring(
+ config.prefix.length,
+ );
var suffix = msg.content.substring(
- cmdTxt.length + config.prefix.length + 1
+ cmdTxt.length + config.prefix.length + 1,
); //add one for the ! and one for the space
if (msg.isMentioned(bot.user)) {
try {
- cmdTxt = msg.content.split(' ')[1];
+ cmdTxt = (msg.content.match(/\S+/g) || [''])[1];
suffix = msg.content.substring(
- bot.user.mention().length + cmdTxt.length + config.prefix.length + 1
+ bot.user.mention().length + cmdTxt.length + config.prefix.length + 1,
);
} catch (e) {
//no command
@@ -182,7 +186,7 @@ function checkMessageForCommand(msg, isEdit) {
msg.content +
' from ' +
msg.author.username +
- ' as command'
+ ' as command',
);
try {
cmd.process(bot, msg, suffix, isEdit);
@@ -214,37 +218,33 @@ function checkMessageForCommand(msg, isEdit) {
}
}
-bot.on('message', msg => checkMessageForCommand(msg, false));
+bot.on('message', (msg) => checkMessageForCommand(msg, false));
-exports.addCommand = function(commandName, commandObject) {
+exports.addCommand = function (commandName, commandObject) {
try {
commands[commandName] = commandObject;
} catch (err) {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
console.log('[' + time + ' PST][' + pm2Name + '] Error addCommand: ' + err);
bot.channels
.get(logChannel)
.send('[' + time + ' PST][' + pm2Name + '] Error addCommand: ' + err);
}
};
-exports.addCustomFunc = function(customFunc) {
+exports.addCustomFunc = function (customFunc) {
try {
customFunc(bot);
} catch (err) {
- var time = moment()
- .tz('America/Los_Angeles')
- .format('MM-DD-YYYY hh:mm a');
+ var time = moment().tz('America/Los_Angeles').format('MM-DD-YYYY hh:mm a');
console.log(
- '[' + time + ' PST][' + pm2Name + '] Error addCustomFunc: ' + err
+ '[' + time + ' PST][' + pm2Name + '] Error addCustomFunc: ' + err,
);
bot.channels
.get(logChannel)
.send('[' + time + ' PST][' + pm2Name + '] Error addCustomFunc: ' + err);
}
};
-exports.commandCount = function() {
+exports.commandCount = function () {
return Object.keys(commands).length;
};
diff --git a/bot/modules/bot-uptime.js b/bot/modules/bot-uptime.js
index 7df747a..69a2f8a 100644
--- a/bot/modules/bot-uptime.js
+++ b/bot/modules/bot-uptime.js
@@ -6,20 +6,20 @@ exports.commands = ['uptime'];
exports.uptime = {
usage: '',
description: 'gets Uptime for Bot',
- process: function(bot, msg, suffix) {
+ process: function (bot, msg, suffix) {
if (suffix != pm2Name) {
return;
}
msg.channel.send(
'i have been Online for ' +
- Math.round(bot.uptime / (1000 * 60 * 60 * 24)) +
- ' days, ' +
- Math.round(bot.uptime / (1000 * 60 * 60)) +
- ' hours, ' +
- Math.round(bot.uptime / (1000 * 60)) % 60 +
- ' minutes, and ' +
- Math.round(bot.uptime / 1000) % 60 +
- ' seconds'
+ Math.round(bot.uptime / (1000 * 60 * 60 * 24)) +
+ ' days, ' +
+ Math.round(bot.uptime / (1000 * 60 * 60)) +
+ ' hours, ' +
+ (Math.round(bot.uptime / (1000 * 60)) % 60) +
+ ' minutes, and ' +
+ (Math.round(bot.uptime / 1000) % 60) +
+ ' seconds',
);
- }
+ },
};
diff --git a/bot/modules/dogeTipper.js b/bot/modules/dogeTipper.js
index 54258df..7c61e8b 100644
--- a/bot/modules/dogeTipper.js
+++ b/bot/modules/dogeTipper.js
@@ -19,12 +19,7 @@ exports.tipdoge = {
paytxfee,
process: async function (bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function (n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Dogecoin (DOGE) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/modules/exampleTipper.js b/bot/modules/exampleTipper.js
index 25be559..2c6a849 100644
--- a/bot/modules/exampleTipper.js
+++ b/bot/modules/exampleTipper.js
@@ -28,12 +28,8 @@ exports.tipltc = {
'__**Litecoin (LTC) Tipper**__\nTransaction Fees: **' + paytxfee + '**\n **!tipltc** : Displays This Message\n **!tipltc balance** : get your balance\n **!tipltc deposit** : get address for your deposits\n **!tipltc withdraw
** : withdraw coins to specified address\n **!tipltc <@user> ** :mention a user with @ and then the amount to tip them\n **!tipltc private ** : put private before Mentioning a user to tip them privately.\n\n has a default txfee of ' + paytxfee,
process: async function(bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function(n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
+
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Litecoin (LTC) Tipper**__\nTransaction Fees: **' + paytxfee + '**\n **!tipltc** : Displays This Message\n **!tipltc balance** : get your balance\n **!tipltc deposit** : get address for your deposits\n **!tipltc withdraw ** : withdraw coins to specified address\n **!tipltc <@user> ** :mention a user with @ and then the amount to tip them\n **!tipltc private ** : put private before Mentioning a user to tip them privately.\n\n **<> : Replace with appropriate value.**',
diff --git a/bot/modules/ftcTipper.js b/bot/modules/ftcTipper.js
index 22bb0b9..dddc1fc 100644
--- a/bot/modules/ftcTipper.js
+++ b/bot/modules/ftcTipper.js
@@ -19,12 +19,7 @@ exports.tipftc = {
paytxfee,
process: async function (bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function (n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Feathercoin (FTC) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/modules/helpTipper.js b/bot/modules/helpTipper.js
index 95041c9..f87ef49 100644
--- a/bot/modules/helpTipper.js
+++ b/bot/modules/helpTipper.js
@@ -11,27 +11,41 @@ exports.commands = ['tiphelp'];
exports.tiphelp = {
usage: '',
description: 'This commands has been changed to currency specific commands!',
- process: function(bot, message) {
+ process: function (bot, message) {
message.author.send(
- '__**Ravencoin (RVN) Tipper**__\nTransaction Fees: **' + ravenFee + '**\n **!tiprvn balance** : get your balance\n **!tiprvn deposit** : get address for your deposits\n **!tiprvn withdraw ** : withdraw coins to specified address\n **!tiprvn <@user> ** :mention a user with @ and then the amount to tip them\n **!tiprvn private ** : put private before Mentioning a user to tip them privately.\n'
+ '__**Ravencoin (RVN) Tipper**__\nTransaction Fees: **' +
+ ravenFee +
+ '**\n **!tiprvn balance** : get your balance\n **!tiprvn deposit** : get address for your deposits\n **!tiprvn withdraw ** : withdraw coins to specified address\n **!tiprvn <@user> ** :mention a user with @ and then the amount to tip them\n **!tiprvn private ** : put private before Mentioning a user to tip them privately.\n',
);
message.author.send(
- '__**Dogecoin (DOGE) Tipper**__\nTransaction Fees: **' + dogeFee + '**\n **!tipdoge balance** : get your balance\n **!tipdoge deposit** : get address for your deposits\n **!tipdoge withdraw ** : withdraw coins to specified address\n **!tipdoge <@user> ** :mention a user with @ and then the amount to tip them\n **!tipdoge private ** : put private before Mentioning a user to tip them privately.\n'
+ '__**Dogecoin (DOGE) Tipper**__\nTransaction Fees: **' +
+ dogeFee +
+ '**\n **!tipdoge balance** : get your balance\n **!tipdoge deposit** : get address for your deposits\n **!tipdoge withdraw ** : withdraw coins to specified address\n **!tipdoge <@user> ** :mention a user with @ and then the amount to tip them\n **!tipdoge private ** : put private before Mentioning a user to tip them privately.\n',
);
message.author.send(
- '__**LBRY Credit (LBC) Tipper**__\nTransaction Fees: **' + lbryFee + '**\n **!tiplbc balance** : get your balance\n **!tiplbc deposit** : get address for your deposits\n **!tiplbc withdraw ** : withdraw coins to specified address\n **!tiplbc <@user> ** :mention a user with @ and then the amount to tip them\n **!tiplbc private ** : put private before Mentioning a user to tip them privately.\n'
+ '__**LBRY Credit (LBC) Tipper**__\nTransaction Fees: **' +
+ lbryFee +
+ '**\n **!tiplbc balance** : get your balance\n **!tiplbc deposit** : get address for your deposits\n **!tiplbc withdraw ** : withdraw coins to specified address\n **!tiplbc <@user> ** :mention a user with @ and then the amount to tip them\n **!tiplbc private ** : put private before Mentioning a user to tip them privately.\n',
);
message.author.send(
- '__**Proton (PROTON) Tipper**__\nTransaction Fees: **' + protonFee + '**\n **!tipproton balance** : get your balance\n **!tipproton deposit** : get address for your deposits\n **!tipproton withdraw ** : withdraw coins to specified address\n **!tipproton <@user> ** :mention a user with @ and then the amount to tip them\n **!tipproton private ** : put private before Mentioning a user to tip them privately.\n'
+ '__**Proton (PROTON) Tipper**__\nTransaction Fees: **' +
+ protonFee +
+ '**\n **!tipproton balance** : get your balance\n **!tipproton deposit** : get address for your deposits\n **!tipproton withdraw ** : withdraw coins to specified address\n **!tipproton <@user> ** :mention a user with @ and then the amount to tip them\n **!tipproton private ** : put private before Mentioning a user to tip them privately.\n',
);
message.author.send(
- '__**Uniform Fiscal Object (UFO) Tipper**__\nTransaction Fees: **' + ufoFee + '**\n **!tipufo balance** : get your balance\n **!tipufo deposit** : get address for your deposits\n **!tipufo withdraw ** : withdraw coins to specified address\n **!tipufo <@user> ** :mention a user with @ and then the amount to tip them\n **!tipufo private ** : put private before Mentioning a user to tip them privately.\n'
+ '__**Uniform Fiscal Object (UFO) Tipper**__\nTransaction Fees: **' +
+ ufoFee +
+ '**\n **!tipufo balance** : get your balance\n **!tipufo deposit** : get address for your deposits\n **!tipufo withdraw ** : withdraw coins to specified address\n **!tipufo <@user> ** :mention a user with @ and then the amount to tip them\n **!tipufo private ** : put private before Mentioning a user to tip them privately.\n',
);
message.author.send(
- '__**Phoenixcoin (PXC) Tipper**__\nTransaction Fees: **' + phoenixFee + '**\n **!tippxc balance** : get your balance\n **!tippxc deposit** : get address for your deposits\n **!tippxc withdraw ** : withdraw coins to specified address\n **!tippxc <@user> ** :mention a user with @ and then the amount to tip them\n **!tippxc private ** : put private before Mentioning a user to tip them privately.\n'
+ '__**Phoenixcoin (PXC) Tipper**__\nTransaction Fees: **' +
+ phoenixFee +
+ '**\n **!tippxc balance** : get your balance\n **!tippxc deposit** : get address for your deposits\n **!tippxc withdraw ** : withdraw coins to specified address\n **!tippxc <@user> ** :mention a user with @ and then the amount to tip them\n **!tippxc private ** : put private before Mentioning a user to tip them privately.\n',
);
message.author.send(
- '__**Feathercoin (FTC) Tipper**__\nTransaction Fees: **' + featherFee + '**\n **!tipftc balance** : get your balance\n **!tipftc deposit** : get address for your deposits\n **!tipufo withdraw ** : withdraw coins to specified address\n **!tipftc <@user> ** :mention a user with @ and then the amount to tip them\n **!tipftc private ** : put private before Mentioning a user to tip them privately.\n\n **<> : Replace with appropriate value.**'
+ '__**Feathercoin (FTC) Tipper**__\nTransaction Fees: **' +
+ featherFee +
+ '**\n **!tipftc balance** : get your balance\n **!tipftc deposit** : get address for your deposits\n **!tipufo withdraw ** : withdraw coins to specified address\n **!tipftc <@user> ** :mention a user with @ and then the amount to tip them\n **!tipftc private ** : put private before Mentioning a user to tip them privately.\n\n **<> : Replace with appropriate value.**',
);
- }
+ },
};
diff --git a/bot/modules/lbcTipper.js b/bot/modules/lbcTipper.js
index 09ff576..75fe989 100644
--- a/bot/modules/lbcTipper.js
+++ b/bot/modules/lbcTipper.js
@@ -19,12 +19,7 @@ exports.tiplbc = {
paytxfee,
process: async function (bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function (n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**LBRY Credit (LBC) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/modules/protonTipper.js b/bot/modules/protonTipper.js
index 53da2cd..94f82f2 100644
--- a/bot/modules/protonTipper.js
+++ b/bot/modules/protonTipper.js
@@ -19,12 +19,7 @@ exports.tipproton = {
paytxfee,
process: async function (bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function (n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Proton (PROTON) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/modules/pxcTipper.js b/bot/modules/pxcTipper.js
index db95dc4..5d591da 100644
--- a/bot/modules/pxcTipper.js
+++ b/bot/modules/pxcTipper.js
@@ -19,12 +19,7 @@ exports.tippxc = {
paytxfee,
process: async function (bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function (n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Phoenixcoin (PXC) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/modules/rvnTipper.js b/bot/modules/rvnTipper.js
index 814abc4..3848217 100644
--- a/bot/modules/rvnTipper.js
+++ b/bot/modules/rvnTipper.js
@@ -19,12 +19,7 @@ exports.tiprvn = {
paytxfee,
process: async function (bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function (n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Ravencoin (RVN) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/modules/ufoTipper.js b/bot/modules/ufoTipper.js
index 74c1cd5..9b84366 100644
--- a/bot/modules/ufoTipper.js
+++ b/bot/modules/ufoTipper.js
@@ -19,12 +19,7 @@ exports.tipufo = {
paytxfee,
process: async function (bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function (n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Uniform Fiscal Object (UFO) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/modules/vtlTipper.js b/bot/modules/vtlTipper.js
index 040a3fa..f7e0ed4 100644
--- a/bot/modules/vtlTipper.js
+++ b/bot/modules/vtlTipper.js
@@ -19,12 +19,7 @@ exports.tipvtl = {
paytxfee,
process: async function (bot, msg, suffix) {
let tipper = msg.author.id.replace('!', ''),
- words = msg.content
- .trim()
- .split(' ')
- .filter(function (n) {
- return n !== '';
- }),
+ words = msg.content.match(/\S+/g) || [], // ⚡ Bolt: avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Vertical (VTL) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/plugins.js b/bot/plugins.js
index a314cd1..30bbf5d 100644
--- a/bot/plugins.js
+++ b/bot/plugins.js
@@ -44,6 +44,6 @@ function load_plugins() {
}
}
console.log(
- `Loaded ${dbot.commandCount()} chat commands and ${otherFunc} custom functions.`
+ `Loaded ${dbot.commandCount()} chat commands and ${otherFunc} custom functions.`,
);
}