geekcomputers / geekcomputers/Python
Bot
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 35.4k
- Fork
- 12.9k
- Merge medio
- 2h 37m
- PR unite (30g)
- 1
Descrizione
import logging
import json
import os
from aiogram import Bot, Dispatcher, executor, types
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
logging.basicConfig(level=logging.INFO)
Telegram tokenni Replit Secrets (🔒) dan oling
BOT_TOKEN = os.getenv("8680300677:AAEzbGu8DHv4B9n9cI9xgkmA9ueA5EvS_GE")
bot = Bot(token=8680300677:AAEzbGu8DHv4B9n9cI9xgkmA9ueA5EvS_GE)
dp = Dispatcher(bot)
Ma'lumotlar va fayllar saqlanishi
DATA_FILE = "users.json"
MEDIA_FOLDER = "files"
if not os.path.exists(MEDIA_FOLDER):
os.makedirs(MEDIA_FOLDER)
Foydalanuvchilarni yuklash / saqlash
def load_users():
if not os.path.exists(DATA_FILE):
return {}
with open(DATA_FILE, "r", encoding="utf-8") as f:
return json.load(f)
def save_users(data):
with open(DATA_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
users = load_users()
Telefon yuborish tugmasi
phone_kb = ReplyKeyboardMarkup(resize_keyboard=True)
phone_kb.add(KeyboardButton("📞 Telefon raqamni yuborish", request_contact=True))
/start komandasi
@dp.message_handler(commands=["start"])
async def start(msg: types.Message):
await msg.answer(
"Assalomu alaykum!\nBot orqali ro‘yxatdan o‘tasiz.\nTelefon raqamingizni yuboring.",
reply_markup=phone_kb
)
Telefon raqam qabul qilish
@dp.message_handler(content_types=types.ContentType.CONTACT)
async def get_phone(msg: types.Message):
user_id = str(msg.from_user.id)
users[user_id] = {
"name": msg.from_user.full_name,
"phone": msg.contact.phone_number,
"passport": "",
"driver_license": "",
"car_passport": "",
"files": []
}
save_users(users)
await msg.answer("✅ Telefon qabul qilindi.\nEndi pasport ma’lumotini kiriting:", reply_markup=types.ReplyKeyboardRemove())
Pasport
@dp.message_handler(lambda m: str(m.from_user.id) in users and users[str(m.from_user.id)]["passport"] == "")
async def get_passport(msg: types.Message):
user_id = str(msg.from_user.id)
users[user_id]["passport"] = msg.text.strip()
save_users(users)
await msg.answer("✅ Pasport qabul qilindi.\nEndi haydovchilik guvohnomangizni kiriting:")
Haydovchilik guvohnomasi
@dp.message_handler(lambda m: str(m.from_user.id) in users and users[str(m.from_user.id)]["driver_license"] == "")
async def get_driver_license(msg: types.Message):
user_id = str(msg.from_user.id)
users[user_id]["driver_license"] = msg.text.strip()
save_users(users)
await msg.answer("✅ Haydovchilik guvohnomasi qabul qilindi.\nEndi mashina texnik pasportini kiriting:")
Mashina texnik pasporti
@dp.message_handler(lambda m: str(m.from_user.id) in users and users[str(m.from_user.id)]["car_passport"] == "")
async def get_car_passport(msg: types.Message):
user_id = str(msg.from_user.id)
users[user_id]["car_passport"] = msg.text.strip()
save_users(users)
await msg.answer("✅ Texnik pasport qabul qilindi.\nEndi hujjatlarni rasm/fayl sifatida yuborishingiz mumkin:")
Fayl / rasm qabul qilish
@dp.message_handler(content_types=[types.ContentType.DOCUMENT, types.ContentType.PHOTO])
async def handle_files(msg: types.Message):
user_id = str(msg.from_user.id)
if user_id not in users:
await msg.answer("Iltimos, /start buyrug‘i orqali ro‘yxatdan o‘ting.")
return
file_id = None
if msg.content_type == "document":
file_id = msg.document.file_id
file_name = msg.document.file_name
await msg.document.download(os.path.join(MEDIA_FOLDER, file_name))
elif msg.content_type == "photo":
file_id = msg.photo[-1].file_id
file_name = f"{file_id}.jpg"
await msg.photo[-1].download(os.path.join(MEDIA_FOLDER, file_name))
users[user_id]["files"].append(file_name)
save_users(users)
await msg.answer(f"✅ Fayl qabul qilindi va saqlandi: {file_name}")
Avto-javob
@dp.message_handler()
async def auto_reply(msg: types.Message):
await msg.answer("🤖 Avto-javob:\nIltimos, /start buyrug‘ini bosing va ro‘yxatdan o‘ting.")
Bot ishga tushadi
if name == "main":
executor.start_polling(dp, skip_updates=True)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La issue contiene uno snippet autonomo di un bot Python, ma non indica alcun file del repository, test, punto di ingresso o modifica richiesta. Prima di scrivere codice, esamina il contesto del repository relativo alla issue #3155 e chiarisci il risultato previsto e l’ambito; non sono forniti criteri di completamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 10/100