Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avtomobil haqida ma'lumot #241

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions Avtomobil haqida ma'lumot
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from telegram import Update, KeyboardButton, ReplyKeyboardMarkup
from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, ConversationHandler, ContextTypes, filters
import requests

# Holatlar
LANGUAGE, USER_TYPE, PHONE, REGION, CAR_TYPE, INSURANCE, PAYMENT = range(7)

# Admin IDsi (adminga xabar yuborish uchun)
ADMIN_ID = 5682528499 # O'zingizning Telegram ID ni kiriting

# API ma'lumotlari
USERNAME = "AXMADJONOV-26"
PASSWORD = "RPY5D1I2"

def send_data_to_website(phone, region, car_type, insurance_type, payment_type, user_type):
url = "https://insurance.uz/api/data"
payload = {
"username": AXMADJONOV-26,
"password": RPY5D1I2,
"phone": phone,
"region": region,
"car_type": car_type,
"insurance_type": insurance_type,
"payment_type": payment_type,
"user_type": user_type
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
return response.json().get("message", "✅ Ma'lumot muvaffaqiyatli yuborildi!")
else:
return f"❌ Xato yuz berdi: Status kodi {response.status_code}"

# Boshlanish
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [
[KeyboardButton("O'zbek tili"), KeyboardButton("Русский")],
[KeyboardButton("English")]
]
reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True)
await update.message.reply_text("\U0001F310 Tilni tanlang | Выберите язык | Choose a language:", reply_markup=reply_markup)
return LANGUAGE

# Tilni o'rnatish
async def set_language(update: Update, context: ContextTypes.DEFAULT_TYPE):
language = update.message.text
context.user_data['language'] = language
message = {
"O'zbek tili": "Jismoniy yoki yuridik shaxsni tanlang:",
"Русский": "Выберите физическое или юридическое лицо:",
"English": "Select individual or legal entity:"
}
await update.message.reply_text(message.get(language, "Invalid language selected."))
keyboard = [
[KeyboardButton("Jismoniy shaxs"), KeyboardButton("Yuridik shaxs")],
[KeyboardButton("Физическое лицо"), KeyboardButton("Юридическое лицо")],
[KeyboardButton("Individual"), KeyboardButton("Legal entity")]
]
reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True)
return USER_TYPE

return PAYMENT

# To'lov turi va ma'lumotlarni yuborish
async def get_payment_type(update: Update, context: ContextTypes.DEFAULT_TYPE):
context.user_data['payment_type'] = update.message.text

phone = context.user_data['phone']
region = context.user_data['region']
car_type = context.user_data['car_type']
insurance_type = context.user_data['insurance_type']
payment_type = context.user_data['payment_type']
user_type = context.user_data['user_type']

lang = context.user_data['language']

if lang == "O'zbek tili":
processing_msg = "🔄 Ma'lumotlaringiz yuborilmoqda..."
elif lang == "Русский":
processing_msg = "🔄 Отправка ваших данных..."
else:
processing_msg = "🔄 Sending your data..."

await update.message.reply_text(processing_msg)

try:
result = send_data_to_website(phone, region, car_type, insurance_type, payment_type, user_type)
await update.message.reply_text(result)

# Admin xabar
admin_msg = f"New submission:\nPhone: {phone}\nRegion: {region}\nCar Type: {car_type}\nInsurance: {insurance_type}\nPayment: {payment_type}\nUser Type: {user_type}"
await context.bot.send_message(chat_id=ADMIN_ID, text=admin_msg)

except Exception as e:
await update.message.reply_text(f"❗ Xatolik: {str(e)}")

return ConversationHandler.END

# Amaliyotni bekor qilish
async def cancel(update: Update, context: ContextTypes.DEFAULT_TYPE):
lang = context.user_data.get('language', "O'zbek tili")

if lang == "O'zbek tili":
cancel_msg = "❌ Amaliyot bekor qilindi."
elif lang == "Русский":
cancel_msg = "❌ Операция отменена."
else:
cancel_msg = "❌ Operation cancelled."

await update.message.reply_text(cancel_msg)
return ConversationHandler.END

# Asosiy bot funksiyasi
def main():
TOKEN = "7701948780:AAGUMDmSIaIWXGqmBtILS6_TyiGfw5lM2eE" # Bot tokeningizni kiriting
application = ApplicationBuilder().token(TOKEN).build()

# ConversationHandler sozlash
conv_handler = ConversationHandler(
entry_points=[CommandHandler("start", start)],
states={
LANGUAGE: [MessageHandler(filters.TEXT & ~filters.COMMAND, set_language)],
USER_TYPE: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_user_type)],
PHONE: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_phone)],
REGION: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_region)],
CAR_TYPE: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_car_type)],
INSURANCE: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_insurance_type)],
PAYMENT: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_payment_type)],
},
fallbacks=[CommandHandler("cancel", cancel)]
)

application.add_handler(conv_handler)
application.run_polling()

