geekcomputers / geekcomputers/Python

Bot

未关闭
#3,155 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
35.4k
派生
12.9k
平均合并
2 小时 37 分钟
30 天内合并 PR
1

描述

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)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

该 issue 包含一个独立的 Python bot 代码片段,但没有指出任何 repository 文件、测试、入口点或所需的更改。在开始编码之前,先检查 issue #3155 周围的 repository 上下文,并明确预期结果和范围;未提供完成标准。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
10/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。