More refactoring

This commit is contained in:
2025-05-14 23:27:50 +02:00
parent ebd8529c41
commit 4a3d2746fb
3 changed files with 25 additions and 10 deletions

6
bot.py
View File

@@ -1,5 +1,6 @@
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, ContextTypes
from datetime import datetime
from config import BotConfig
from gates import Gates
from users import Users, Credential, Role
@@ -10,11 +11,10 @@ gates = Gates()
users = Users()
async def post_init(application: Application) -> None:
bot_commands = bot_config.commands
await application.bot.set_my_commands(bot_commands)
await application.bot.set_my_name(bot_config.name)
await application.bot.set_my_description(bot_config.description)
await application.bot.set_my_short_description(bot_config.short_description)
await application.bot.set_my_commands(bot_config.commands)
async def updateuser(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id = str(update.effective_user.id)
@@ -94,7 +94,7 @@ async def approve(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id = context.args[0]
gate = context.args[1]
expires_at = context.args[2]
users.grant_access(user_id, gate, expires_at, grantor_id=approver_id)
users.grant_access(user_id, gate, datetime.fromisoformat(expires_at.replace("Z", "+00:00")), grantor_id=approver_id)
await update.message.reply_text(f"Access to {gate} granted to user {user_id}.")
try:
await context.bot.send_message(chat_id=user_id, text=f"Access granted to gate {gate} up to {expires_at}")