Created modules and organized code

This commit is contained in:
2025-05-23 00:06:26 +02:00
parent 020b5e0193
commit 3088a75a7d
17 changed files with 340 additions and 248 deletions

16
handlers/credentials.py Normal file
View File

@@ -0,0 +1,16 @@
from telegram import Update
from telegram.ext import ContextTypes
from models import Users, Credential, Role
async def setcredentials(update: Update, context: ContextTypes.DEFAULT_TYPE, users: Users):
user_id = str(update.effective_user.id)
args = context.args
if len(args) != 2:
return await update.message.reply_text("Usage: `/setcredentials <username> <password>`")
role = users.get_role(user_id)
if role not in (Role.ADMIN, Role.MEMBER):
return await update.message.reply_text("Only members or admins can set credentials")
if users.set_credentials(user_id, Credential(args[0], args[1])):
await update.message.reply_text("Credentials saved")
else:
await update.message.reply_text("Error saving credentials")