Accept leading-whitespace commands; log spawn send failures
This commit is contained in:
@@ -572,7 +572,12 @@ class DuckHuntBot:
|
|||||||
"""Handle bot commands with enhanced error handling and input validation"""
|
"""Handle bot commands with enhanced error handling and input validation"""
|
||||||
try:
|
try:
|
||||||
# Validate input parameters
|
# Validate input parameters
|
||||||
if not isinstance(message, str) or not message.startswith('!'):
|
if not isinstance(message, str):
|
||||||
|
return
|
||||||
|
|
||||||
|
# Some clients/users may prefix commands with whitespace (e.g. " !bang").
|
||||||
|
message = message.lstrip()
|
||||||
|
if not message.startswith('!'):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not isinstance(user, str) or not isinstance(channel, str):
|
if not isinstance(user, str) or not isinstance(channel, str):
|
||||||
@@ -580,7 +585,7 @@ class DuckHuntBot:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Sanitize inputs
|
# Sanitize inputs
|
||||||
safe_message = sanitize_user_input(message, max_length=500)
|
safe_message = sanitize_user_input(message, max_length=500).lstrip()
|
||||||
safe_user = sanitize_user_input(user, max_length=200)
|
safe_user = sanitize_user_input(user, max_length=200)
|
||||||
safe_channel = sanitize_user_input(channel, max_length=100)
|
safe_channel = sanitize_user_input(channel, max_length=100)
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,8 @@ class DuckGame:
|
|||||||
|
|
||||||
# All duck types use the same spawn message - type is hidden!
|
# All duck types use the same spawn message - type is hidden!
|
||||||
message = self.bot.messages.get('duck_spawn')
|
message = self.bot.messages.get('duck_spawn')
|
||||||
self.bot.send_message(channel, message)
|
if not self.bot.send_message(channel, message):
|
||||||
|
self.logger.warning(f"Failed to send duck spawn message to {channel}")
|
||||||
|
|
||||||
async def force_spawn_duck(self, channel, duck_type):
|
async def force_spawn_duck(self, channel, duck_type):
|
||||||
"""Force spawn a specific duck type in a channel (admin/items), even if ducks already exist."""
|
"""Force spawn a specific duck type in a channel (admin/items), even if ducks already exist."""
|
||||||
@@ -184,7 +185,8 @@ class DuckGame:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.bot.send_message(channel, self.bot.messages.get('duck_spawn'))
|
if not self.bot.send_message(channel, self.bot.messages.get('duck_spawn')):
|
||||||
|
self.logger.warning(f"Failed to send forced duck spawn message to {channel}")
|
||||||
|
|
||||||
def _choose_duck_type(self):
|
def _choose_duck_type(self):
|
||||||
"""Choose a duck type using duck_types.*.chance (with legacy fallbacks)."""
|
"""Choose a duck type using duck_types.*.chance (with legacy fallbacks)."""
|
||||||
|
|||||||
Reference in New Issue
Block a user