24 lines
1.0 KiB
Python
24 lines
1.0 KiB
Python
import secrets
|
|
from telegram import Update
|
|
from telegram.ext import CommandHandler, ContextTypes
|
|
from db import AsyncSessionLocal, log_action
|
|
from models import Admin
|
|
|
|
async def share_bot(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
user_id = update.effective_user.id
|
|
channel_id = context.user_data.get("channel_id")
|
|
if not channel_id:
|
|
await update.message.reply_text("Сначала выберите канал через /channel_buttons.")
|
|
return
|
|
token = secrets.token_urlsafe(16)
|
|
session = AsyncSessionLocal()
|
|
admin = Admin(tg_id=user_id, channel_id=channel_id, inviter_id=user_id, invite_token=token)
|
|
session.add(admin)
|
|
session.commit()
|
|
session.close()
|
|
link = f"/invite_admin {channel_id} {user_id} {token}"
|
|
await update.message.reply_text(f"Инвайт-ссылка для нового администратора:\n{link}")
|
|
log_action(user_id, "share_bot", f"channel_id={channel_id}, token={token}")
|
|
|
|
share_bot_handler = CommandHandler("share_bot", share_bot)
|