Resolve type assertions

This commit is contained in:
2025-05-23 20:21:58 +02:00
parent 3088a75a7d
commit 5b8cbf8b9f
6 changed files with 32 additions and 6 deletions

View File

@@ -3,6 +3,9 @@ from telegram.ext import ContextTypes
from models import Gates, Users, Role
async def opengate(update: Update, context: ContextTypes.DEFAULT_TYPE, users: Users, gates: Gates):
assert update.effective_user is not None
assert update.message is not None
user_id = str(update.effective_user.id)
args = context.args
if not args:
@@ -16,6 +19,8 @@ async def opengate(update: Update, context: ContextTypes.DEFAULT_TYPE, users: Us
return await update.message.reply_text("Please set your credentials with `/setcredentials` first")
elif role == Role.GUEST and users.can_open_gate(user_id, gate):
grantor = users.get_grantor(user_id, gate)
assert grantor is not None
creds = users.get_credentials(grantor)
if not grantor:
return await update.message.reply_text("No valid grantor available.")
@@ -45,13 +50,16 @@ async def open_gate_menu(update: Update, context: ContextTypes.DEFAULT_TYPE, gat
await update.callback_query.edit_message_text(
"Select a gate to open:", reply_markup=reply_markup
)
else:
elif update.message:
await update.message.reply_text("Select a gate to open:", reply_markup=reply_markup)
async def handle_gate_open_callback(update: Update, context: ContextTypes.DEFAULT_TYPE, users: Users, gates: Gates):
assert update.callback_query is not None
query = update.callback_query
user_id = str(query.from_user.id)
data = query.data
assert data is not None
if data.startswith("opengate_"):
gate_id = data[len("opengate_") :]
gate_name = gates.get_name(gate_id)
@@ -63,6 +71,7 @@ async def handle_gate_open_callback(update: Update, context: ContextTypes.DEFAUL
return
elif role == Role.GUEST and users.can_open_gate(user_id, gate_id):
grantor = users.get_grantor(user_id, gate_id)
assert grantor is not None
creds = users.get_credentials(grantor)
if not grantor or not creds:
await query.answer("No valid grantor credentials available.", show_alert=True)