|
@@ -11,7 +11,7 @@ import asyncio
|
|
|
import re
|
|
|
from datetime import datetime, timedelta
|
|
|
from typing import Optional, Dict, Any
|
|
|
-from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
|
|
+from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup, KeyboardButton
|
|
|
from telegram.ext import Application, CommandHandler, CallbackQueryHandler, ContextTypes, MessageHandler, filters
|
|
|
from hyperliquid_client import HyperliquidClient
|
|
|
from trading_stats import TradingStats
|
|
@@ -91,6 +91,34 @@ class TelegramTradingBot:
|
|
|
except Exception as e:
|
|
|
logger.error(f"Failed to send message: {e}")
|
|
|
|
|
|
+ def _create_custom_keyboard(self) -> Optional[ReplyKeyboardMarkup]:
|
|
|
+ """Create a custom keyboard from configuration."""
|
|
|
+ if not Config.TELEGRAM_CUSTOM_KEYBOARD_ENABLED:
|
|
|
+ return None
|
|
|
+
|
|
|
+ try:
|
|
|
+ layout = Config.TELEGRAM_CUSTOM_KEYBOARD_LAYOUT
|
|
|
+ # Parse the layout: "cmd1,cmd2,cmd3|cmd4,cmd5|cmd6,cmd7,cmd8,cmd9"
|
|
|
+ rows = layout.split('|')
|
|
|
+ keyboard = []
|
|
|
+
|
|
|
+ for row in rows:
|
|
|
+ commands = [cmd.strip() for cmd in row.split(',') if cmd.strip()]
|
|
|
+ if commands:
|
|
|
+ keyboard.append([KeyboardButton(cmd) for cmd in commands])
|
|
|
+
|
|
|
+ if keyboard:
|
|
|
+ return ReplyKeyboardMarkup(
|
|
|
+ keyboard,
|
|
|
+ resize_keyboard=True, # Resize to fit screen
|
|
|
+ one_time_keyboard=False, # Keep keyboard persistent
|
|
|
+ selective=True # Show only to authorized users
|
|
|
+ )
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(f"Failed to create custom keyboard: {e}")
|
|
|
+
|
|
|
+ return None
|
|
|
+
|
|
|
async def start_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
"""Handle the /start command."""
|
|
|
if not self.is_authorized(update.effective_chat.id):
|
|
@@ -220,7 +248,23 @@ For support, contact your bot administrator.
|
|
|
]
|
|
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
|
|
|
|
|
- await update.message.reply_text(welcome_text, parse_mode='HTML', reply_markup=reply_markup)
|
|
|
+ # Create custom keyboard for persistent buttons
|
|
|
+ custom_keyboard = self._create_custom_keyboard()
|
|
|
+
|
|
|
+ # Send message with inline keyboard
|
|
|
+ await update.message.reply_text(
|
|
|
+ welcome_text,
|
|
|
+ parse_mode='HTML',
|
|
|
+ reply_markup=reply_markup
|
|
|
+ )
|
|
|
+
|
|
|
+ # If custom keyboard is enabled, send a follow-up message to set the custom keyboard
|
|
|
+ if custom_keyboard:
|
|
|
+ await update.message.reply_text(
|
|
|
+ "⌨️ <b>Custom keyboard enabled!</b>\n\nUse the buttons below for quick access to commands:",
|
|
|
+ parse_mode='HTML',
|
|
|
+ reply_markup=custom_keyboard
|
|
|
+ )
|
|
|
|
|
|
async def help_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
"""Handle the /help command."""
|