if __name__ == "__main__":
main()
118 changes: 118 additions & 0 deletions Avtomobil sug'urta 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from telegram import Update, KeyboardButton, ReplyKeyboardMarkup
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext

# Token va Admin ID
TOKEN = "YOUR_BOT_API_TOKEN" # O'zingizning tokeningizni kiriting
ADMIN_ID = 5682528499 # Admin ID-ni o'zgartiring

# Foydalanuvchi tillari
LANGUAGES = {
"uz": {
"welcome": "Iltimos, tilni tanlang:",
"uzbek": "O'zbekcha",
"russian": "Русский",
"english": "English",
"region": "Iltimos, viloyatingizni tanlang:",
"car_type": "Iltimos, avtomobil turini tanlang:",
"insurance": "Iltimos, sug'urta turini tanlang:",
"passport": "Iltimos, avtomobilning Texpasport ma'lumotlarini kiriting:",
"drivers": "Iltimos, haydovchilar sonini tanlang (1-5):",
"id_passport": "Iltimos, ID raqam va passport seriyasini kiriting:",
"payment": "Iltimos, to'lov turini tanlang:",
"thanks": "Rahmat, ma'lumotlaringiz adminga yuborildi!",
},
"ru": {
"welcome": "Пожалуйста, выберите язык:",
"uzbek": "O'zbekcha",
"russian": "Русский",
"english": "English",
"region": "Пожалуйста, выберите ваш регион:",
"car_type": "Пожалуйста, выберите тип автомобиля:",
"insurance": "Пожалуйста, выберите тип страховки:",
"passport": "Пожалуйста, введите данные техпаспорта автомобиля:",
"drivers": "Пожалуйста, выберите количество водителей (1-5):",
"id_passport": "Пожалуйста, введите номер ID и серию паспорта:",
"payment": "Пожалуйста, выберите тип оплаты:",
"thanks": "Спасибо, ваша информация отправлена администратору!",
},
"en": {
"welcome": "Please select a language:",
"uzbek": "O'zbekcha",
"russian": "Русский",
"english": "English",
"region": "Please select your region:",
"car_type": "Please select the type of vehicle:",
"insurance": "Please select the type of insurance:",
"passport": "Please enter the vehicle's technical passport details:",
"drivers": "Please select the number of drivers (1-5):",
"id_passport": "Please enter your ID number and passport series:",
"payment": "Please select the payment type:",
"thanks": "Thank you, your information has been sent to the admin!",
},
}

# Foydalanuvchi tillarini saqlash
user_languages = {}

# Start komandasi
def start(update: Update, context: CallbackContext):
keyboard = [
[KeyboardButton(LANGUAGES["uz"]["uzbek"])],
[KeyboardButton(LANGUAGES["uz"]["russian"])],
[KeyboardButton(LANGUAGES["uz"]["english"])]
]
reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True)
update.message.reply_text(LANGUAGES["uz"]["welcome"], reply_markup=reply_markup)

# Tilni tanlash
def process_language(update: Update, context: CallbackContext):
user_language = None
if update.message.text == LANGUAGES["uz"]["uzbek"]:
user_language = "uz"
elif update.message.text == LANGUAGES["uz"]["russian"]:
user_language = "ru"
elif update.message.text == LANGUAGES["uz"]["english"]:
user_language = "en"

if user_language:
user_languages[update.message.chat_id] = user_language
ask_region(update, context)
else:
update.message.reply_text("Iltimos, berilgan variantlardan birini tanlang.")

# Viloyatni tanlash
def ask_region(update: Update, context: CallbackContext):
user_language = user_languages.get(update.message.chat_id, "uz")
regions = [
"Navoiy viloyati", "Toshkent viloyati", "Andijon viloyati",
"Buxoro viloyati", "Fargʻona viloyati", "Jizzax viloyati",
"Xorazm viloyati", "Namangan viloyati", "Qashqadaryo viloyati",
"Qoraqalpogʻiston Respublikasi", "Samarqand viloyati",
"Sirdaryo viloyati", "Surxondaryo viloyati", "Toshkent shahar"
]
keyboard = [[KeyboardButton(region)] for region in regions]
reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True)
update.message.reply_text(LANGUAGES[user_language]["region"], reply_markup=reply_markup)

# Adminni xabardor qilish
def notify_admin(update: Update, context: CallbackContext):
user_language = user_languages.get(update.message.chat_id, "uz")
context.bot.send_message(chat_id=ADMIN_ID, text=f"Foydalanuvchi: {update.message.from_user.username}, ID: {update.message.chat_id}")
update.message.reply_text(LANGUAGES[user_language]["thanks"])

# Asosiy ishga tushirish funksiyasi
def main():
updater = Updater(TOKEN)
dispatcher = updater.dispatcher

# Komandalar
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, process_language))
dispatcher.add_handler(MessageHandler(Filters.contact, notify_admin))

# Botni ishga tushirish
updater.start_polling()
updater.idle()

if __name__ == '__main__':
main()