mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-02 10:16:11 +00:00
fix: bot trigger matched against message body only, not sender name
Channel messages have the format "sender_name: body". The trigger was being searched across the whole string, so a nick containing the trigger word would fire a reply even with an unrelated message. Now the match skips past the ": " separator and only checks the message body. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
361af6a795
commit
4d08c130e9
@@ -40,10 +40,15 @@ void MyMesh::tryBotReplyChannel(uint8_t channel_idx, const char* text) {
|
|||||||
millis() - _bot_last_reply_ms > 10000UL))
|
millis() - _bot_last_reply_ms > 10000UL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Skip "sender_name: " prefix so the trigger is only matched against the message body.
|
||||||
|
const char* msg = text;
|
||||||
|
const char* sep = strstr(text, ": ");
|
||||||
|
if (sep) msg = sep + 2;
|
||||||
|
|
||||||
const char* tr = _prefs.bot_trigger;
|
const char* tr = _prefs.bot_trigger;
|
||||||
int tlen = strlen(tr);
|
int tlen = strlen(tr);
|
||||||
bool matched = false;
|
bool matched = false;
|
||||||
for (const char* t = text; *t && !matched; t++) {
|
for (const char* t = msg; *t && !matched; t++) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < tlen && tolower((uint8_t)t[i]) == tolower((uint8_t)tr[i])) i++;
|
while (i < tlen && tolower((uint8_t)t[i]) == tolower((uint8_t)tr[i])) i++;
|
||||||
if (i == tlen) matched = true;
|
if (i == tlen) matched = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user