import requests import telebot from telebot import types import webbrowser import sqlite3 dow_file = None bot = telebot.TeleBot('6292869682:AAE6SEjERUcworxKRk5Xx-nyKJTkhbjo9iM') API_weather = '20648333e6935d836ba391c943d4f9cc' name = None @bot.message_handler(commands=['foto']) def foto(message): fotoe = bot.send_message(message.chat.id, 'Пришлите фото!') bot.register_next_step_handler(fotoe, get_foto) def get_foto(message): global dow_file file_id = message.photo[-1].file_id file_info = bot.get_file(file_id) dow_file = bot.download_file(file_info.file_path) mess = bot.send_message(message.chat.id, 'Отправьте описание этого изображения!') bot.register_next_step_handler(mess, get_text) def get_text(message): global dow_file title = message.text with open(f'TEM/DR/{title}.jpg', 'wb') as ph: ph.write(dow_file) bot.send_message(message.chat.id, 'Все отлично получено!') @bot.message_handler(commands=['site']) def site(message): webbrowser.open('https://pypi.org/project/pyTelegramBotAPI/') @bot.message_handler(commands=['start_test']) def start(message): conn = sqlite3.connect('Opalami.sql') cur = conn.cursor() cur.execute('CREATE TABLE IF NOT EXISTS users (id int auto_increment primary key, name varchar(50), pass varchar(50))') conn.commit() cur.close() conn.close() mess = f'KU, {message.from_user.first_name} {message.from_user.last_name}. Введите ваш ID.' bot.send_message(message.chat.id, mess, parse_mode='html') bot.register_next_step_handler(message, user_name) def user_name(message): global name name = message.text.strip() bot.send_message(message.chat.id, 'Введите пароль.') bot.register_next_step_handler(message, user_password) def user_password(message): password = message.text.strip() conn = sqlite3.connect('Opalami.sql') cur = conn.cursor() cur.execute("INSERT INTO users (name, pass) VALUES ('%s', '%s')" % (name, password)) conn.commit() cur.close() conn.close() markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton(text='Список пользователей', callback_data='users')) bot.send_message(message.chat.id, 'Вы зарегестрированы!', reply_markup=markup) @bot.message_handler(commands=['pogoda']) def pogjda(message): bot.send_message(message.chat.id, 'Напиши название своего города') @bot.callback_query_handler(func=lambda call: True) def callback(call): conn = sqlite3.connect('Opalami.sql') cur = conn.cursor() cur.execute('SELECT * FROM users') users = cur.fetchall() info = '' for el in users: info += f'Имя: {el[1]}, пароль: {el[2]}\n\n' cur.close() conn.close() bot.send_message(call.message.chat.id, info) @bot.message_handler(content_types=['photo']) def Photo_handler(message): markup = types.InlineKeyboardMarkup() btn1 = types.InlineKeyboardButton('Удалить фото', callback_data='delete') btn2 = types.InlineKeyboardButton('Изменить', callback_data='izmena') markup.row(btn1, btn2) bot.reply_to(message, 'Вау, что за валына!', reply_markup=markup) @bot.message_handler(commands=['help']) def website(message): markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton(text="Кнопочка", url='https://pypi.org/project/pyTelegramBotAPI/')) bot.send_message(message.chat.id, 'Вот, держи!', reply_markup=markup) @bot.callback_query_handler(func=lambda callback:True) def callback_message(callback): if callback.data == 'delete': bot.delete_message(callback.message.chat.id, callback.message.message_id-1) elif callback.data == 'izmena': bot.edit_message_text('Edit text',callback.message.chat.id, callback.message.message_id-1) @bot.message_handler(commands=['start']) def start(message): markup = types.ReplyKeyboardMarkup() btn1 = types.KeyboardButton(text = 'Перейти на сайт') btn2 = types.KeyboardButton(text = 'Удалить фото') markup.row(btn1, btn2) # bot.send_message(message.chat.id, "Привет, держи", reply_markup=markup) file = open('photo/KU.jpg', 'rb') bot.send_photo(message.chat.id, file, reply_markup=markup) file.close() bot.register_next_step_handler(message, on_click) def on_click(message): if message.text == 'Перейти на сайт': bot.send_message(message.chat.id, 'Web is here') elif message.text == 'Удалить фото': bot.send_message(message.chat.id, 'Deleted !') @bot.message_handler(content_types=['text']) def weather(message): city = message.text.strip().lower inf_weather = requests.get(f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_weather}') bot.reply_to(message, f'Сейчас там погода: {inf_weather.json()}') @bot.message_handler() def TEXT(message): if message.text.lower() == 'id': bot.send_message(message.chat.id, message.from_user.id) if message.text.lower() == 'date': bot.send_message(message.chat.id, message.date) if message.text.lower() == 'привет' or message.text.lower() == 'hello': bot.send_message(message.chat.id, text=f'И тебе привет, {message.from_user.first_name}') # if message.text.lower() == 'photo': # photo = open('photo/KU.jpg', 'rb') # bot.send_photo(message.chat.id, photo) # photo.close() # bot.polling(none_stop=True)