Guest User

Untitled

a guest
Jan 14th, 2020
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. import telebot
  3. from sqlite3 import *
  4. from telebot import types
  5.  
  6. playersDB = "db\\players.db"
  7.  
  8. token = "937508396:AAGLapcfG5X4I8IzZwVKqRM4H48ppd8ZnLw"
  9. bot = telebot.TeleBot(token)
  10.  
  11. minNameLen = 3
  12.  
  13. global connection
  14. global cursor
  15. connection = connect(playersDB)
  16. cursor = connection.cursor()
  17.  
  18. def updateDB():
  19. connection.close()
  20. connection = connect(playersDB)
  21. cursor = connection.cursor()
  22.  
  23. @bot.message_handler(commands=['start'])
  24. def start(message):
  25. bot.send_message(message.chat.id, "Начинаем регистрацию...")
  26. cursor.execute("INSERT INTO players (id,name,status,level,completed_quests) VALUES (?,?,?,?,?)", (message.chat.id, "not_registered", "player", 0,""))
  27. connection.commit()
  28.  
  29. @bot.message_handler(commands=['register'])
  30. def register(message):
  31. name = message.split(maxsplit=1)[1]
  32. if str(message.chat.id) in [x for y in cursor.execute("SELECT id FROM players") for x in y]:
  33. bot.send_message(message.chat.id, "Вы уже зарегистрировавны")
  34. elif len(str(name)) >= minNameLen:
  35. cursor.execute("UPDATE players SET name=? WHERE id=?", (message.text, message.chat.id))
  36. cursor.execute("UPDATE players SET status=? WHERE id=?", ("registered", message.chat.id))
  37. connection.commit()
  38. else:
  39. bot.send_message(message.chat.id, "Длина имени должна быть больше "+str(minNameLen))
  40.  
  41. @bot.message_handler(content_types=["text"])
  42. def take_message(message):
  43. bot.send_message(message.chat.id, message.text)
  44. @bot.message_handler(commands=['deleteuser'])
  45. def deleteuser(message):
  46. connection = connect(playersDB)
  47. cursor = connection.cursor()
  48. cursor.execute("DELETE FROM players WHERE id=? ", (message.chat.id,))
  49. connection.commit()
  50. connection.close()
  51.  
  52. bot.polling(none_stop=True)
RAW Paste Data