این کد منه میخوام با uptimerobot آنلاین نگهداشدا م: import telebot from telebot import…
- User
این کد منه میخوام با uptimerobot آنلاین نگهداشدا م: import telebot from telebot import types import sqlite3 import os from datetime import datetime
BOT_TOKEN = '6527538495:AAH85hVHxSrHECVepMqoIW4_IBYNxl_oLzc' bot = telebot.TeleBot(BOT_TOKEN)
def setup_database(): conn = sqlite3.connect('bot_database.db') c = conn.cursor() c.execute('''CREATE TABLE IF NOT EXISTS users (user_id INTEGER PRIMARY KEY, username TEXT, join_date TEXT)''') conn.commit() conn.close()
def register_user(user_id, username): conn = sqlite3.connect('bot_database.db') c = conn.cursor() join_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") c.execute("INSERT OR IGNORE INTO users VALUES (?, ?, ?)", (user_id, username, join_date)) conn.commit() conn.close()
@bot.message_handler(commands=['start']) def send_welcome(message): user_id = message.from_user.id username = message.from_user.username register_user(user_id, username)
markup = types.ReplyKeyboardMarkup(row_width=2) btn1 = types.KeyboardButton('📸 ارسال عکس') btn2 = types.KeyboardButton('📹 ارسال ویدیو') btn3 = types.KeyboardButton('📄 ارسال فایل') btn4 = types.KeyboardButton('ℹ️ راهنما') markup.add(btn1, btn2, btn3, btn4) bot.reply_to(message, "سلام! به ربات ما خوش آمدید.\nاز منوی زیر گزینه مورد نظر را انتخاب کنید.", reply_markup=markup)@bot.message_handler(commands=['help']) def help_command(message): help_text = """ 📌 راهنمای استفاده از ربات: /start - شروع مجدد ربات /help - نمایش این راهنما /profile - مشاهده پروفایل /upload - آپلود فایل /stats - آمار ربات """ bot.reply_to(message, help_text)
@bot.message_handler(content_types=['photo']) def handle_photo(message): try: file_info = bot.get_file(message.photo[-1].file_id) downloaded_file = bot.download_file(file_info.file_path)
file_name = f"photos/photo_{message.from_user.id}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg" with open(file_name, 'wb') as new_file: new_file.write(downloaded_file) bot.reply_to(message, "✅ عکس با موفقیت ذخیره شد!") except Exception as e: bot.reply_to(message, "❌ خطا در ذخیره عکس")@bot.message_handler(content_types=['video']) def handle_video(message): try: file_info = bot.get_file(message.video.file_id) downloaded_file = bot.download_file(file_info.file_path)
file_name = f"videos/video_{message.from_user.id}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4" with open(file_name, 'wb') as new_file: new_file.write(downloaded_file) bot.reply_to(message, "✅ ویدیو با موفقیت ذخیره شد!") except Exception as e: bot.reply_to(message, "❌ خطا در ذخیره ویدیو")@bot.message_handler(content_types=['document']) def handle_docs(message): try: file_info = bot.get_file(message.document.file_id) downloaded_file = bot.download_file(file_info.file_path)
file_name = f"files/{message.document.file_name}" with open(file_name, 'wb') as new_file: new_file.write(downloaded_file) bot.reply_to(message, "✅ فایل با موفقیت ذخیره شد!") except Exception as e: bot.reply_to(message, "❌ خطا در ذخیره فایل") - Assistant