crypto-agent/bot/response_formatter.py
2024-12-04 23:10:02 +03:00

160 lines
6.1 KiB
Python

from typing import Dict, List, Union, Optional
from datetime import datetime
class ResponseFormatter:
"""Handles formatting of all bot responses"""
@staticmethod
def format_token_analysis(analysis: Dict, tier: str) -> str:
"""Format token analysis response"""
sections = []
# Header
sections.append("๐Ÿ”Ž Token Analysis Report")
sections.append("=" * 25)
# Basic Analysis (All Tiers)
basic = analysis.get("basic", {})
sections.extend([
"๐Ÿ“Š Basic Metrics",
f"โ€ข Price: ${basic.get('price', 'N/A'):,.4f}",
f"โ€ข 24h Volume: ${basic.get('volume', 'N/A'):,.2f}",
f"โ€ข Market Cap: ${basic.get('market_cap', 'N/A'):,.2f}",
""
])
# Advanced Analysis (Pro & Premium)
if tier in ["pro", "premium"] and "advanced" in analysis:
advanced = analysis["advanced"]
sections.extend([
"๐Ÿ” Advanced Analysis",
f"โ€ข Liquidity: ${advanced.get('liquidity', 'N/A'):,.2f}",
f"โ€ข 24h Change: {advanced.get('price_change', 'N/A')}%",
"โ€ข Pattern: " + advanced.get('patterns', 'No patterns detected'),
""
])
# Premium Analysis
if tier == "premium" and "premium" in analysis:
premium = analysis["premium"]
sections.extend([
"๐ŸŽฏ AI Insights",
f"โ€ข Signal: {premium.get('signals', 'N/A')}",
f"โ€ข Strength: {premium.get('signal_strength', 'N/A')}",
f"โ€ข Recommendation: {premium.get('recommendation', 'N/A')}",
""
])
return "\n".join(sections)
@staticmethod
def format_alert_message(alert: Dict) -> str:
"""Format price alert message"""
return (
"๐Ÿšจ Price Alert!\n\n"
f"Token: {alert.get('token_symbol', 'Unknown')}\n"
f"Price: ${alert.get('current_price', 0):,.4f}\n"
f"Change: {alert.get('price_change', 0):+.2f}%\n"
f"Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S UTC')}"
)
@staticmethod
def format_subscription_plans(plans: List[Dict], current_tier: str) -> str:
"""Format subscription plans message"""
sections = ["๐Ÿ“ฑ Available Subscription Plans\n"]
for plan in plans:
# Plan header
if plan['tier'] == current_tier:
sections.append(f"โœ… {plan['tier'].upper()} (Current Plan)")
else:
sections.append(f"๐Ÿ’  {plan['tier'].upper()}")
# Plan details
sections.extend([
f"Price: ${plan['price']}/month",
"Features:"
])
# Plan features
for feature in plan['features']:
sections.append(f" โ€ข {feature}")
sections.append("") # Empty line between plans
return "\n".join(sections)
@staticmethod
def format_monitor_status(monitors: List[Dict]) -> str:
"""Format monitoring status message"""
if not monitors:
return "๐Ÿ“Š No active monitors. Use /monitor to start tracking tokens!"
sections = ["๐Ÿ“Š Active Monitors\n"]
for monitor in monitors:
sections.extend([
f"Token: {monitor.get('symbol', 'Unknown')}",
f"Price: ${monitor.get('current_price', 0):,.4f}",
f"Alert Threshold: {monitor.get('alert_threshold', 0)}%",
f"Started: {monitor.get('start_time', 'Unknown')}\n"
])
return "\n".join(sections)
@staticmethod
def format_error_message(error: str, suggestion: Optional[str] = None) -> str:
"""Format error message with optional suggestion"""
message = f"โŒ Error: {error}"
if suggestion:
message += f"\n๐Ÿ’ก Suggestion: {suggestion}"
return message
@staticmethod
def format_success_message(action: str) -> str:
"""Format success message"""
return f"โœ… Success: {action}"
@staticmethod
def format_welcome_message(username: str) -> str:
"""Format welcome message for new users"""
return (
f"๐Ÿ‘‹ Welcome {username}!\n\n"
"I'm your crypto trading assistant. Here's what I can do:\n\n"
"๐Ÿ” Token Analysis:\n"
"โ€ข /analyze <token_address> - Analyze any token\n"
"โ€ข /monitor <token_address> - Track price changes\n"
"โ€ข /alerts - View your active alerts\n\n"
"๐Ÿ’Ž Account & Settings:\n"
"โ€ข /subscribe - View subscription plans\n"
"โ€ข /status - Check your account status\n"
"โ€ข /help - Get detailed help\n\n"
"Start with /analyze to check your first token!"
)
@staticmethod
def format_help_message() -> str:
"""Format help message"""
return (
"๐Ÿ“š Command Reference\n\n"
"Analysis Commands:\n"
"โ€ข /analyze <token> - Get token analysis\n"
"โ€ข /monitor <token> - Start price tracking\n"
"โ€ข /alerts - View active alerts\n\n"
"Account Commands:\n"
"โ€ข /subscribe - View/change subscription\n"
"โ€ข /status - Account status\n"
"โ€ข /settings - Bot settings\n\n"
"Need help? Contact @support"
)
@staticmethod
def format_status_message(user_data: Dict) -> str:
"""Format user status message"""
return (
"๐Ÿ“Š Your Account Status\n\n"
f"Plan: {user_data.get('tier', 'Free')}\n"
f"Analyses Today: {user_data.get('analyses_today', 0)}/{user_data.get('daily_limit', 3)}\n"
f"Active Monitors: {user_data.get('active_monitors', 0)}/{user_data.get('monitor_limit', 1)}\n"
f"Member Since: {user_data.get('joined_date', 'Unknown')}\n\n"
"Use /subscribe to upgrade your plan!"
)