diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 23b221cc..9dd0e22a 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -272,7 +272,6 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no rd(&_prefs.bot_channel_enabled, sizeof(_prefs.bot_channel_enabled)); rd(&_prefs.bot_channel_idx, sizeof(_prefs.bot_channel_idx)); rd(_prefs.bot_trigger, sizeof(_prefs.bot_trigger)); - for (char* p = _prefs.bot_trigger; *p; p++) *p = (char)tolower((uint8_t)*p); rd(_prefs.bot_reply_dm, sizeof(_prefs.bot_reply_dm)); rd(_prefs.bot_reply_ch, sizeof(_prefs.bot_reply_ch)); rd(&_prefs.clock_hide_seconds, sizeof(_prefs.clock_hide_seconds)); diff --git a/examples/companion_radio/MyMeshBot.h b/examples/companion_radio/MyMeshBot.h index 1058b10c..9b6cabc5 100644 --- a/examples/companion_radio/MyMeshBot.h +++ b/examples/companion_radio/MyMeshBot.h @@ -8,13 +8,17 @@ void MyMesh::tryBotReplyDM(const ContactInfo& from, const char* text) { millis() - _bot_last_dm_reply_ms > 10000UL)) return; - // Lower-case the body once, then a single strstr — avoids O(n*m) tolower per offset. + // Lower-case both body and trigger for case-insensitive matching. char low[200]; size_t n = strlen(text); if (n >= sizeof(low)) n = sizeof(low) - 1; for (size_t i = 0; i < n; i++) low[i] = (char)tolower((uint8_t)text[i]); low[n] = '\0'; - if (!strstr(low, _prefs.bot_trigger)) return; + char low_trigger[sizeof(_prefs.bot_trigger)]; + size_t tlen = strnlen(_prefs.bot_trigger, sizeof(low_trigger) - 1); + for (size_t i = 0; i < tlen; i++) low_trigger[i] = (char)tolower((uint8_t)_prefs.bot_trigger[i]); + low_trigger[tlen] = '\0'; + if (!strstr(low, low_trigger)) return; uint32_t ts = getRTCClock()->getCurrentTime(); char expanded[200]; @@ -48,7 +52,11 @@ void MyMesh::tryBotReplyChannel(uint8_t channel_idx, const char* text) { if (n >= sizeof(low)) n = sizeof(low) - 1; for (size_t i = 0; i < n; i++) low[i] = (char)tolower((uint8_t)msg[i]); low[n] = '\0'; - if (!strstr(low, _prefs.bot_trigger)) return; + char low_trigger[sizeof(_prefs.bot_trigger)]; + size_t tlen = strnlen(_prefs.bot_trigger, sizeof(low_trigger) - 1); + for (size_t i = 0; i < tlen; i++) low_trigger[i] = (char)tolower((uint8_t)_prefs.bot_trigger[i]); + low_trigger[tlen] = '\0'; + if (!strstr(low, low_trigger)) return; ChannelDetails ch; if (!getChannel(channel_idx, ch)) return; diff --git a/examples/companion_radio/ui-new/BotScreen.h b/examples/companion_radio/ui-new/BotScreen.h index 2ddc6074..b581a40c 100644 --- a/examples/companion_radio/ui-new/BotScreen.h +++ b/examples/companion_radio/ui-new/BotScreen.h @@ -114,7 +114,6 @@ public: if (_kb_field == 2) { strncpy(_prefs->bot_trigger, _kb->buf, sizeof(_prefs->bot_trigger) - 1); _prefs->bot_trigger[sizeof(_prefs->bot_trigger) - 1] = '\0'; - for (char* p = _prefs->bot_trigger; *p; p++) *p = (char)tolower((uint8_t)*p); } else if (_kb_field == 3) { strncpy(_prefs->bot_reply_dm, _kb->buf, sizeof(_prefs->bot_reply_dm) - 1); _prefs->bot_reply_dm[sizeof(_prefs->bot_reply_dm) - 1] = '\0';