diff --git a/.jules/bolt.md b/.jules/bolt.md
index e79ba97..ea4d6d7 100644
--- a/.jules/bolt.md
+++ b/.jules/bolt.md
@@ -1,3 +1,7 @@
## 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-18 - String tokenization optimization
+**Learning:** Found an inefficient string parsing pattern chaining `.trim().split(' ').filter(...)` in all Discord bot command message handlers, causing multiple intermediate array allocations per command.
+**Action:** Replaced the pattern with `msg.content.match(/\S+/g) || []` to extract tokens cleanly without creating intermediate filtered arrays. This improves command parsing performance in high-traffic scenarios.
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..35c0cdb 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: Use regex match to 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..add39ce 100644
--- a/bot/modules/exampleTipper.js
+++ b/bot/modules/exampleTipper.js
@@ -28,12 +28,7 @@ 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: Use regex match to 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..b790913 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: Use regex match to 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..e619f6d 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: Use regex match to 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..d909482 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: Use regex match to 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..845f346 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: Use regex match to 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..33dc319 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: Use regex match to 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..419b255 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: Use regex match to 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..42ec55c 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: Use regex match to avoid intermediate array allocations from split/filter
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Vertical (VTL) Tipper**__\nTransaction Fees: **' +