Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import telebot
- from sqlite3 import *
- from telebot import types
- playersDB = "db\\players.db"
- token = "937508396:AAGLapcfG5X4I8IzZwVKqRM4H48ppd8ZnLw"
- bot = telebot.TeleBot(token)
- minNameLen = 3
- global connection
- global cursor
- connection = connect(playersDB)
- cursor = connection.cursor()
- def updateDB():
- connection.close()
- connection = connect(playersDB)
- cursor = connection.cursor()
- @bot.message_handler(commands=['start'])
- def start(message):
- bot.send_message(message.chat.id, "Начинаем регистрацию...")
- cursor.execute("INSERT INTO players (id,name,status,level,completed_quests) VALUES (?,?,?,?,?)", (message.chat.id, "not_registered", "player", 0,""))
- connection.commit()
- @bot.message_handler(commands=['register'])
- def register(message):
- name = message.split(maxsplit=1)[1]
- if str(message.chat.id) in [x for y in cursor.execute("SELECT id FROM players") for x in y]:
- bot.send_message(message.chat.id, "Вы уже зарегистрировавны")
- elif len(str(name)) >= minNameLen:
- cursor.execute("UPDATE players SET name=? WHERE id=?", (message.text, message.chat.id))
- cursor.execute("UPDATE players SET status=? WHERE id=?", ("registered", message.chat.id))
- connection.commit()
- else:
- bot.send_message(message.chat.id, "Длина имени должна быть больше "+str(minNameLen))
- @bot.message_handler(content_types=["text"])
- def take_message(message):
- bot.send_message(message.chat.id, message.text)
- @bot.message_handler(commands=['deleteuser'])
- def deleteuser(message):
- connection = connect(playersDB)
- cursor = connection.cursor()
- cursor.execute("DELETE FROM players WHERE id=? ", (message.chat.id,))
- connection.commit()
- connection.close()
- bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement