Skip to content

Commit da7db84

Browse files
authored
Merge pull request #59 from agessaman/dev
Minor release fixes. Fix logic in multitest command to avoid having a subsequent request block both test requests. Fixed issue with per-user rate limit that prevented second message responses from commands from being sent.
2 parents 7745499 + 1b5a3db commit da7db84

File tree

11 files changed

+65
-34
lines changed

11 files changed

+65
-34
lines changed

config.ini.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ startup_advert = false
124124
# device: Device handles auto-addition using standard auto-discovery mode, bot manages contact list capacity (purge old contacts when near limits)
125125
# bot: Bot automatically adds new companion contacts to device, bot manages contact list capacity (purge old contacts when near limits)
126126
# false: Manual mode - no automatic actions, use !repeater commands to manage contacts (default)
127-
auto_manage_contacts = false
127+
auto_manage_contacts = bot
128128

129129
# Database path for main bot database
130130
# Default: meshcore_bot.db

modules/commands/airplanes_command.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,11 @@ async def _send_split_response(self, message: MeshMessage, response: str, max_le
786786
if len(current_message) + len(line) + 1 > max_length: # +1 for newline
787787
# Send current message and start new one
788788
if current_message:
789-
await self.send_response(message, current_message.rstrip())
789+
# Per-user rate limit applies only to first message (trigger); skip for continuations
790+
await self.send_response(
791+
message, current_message.rstrip(),
792+
skip_user_rate_limit=(message_count > 0)
793+
)
790794
await asyncio.sleep(2.0) # Delay between messages
791795
message_count += 1
792796

@@ -799,6 +803,6 @@ async def _send_split_response(self, message: MeshMessage, response: str, max_le
799803
else:
800804
current_message = line
801805

802-
# Send the last message if there's content
806+
# Send the last message if there's content (continuation; skip per-user rate limit)
803807
if current_message:
804-
await self.send_response(message, current_message)
808+
await self.send_response(message, current_message, skip_user_rate_limit=True)

modules/commands/alternatives/wx_international.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,11 @@ async def _send_multiday_forecast(self, message: MeshMessage, forecast_text: str
11781178
if self._count_display_width(test_message) > max_length:
11791179
# Send current message and start new one
11801180
if current_message:
1181-
await self.send_response(message, current_message)
1181+
# Per-user rate limit applies only to first message (trigger); skip for continuations
1182+
await self.send_response(
1183+
message, current_message,
1184+
skip_user_rate_limit=(message_count > 0)
1185+
)
11821186
message_count += 1
11831187
# Wait between messages (same as other commands)
11841188
if i < len(lines):
@@ -1187,7 +1191,10 @@ async def _send_multiday_forecast(self, message: MeshMessage, forecast_text: str
11871191
current_message = line
11881192
else:
11891193
# Single line is too long, send it anyway (will be truncated by bot)
1190-
await self.send_response(message, line)
1194+
await self.send_response(
1195+
message, line,
1196+
skip_user_rate_limit=(message_count > 0)
1197+
)
11911198
message_count += 1
11921199
if i < len(lines) - 1:
11931200
await asyncio.sleep(2.0)
@@ -1199,9 +1206,9 @@ async def _send_multiday_forecast(self, message: MeshMessage, forecast_text: str
11991206
else:
12001207
current_message = line
12011208

1202-
# Send the last message if there's content
1209+
# Send the last message if there's content (continuation; skip per-user rate limit)
12031210
if current_message:
1204-
await self.send_response(message, current_message)
1211+
await self.send_response(message, current_message, skip_user_rate_limit=True)
12051212

12061213
def _degrees_to_direction(self, degrees: float) -> str:
12071214
"""Convert wind direction in degrees to compass direction with emoji.

modules/commands/channels_command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ async def _send_multiple_messages(self, message: MeshMessage, messages: list) ->
446446
if i > 0:
447447
# Small delay between messages to prevent overwhelming the network
448448
await asyncio.sleep(0.5)
449-
await self.send_response(message, msg_content)
449+
# Per-user rate limit applies only to first message (trigger); skip for continuations
450+
await self.send_response(message, msg_content, skip_user_rate_limit=(i > 0))
450451

451452
def _parse_config_channels(self):
452453
"""Parse all channels from config, returning a generator of (name, description) tuples.

modules/commands/dadjoke_command.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,10 @@ async def send_dad_joke_with_length_handling(self, message: MeshMessage, joke_da
218218
parts = self.split_dad_joke(joke_text)
219219

220220
if len(parts) == 2 and len(parts[0]) <= 130 and len(parts[1]) <= 130:
221-
# Can be split into two messages
221+
# Can be split into two messages (per-user rate limit applies only to first)
222222
await self.send_response(message, parts[0])
223223
# Use conservative delay to avoid rate limiting (same as weather command)
224-
await asyncio.sleep(2.0)
225-
await self.send_response(message, parts[1])
224+
await self.send_response(message, parts[1], skip_user_rate_limit=True)
226225
else:
227226
# Cannot be split properly, send as single message (user will see truncation)
228227
await self.send_response(message, joke_text)

modules/commands/joke_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,11 @@ async def send_joke_with_length_handling(self, message: MeshMessage, joke_data:
304304
parts = self.split_joke(joke_text)
305305

306306
if len(parts) == 2 and len(parts[0]) <= 130 and len(parts[1]) <= 130:
307-
# Can be split into two messages
307+
# Can be split into two messages (per-user rate limit applies only to first)
308308
await self.send_response(message, parts[0])
309309
# Use conservative delay to avoid rate limiting (same as weather command)
310310
await asyncio.sleep(2.0)
311-
await self.send_response(message, parts[1])
311+
await self.send_response(message, parts[1], skip_user_rate_limit=True)
312312
else:
313313
# Cannot be split properly, send as single message (user will see truncation)
314314
await self.send_response(message, joke_text)

modules/commands/multitest_command.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,8 @@ async def execute(self, message: MeshMessage) -> bool:
353353
existing_session = self._active_sessions[user_id]
354354
elapsed = time.time() - existing_session.listening_start_time
355355
if elapsed < existing_session.listening_duration:
356-
# User already has an active session, reject this one
357-
remaining = existing_session.listening_duration - elapsed
358-
response = f"Multitest already in progress. Please wait {remaining:.1f} seconds."
359-
await self.send_response(message, response)
356+
# User already has an active session - silently ignore second Mt
357+
# so the first session can complete and send its response
360358
return True
361359

362360
# Record execution time BEFORE starting async work to prevent race conditions

modules/commands/path_command.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,11 @@ async def _send_path_response(self, message: MeshMessage, response: str):
16611661
# Add ellipsis on new line to end of continued message (if not the last message)
16621662
if i < len(lines):
16631663
current_message += self.translate('commands.path.continuation_end')
1664-
await self.send_response(message, current_message.rstrip())
1664+
# Per-user rate limit applies only to first message (trigger); skip for continuations
1665+
await self.send_response(
1666+
message, current_message.rstrip(),
1667+
skip_user_rate_limit=(message_count > 0)
1668+
)
16651669
await asyncio.sleep(3.0) # Delay between messages (same as other commands)
16661670
message_count += 1
16671671

@@ -1677,9 +1681,9 @@ async def _send_path_response(self, message: MeshMessage, response: str):
16771681
else:
16781682
current_message = line
16791683

1680-
# Send the last message if there's content
1684+
# Send the last message if there's content (continuation; skip per-user rate limit)
16811685
if current_message:
1682-
await self.send_response(message, current_message)
1686+
await self.send_response(message, current_message, skip_user_rate_limit=True)
16831687

16841688
async def _extract_path_from_recent_messages(self) -> str:
16851689
"""Extract path from the current message's path information (same as test command)"""

modules/commands/prefix_command.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,9 @@ async def _send_prefix_response(self, message: MeshMessage, response: str) -> No
13691369
if len(response) <= max_length:
13701370
# Single message is fine
13711371
await self.send_response(message, response)
1372+
return
13721373
else:
1374+
# Multi-message: per-user rate limit applies only to the first message (the trigger)
13731375
# Split into multiple messages for over-the-air transmission
13741376
# But keep the full response in last_response for web viewer
13751377
lines = response.split('\n')
@@ -1433,7 +1435,9 @@ async def _send_prefix_response(self, message: MeshMessage, response: str) -> No
14331435
# Send current message and start new one
14341436
# Add ellipsis on new line to end of continued message
14351437
current_message += continuation_end
1436-
await self.send_response(message, current_message.rstrip())
1438+
# Per-user rate limit applies only to the first message (trigger); skip for continuations
1439+
skip_user_limit = message_count > 0
1440+
await self.send_response(message, current_message.rstrip(), skip_user_rate_limit=skip_user_limit)
14371441
await asyncio.sleep(3.0) # Delay between messages (same as other commands)
14381442
message_count += 1
14391443
lines_in_current = 0
@@ -1449,9 +1453,9 @@ async def _send_prefix_response(self, message: MeshMessage, response: str) -> No
14491453
current_message = line
14501454
lines_in_current += 1
14511455

1452-
# Send the last message if there's content
1456+
# Send the last message if there's content (continuation; skip per-user rate limit)
14531457
if current_message:
1454-
await self.send_response(message, current_message)
1458+
await self.send_response(message, current_message, skip_user_rate_limit=True)
14551459

14561460
async def __aenter__(self):
14571461
"""Async context manager entry"""

modules/commands/solarforecast_command.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,11 @@ async def _send_forecast_response(self, message: MeshMessage, forecast_text: str
10861086
if len(test_message) > 130:
10871087
# Send current message and start new one
10881088
if current_message:
1089-
await self.send_response(message, current_message)
1089+
# Per-user rate limit applies only to first message (trigger); skip for continuations
1090+
await self.send_response(
1091+
message, current_message,
1092+
skip_user_rate_limit=(message_count > 0)
1093+
)
10901094
message_count += 1
10911095
# Wait between messages (same as other commands)
10921096
if message_count > 0 and i < len(lines):
@@ -1095,7 +1099,10 @@ async def _send_forecast_response(self, message: MeshMessage, forecast_text: str
10951099
current_message = line
10961100
else:
10971101
# Single line is too long, send it anyway (will be truncated by bot)
1098-
await self.send_response(message, line)
1102+
await self.send_response(
1103+
message, line,
1104+
skip_user_rate_limit=(message_count > 0)
1105+
)
10991106
message_count += 1
11001107
if i < len(lines) - 1:
11011108
await asyncio.sleep(2.0)
@@ -1106,7 +1113,7 @@ async def _send_forecast_response(self, message: MeshMessage, forecast_text: str
11061113
else:
11071114
current_message = line
11081115

1109-
# Send the last message if there's content
1116+
# Send the last message if there's content (continuation; skip per-user rate limit)
11101117
if current_message:
1111-
await self.send_response(message, current_message)
1118+
await self.send_response(message, current_message, skip_user_rate_limit=True)
11121119

0 commit comments

Comments
 (0)