init commit 2

This commit is contained in:
2024-12-06 10:47:30 +09:00
parent fc1c0d6405
commit 6e8d1fb6e3
37 changed files with 746 additions and 0 deletions

0
bot/__init__.py Normal file
View File

3
bot/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
bot/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class BotConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'bot'

39
bot/bot.py Normal file
View File

@@ -0,0 +1,39 @@
from telegram import Update
from telegram.ext import Updater, CommandHandler, CallbackContext
from users.models import User, UserConfirmation
import uuid
def start(update: Update, context: CallbackContext):
user_id = update.message.from_user.id
chat_id = update.message.chat_id
user, created = User.objects.get_or_create(telegram_id=user_id, defaults={'chat_id': chat_id})
if not user.confirmed:
confirmation_code = str(uuid.uuid4())
UserConfirmation.objects.create(user=user, confirmation_code=confirmation_code)
update.message.reply_text(f"Ваш код подтверждения: {confirmation_code}")
else:
update.message.reply_text("Вы уже зарегистрированы!")
def confirm(update: Update, context: CallbackContext):
user_id = update.message.from_user.id
code = ' '.join(context.args)
try:
confirmation = UserConfirmation.objects.get(user__telegram_id=user_id, confirmation_code=code)
confirmation.user.confirmed = True
confirmation.user.save()
confirmation.delete()
update.message.reply_text("Регистрация подтверждена!")
except UserConfirmation.DoesNotExist:
update.message.reply_text("Неверный код подтверждения!")
def main():
updater = Updater("YOUR_TELEGRAM_BOT_TOKEN")
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("confirm", confirm))
updater.start_polling()
updater.idle()

View File

3
bot/models.py Normal file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
bot/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

0
bot/urls.py Normal file
View File

3
bot/views.py Normal file
View File

@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.