@@ -197,30 +197,65 @@ async def send_dm(self, recipient_id: str, content: str) -> bool:
197197 contact_name = contact .get ('name' , contact .get ('adv_name' , recipient_id ))
198198 self .logger .info (f"Sending DM to { contact_name } : { content } " )
199199
200- # Import send_msg from meshcore-cli
201- from meshcore_cli .meshcore_cli import send_msg
202-
203- # Use send_msg to send the actual message (not a command)
204- result = await send_msg (self .bot .meshcore , contact , content )
200+ # Try to use send_msg_with_retry if available (meshcore-2.1.6+)
201+ try :
202+ # Use the meshcore commands interface for send_msg_with_retry
203+ if hasattr (self .bot .meshcore , 'commands' ) and hasattr (self .bot .meshcore .commands , 'send_msg_with_retry' ):
204+ self .logger .debug ("Using send_msg_with_retry for improved reliability" )
205+
206+ # Use send_msg_with_retry with configurable retry parameters
207+ max_attempts = self .bot .config .getint ('Bot' , 'dm_max_retries' , fallback = 3 )
208+ max_flood_attempts = self .bot .config .getint ('Bot' , 'dm_max_flood_attempts' , fallback = 2 )
209+ flood_after = self .bot .config .getint ('Bot' , 'dm_flood_after' , fallback = 2 )
210+ timeout = 0 # Use suggested timeout from meshcore
211+
212+ self .logger .debug (f"Attempting DM send with { max_attempts } max attempts" )
213+ result = await self .bot .meshcore .commands .send_msg_with_retry (
214+ contact ,
215+ content ,
216+ max_attempts = max_attempts ,
217+ max_flood_attempts = max_flood_attempts ,
218+ flood_after = flood_after ,
219+ timeout = timeout
220+ )
221+ else :
222+ # Fallback to regular send_msg for older meshcore versions
223+ self .logger .debug ("send_msg_with_retry not available, using send_msg" )
224+ result = await self .bot .meshcore .commands .send_msg (contact , content )
225+
226+ except AttributeError :
227+ # Fallback to regular send_msg for older meshcore versions
228+ self .logger .debug ("send_msg_with_retry not available, using send_msg" )
229+ result = await self .bot .meshcore .commands .send_msg (contact , content )
205230
206231 # Check if the result indicates success
207232 if result :
208233 if hasattr (result , 'type' ) and result .type == EventType .ERROR :
209- self .logger .error (f"Failed to send DM : { result .payload } " )
234+ self .logger .error (f"❌ DM failed to { contact_name } : { result .payload } " )
210235 return False
211236 elif hasattr (result , 'type' ) and result .type == EventType .MSG_SENT :
212- self .logger .info (f"Successfully sent DM to { contact_name } " )
237+ # For send_msg_with_retry, check if we got an ACK (result is not None means ACK received)
238+ if hasattr (self .bot .meshcore , 'commands' ) and hasattr (self .bot .meshcore .commands , 'send_msg_with_retry' ):
239+ # We used send_msg_with_retry, so result being returned means ACK was received
240+ self .logger .info (f"✅ DM sent and ACK received from { contact_name } " )
241+ else :
242+ # We used regular send_msg, so just log the send
243+ self .logger .info (f"✅ DM sent to { contact_name } " )
213244 self .bot .rate_limiter .record_send ()
214245 self .bot .bot_tx_rate_limiter .record_tx ()
215246 return True
216247 else :
217248 # If result is not None but doesn't have expected attributes, assume success
218- self .logger .info (f"DM sent to { contact_name } (result: { result } )" )
249+ self .logger .info (f"✅ DM sent to { contact_name } (result: { result } )" )
219250 self .bot .rate_limiter .record_send ()
220251 self .bot .bot_tx_rate_limiter .record_tx ()
221252 return True
222253 else :
223- self .logger .error (f"Failed to send DM: No result returned" )
254+ # This means send_msg_with_retry failed to get an ACK after all retries
255+ if hasattr (self .bot .meshcore , 'commands' ) and hasattr (self .bot .meshcore .commands , 'send_msg_with_retry' ):
256+ self .logger .error (f"❌ DM to { contact_name } failed - no ACK received after retries" )
257+ else :
258+ self .logger .error (f"❌ DM to { contact_name } failed - no result returned" )
224259 return False
225260
226261 except Exception as e :
0 commit comments