Files
lagomareGateKeeperBot/handlers/credentials.py
2025-08-21 00:49:18 +02:00

20 lines
895 B
Python

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):
assert update.effective_user is not None
assert update.message is not None
assert context.args is not None
user_id = str(update.effective_user.id)
args = context.args
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 len(args) != 2:
return await update.message.reply_text("Usage: `/setcredentials <username> <password>`")
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")