Files
post_bot/.history/main_20250903222258.py
Andrey K. Choi aca280b64d
Some checks failed
continuous-integration/drone Build is failing
init commit
2025-09-04 01:51:59 +09:00

40 lines
1.3 KiB
Python

import logging
import os
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Application, CommandHandler, MessageHandler, filters, CallbackQueryHandler, ConversationHandler, ContextTypes
from dotenv import load_dotenv
from db import SessionLocal, init_db
from models import Admin, Channel, Group, Button
load_dotenv()
TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN')
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
init_db()
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
session = SessionLocal()
user_id = update.effective_user.id
admin = session.query(Admin).filter_by(tg_id=user_id).first()
if not admin:
admin = Admin(tg_id=user_id)
session.add(admin)
session.commit()
await update.message.reply_text('Вы зарегистрированы как админ.')
else:
await update.message.reply_text('Вы уже зарегистрированы.')
session.close()
# ...handlers for add_channel, add_group, add_button, new_post, etc. будут добавлены...
def main():
application = Application.builder().token(TELEGRAM_TOKEN).build()
application.add_handler(CommandHandler('start', start))
# ...add other handlers...
application.run_polling()
if __name__ == '__main__':
main()