import telebot
import sqlite3
import config
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands = ['start'], content_types = ['text'])
def start(message):
answer = bot.send_message(message.chat.id, 'Логин:')
bot.register_next_step_handler(answer, entry_login)
def entry_login(message):
user_id = str(message.from_user.id).replace('(', '').replace(')', '').replace(',', '')
user_login = message.text
print(user_id)
print(user_login)
answer = bot.send_message(message.chat.id, 'Пароль:')
bot.register_next_step_handler(answer, entry_password)
@bot.message_handler(content_types = ['text'])
def entry_password(message):
user_password = message.text
print(user_password)
answer = bot.send_message(message.chat.id, 'Группа:')
bot.register_next_step_handler(answer, entry_group)
@bot.message_handler(content_types = ['text'])
def entry_group(message):
user_group = message.text
print(user_group)
answer = bot.send_message(message.chat.id, 'Входим...')
bot.register_next_step_handler(answer, database)
@bot.message_handler(content_types = ['text'])
def database(message):
db = sqlite3.connect('database.db', check_same_thread = False)
cursor = db.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
user_id INT UNIQUE,
user_login VARCHAR(255),
user_password VARCHAR(255),
user_group INT
)''')
cursor.execute('INSERT INTO users (user_id, user_login, user_password, user_group) VALUES (?, ?, ?, ?)', (user_id, user_login, user_password, user_group,))
db.commit()
bot.enable_save_next_step_handlers(delay = 2)
bot.load_next_step_handlers()
if __name__ == '__main__':
bot.infinity_polling(True)