mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-07-30 23:39:50 +00:00
Add configurable transmission delay to prevent message collisions
This commit is contained in:
@@ -6,6 +6,7 @@ Handles all bot commands, keyword matching, and response generation
|
||||
|
||||
import re
|
||||
import time
|
||||
import asyncio
|
||||
from typing import List, Dict, Tuple, Optional, Any
|
||||
from meshcore import EventType
|
||||
|
||||
@@ -33,6 +34,12 @@ class CommandManager:
|
||||
|
||||
self.logger.info(f"CommandManager initialized with {len(self.commands)} plugins")
|
||||
|
||||
async def _apply_tx_delay(self):
|
||||
"""Apply transmission delay to prevent message collisions"""
|
||||
if self.bot.tx_delay_ms > 0:
|
||||
self.logger.debug(f"Applying {self.bot.tx_delay_ms}ms transmission delay")
|
||||
await asyncio.sleep(self.bot.tx_delay_ms / 1000.0)
|
||||
|
||||
def load_keywords(self) -> Dict[str, str]:
|
||||
"""Load keywords from config"""
|
||||
keywords = {}
|
||||
@@ -176,6 +183,9 @@ class CommandManager:
|
||||
# Wait for bot TX rate limiter (prevents network overload)
|
||||
await self.bot.bot_tx_rate_limiter.wait_for_tx()
|
||||
|
||||
# Apply transmission delay to prevent message collisions
|
||||
await self._apply_tx_delay()
|
||||
|
||||
try:
|
||||
# Find the contact by name (since recipient_id is the contact name)
|
||||
contact = self.bot.meshcore.get_contact_by_name(recipient_id)
|
||||
@@ -231,6 +241,9 @@ class CommandManager:
|
||||
# Wait for bot TX rate limiter (prevents network overload)
|
||||
await self.bot.bot_tx_rate_limiter.wait_for_tx()
|
||||
|
||||
# Apply transmission delay to prevent message collisions
|
||||
await self._apply_tx_delay()
|
||||
|
||||
try:
|
||||
# Get channel number from channel name
|
||||
channel_num = self.bot.channel_manager.get_channel_number(channel)
|
||||
|
||||
Reference in New Issue
Block a user