Show only granted gates in menu

This commit is contained in:
2025-05-24 00:08:08 +02:00
parent 5b8cbf8b9f
commit 9af398faef
5 changed files with 35 additions and 8 deletions

View File

@@ -38,12 +38,26 @@ async def opengate(update: Update, context: ContextTypes.DEFAULT_TYPE, users: Us
return await update.message.reply_text(f"Gate {gate_name} opened!")
await update.message.reply_text(f"ERROR: Cannot open gate {gate_name}")
async def open_gate_menu(update: Update, context: ContextTypes.DEFAULT_TYPE, gates: Gates):
async def open_gate_menu(update: Update, context: ContextTypes.DEFAULT_TYPE, users: Users, gates: Gates):
assert update.effective_user is not None
user_id = str(update.effective_user.id)
granted_gates = users.get_granted_gates(user_id)
if not granted_gates:
if update.callback_query:
await update.callback_query.answer("You have no gates to open.")
elif update.message:
return await update.message.reply_text("You have no gates to open.")
if 'all' in granted_gates:
granted_gates = gates.get_all_gates_id()
# Show a list of available gates as buttons
keyboard = [
[InlineKeyboardButton(gate.name, callback_data=f"opengate_{gate_id}")]
for gate_id, gate in gates._gates.items()
]
keyboard = []
for gate_id in granted_gates:
gate_name = gates.get_name(gate_id)
assert gate_name is not None
keyboard.append([InlineKeyboardButton(gate_name, callback_data=f"opengate_{gate_id}")])
reply_markup = InlineKeyboardMarkup(keyboard)
if update.callback_query:
await update.callback_query.answer()