feat: Add slash command help system (#57) #62
@@ -472,6 +472,15 @@ class ConversationalAgent:
|
|||||||
# Track pending command after acknowledgment
|
# Track pending command after acknowledgment
|
||||||
self.pending_command = None
|
self.pending_command = None
|
||||||
|
|
||||||
|
def _is_error_output(self, code: int, output: str) -> bool:
|
||||||
|
"""Check if the command output contains an error."""
|
||||||
|
if code != 0:
|
||||||
|
return True
|
||||||
|
# Check for common error patterns in output
|
||||||
|
if output.startswith("Error:") or "API error" in output or "api key invalid" in output.lower():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def _handle_slash_command(self, user_message: str) -> Dict[str, Any]:
|
def _handle_slash_command(self, user_message: str) -> Dict[str, Any]:
|
||||||
"""Handle slash command help requests.
|
"""Handle slash command help requests.
|
||||||
|
|
||||||
@@ -664,7 +673,14 @@ class ConversationalAgent:
|
|||||||
"trending",
|
"trending",
|
||||||
["--chain", "bsc", "--page-size", "10"],
|
["--chain", "bsc", "--page-size", "10"],
|
||||||
)
|
)
|
||||||
if code == 0:
|
if self._is_error_output(code, output):
|
||||||
|
return {
|
||||||
|
"response": f"Failed to get trending tokens: {output}",
|
||||||
|
"thinking": None,
|
||||||
|
"strategy_updated": False,
|
||||||
|
"strategy_needs_confirmation": False,
|
||||||
|
"success": True,
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
data = json.loads(output)
|
data = json.loads(output)
|
||||||
# Handle both dict with 'tokens' key and direct list
|
# Handle both dict with 'tokens' key and direct list
|
||||||
@@ -709,14 +725,6 @@ class ConversationalAgent:
|
|||||||
"strategy_needs_confirmation": False,
|
"strategy_needs_confirmation": False,
|
||||||
"success": True,
|
"success": True,
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return {
|
|
||||||
"response": f"Failed to get trending tokens: {output}",
|
|
||||||
"thinking": None,
|
|
||||||
"strategy_updated": False,
|
|
||||||
"strategy_needs_confirmation": False,
|
|
||||||
"success": True,
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
"response": f"Error getting trending tokens: {str(e)}",
|
"response": f"Error getting trending tokens: {str(e)}",
|
||||||
@@ -733,7 +741,14 @@ class ConversationalAgent:
|
|||||||
"search",
|
"search",
|
||||||
["--keyword", keyword.strip(), "--chain", "bsc", "--limit", "10"],
|
["--keyword", keyword.strip(), "--chain", "bsc", "--limit", "10"],
|
||||||
)
|
)
|
||||||
if code == 0:
|
if self._is_error_output(code, output):
|
||||||
|
return {
|
||||||
|
"response": f"Failed to search tokens: {output}",
|
||||||
|
"thinking": None,
|
||||||
|
"strategy_updated": False,
|
||||||
|
"strategy_needs_confirmation": False,
|
||||||
|
"success": True,
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
data = json.loads(output)
|
data = json.loads(output)
|
||||||
# Handle both dict with 'tokens' key and direct list
|
# Handle both dict with 'tokens' key and direct list
|
||||||
@@ -778,14 +793,6 @@ class ConversationalAgent:
|
|||||||
"strategy_needs_confirmation": False,
|
"strategy_needs_confirmation": False,
|
||||||
"success": True,
|
"success": True,
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return {
|
|
||||||
"response": f"Failed to search tokens: {output}",
|
|
||||||
"thinking": None,
|
|
||||||
"strategy_updated": False,
|
|
||||||
"strategy_needs_confirmation": False,
|
|
||||||
"success": True,
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
"response": f"Error searching tokens: {str(e)}",
|
"response": f"Error searching tokens: {str(e)}",
|
||||||
@@ -802,7 +809,14 @@ class ConversationalAgent:
|
|||||||
"risk",
|
"risk",
|
||||||
["--address", address.strip(), "--chain", "bsc"],
|
["--address", address.strip(), "--chain", "bsc"],
|
||||||
)
|
)
|
||||||
if code == 0:
|
if self._is_error_output(code, output):
|
||||||
|
return {
|
||||||
|
"response": f"Failed to get risk data: {output}",
|
||||||
|
"thinking": None,
|
||||||
|
"strategy_updated": False,
|
||||||
|
"strategy_needs_confirmation": False,
|
||||||
|
"success": True,
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
data = json.loads(output)
|
data = json.loads(output)
|
||||||
data_field = data.get("data")
|
data_field = data.get("data")
|
||||||
@@ -862,14 +876,6 @@ class ConversationalAgent:
|
|||||||
"strategy_needs_confirmation": False,
|
"strategy_needs_confirmation": False,
|
||||||
"success": True,
|
"success": True,
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return {
|
|
||||||
"response": f"Failed to get risk data: {output}",
|
|
||||||
"thinking": None,
|
|
||||||
"strategy_updated": False,
|
|
||||||
"strategy_needs_confirmation": False,
|
|
||||||
"success": True,
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
"response": f"Error getting risk data: {str(e)}",
|
"response": f"Error getting risk data: {str(e)}",
|
||||||
@@ -994,7 +1000,14 @@ class ConversationalAgent:
|
|||||||
"price",
|
"price",
|
||||||
["--tokens"] + tokens_list,
|
["--tokens"] + tokens_list,
|
||||||
)
|
)
|
||||||
if code == 0:
|
if self._is_error_output(code, output):
|
||||||
|
return {
|
||||||
|
"response": f"Failed to get prices: {output}",
|
||||||
|
"thinking": None,
|
||||||
|
"strategy_updated": False,
|
||||||
|
"strategy_needs_confirmation": False,
|
||||||
|
"success": True,
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
data = json.loads(output)
|
data = json.loads(output)
|
||||||
prices = data.get("data", {})
|
prices = data.get("data", {})
|
||||||
@@ -1029,14 +1042,6 @@ class ConversationalAgent:
|
|||||||
"strategy_needs_confirmation": False,
|
"strategy_needs_confirmation": False,
|
||||||
"success": True,
|
"success": True,
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return {
|
|
||||||
"response": f"Failed to get prices: {output}",
|
|
||||||
"thinking": None,
|
|
||||||
"strategy_updated": False,
|
|
||||||
"strategy_needs_confirmation": False,
|
|
||||||
"success": True,
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
"response": f"Error getting prices: {str(e)}",
|
"response": f"Error getting prices: {str(e)}",
|
||||||
|
|||||||
Reference in New Issue
Block a user