From d7330141a003a507d8ea6c443c9df11eefdc1334 Mon Sep 17 00:00:00 2001
From: "google-labs-jules[bot]"
<161369871+google-labs-jules[bot]@users.noreply.github.com>
Date: Tue, 7 Jul 2026 12:18:05 +0000
Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20string=20tokeniz?=
=?UTF-8?q?ation=20with=20regex=20match?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Replaces multiple intermediate object and array allocations created by `.trim().split(' ').filter(...)` chains with a single `.match(/\S+/g) || []` regular expression. Applied to all tipper modules and the main command parser loop in `bot.js`.
Co-authored-by: DerUntote <8378077+DerUntote@users.noreply.github.com>
---
.jules/bolt.md | 4 ++++
bot/bot.js | 4 ++--
bot/modules/dogeTipper.js | 7 +------
bot/modules/exampleTipper.js | 7 +------
bot/modules/ftcTipper.js | 7 +------
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 +------
11 files changed, 15 insertions(+), 56 deletions(-)
diff --git a/.jules/bolt.md b/.jules/bolt.md
index e79ba97..b7feea4 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)).
+
+## 2026-07-07 - Regex Match for String Tokenization
+**Learning:** Using `.match(/\S+/g) || []` to extract non-whitespace tokens from a string avoids intermediate array allocations and object creation compared to chaining `.trim().split(' ').filter(...)`.
+**Action:** Replaced `.trim().split(' ').filter(...)` and `.split(' ')` with `.match(/\S+/g) || []`.
diff --git a/bot/bot.js b/bot/bot.js
index da72836..439e2bf 100644
--- a/bot/bot.js
+++ b/bot/bot.js
@@ -153,13 +153,13 @@ function checkMessageForCommand(msg, isEdit) {
return;
});
}
- var cmdTxt = msg.content.split(' ')[0].substring(config.prefix.length);
+ var cmdTxt = (msg.content.match(/\S+/g) || [''])[0].substring(config.prefix.length); // ⚡ Bolt: Use Regex match over split for performance
var suffix = msg.content.substring(
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]; // ⚡ Bolt: Use Regex match over split for performance
suffix = msg.content.substring(
bot.user.mention().length + cmdTxt.length + config.prefix.length + 1
);
diff --git a/bot/modules/dogeTipper.js b/bot/modules/dogeTipper.js
index 54258df..c75ea1d 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 over split/filter for performance
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..0b4a003 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 over split/filter for performance
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..1788a3e 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 over split/filter for performance
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Feathercoin (FTC) Tipper**__\nTransaction Fees: **' +
diff --git a/bot/modules/lbcTipper.js b/bot/modules/lbcTipper.js
index 09ff576..6f2ffee 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 over split/filter for performance
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..bca1e80 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 over split/filter for performance
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..63f980c 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 over split/filter for performance
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..1dc6bda 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 over split/filter for performance
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..209bf44 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 over split/filter for performance
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..290b6a4 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 over split/filter for performance
subcommand = words.length >= 2 ? words[1] : 'help',
helpmsg =
'__**Vertical (VTL) Tipper**__\nTransaction Fees: **' +