AsTheSkies

Audibot

Dec 3rd, 2021 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import telebot
  2. import sqlite3
  3.  
  4. # bot
  5. bot = telebot.TeleBot("token")
  6.  
  7.  
  8. @bot.message_handler(commands=['add'])
  9. def add(message):
  10. connect = sqlite3.connect('users.db')
  11. cursor = connect.cursor()
  12.  
  13. cursor.execute("""CREATE TABLE IF NOT EXISTS user_id(
  14. id INTEGER,
  15. info TEXT,
  16. username TEXT
  17. )""")
  18.  
  19. connect.commit()
  20.  
  21. # add values in fields
  22. text = message.text.replace('/add ', '', 1)
  23. user_id = [message.chat.id, text, message.chat.username]
  24. cursor.execute("INSERT INTO user_id(id, info, username) VALUES(?, ?, ?);", user_id)
  25. connect.commit()
  26.  
  27.  
  28. @bot.message_handler(commands=['get'])
  29. def get(message):
  30. connect = sqlite3.connect('users.db')
  31. cursor = connect.cursor()
  32. cursor.execute("SELECT info FROM user_id WHERE info='%s'")
  33. print(cursor.fetchall())
  34.  
  35. if cursor.fetchall() is None:
  36. bot.send_message(message.chat.id, "Вы должны зарегистрироваться с помощью команды /add")
  37. else:
  38. bot.send_message(message.text, '//', message.chat.id)
  39. connect.commit()
  40.  
  41. @bot.message_handler(commands=['delete'])
  42. def delete(message):
  43. pass
  44.  
  45.  
  46. # polling
  47. bot.polling()
  48.  
Add Comment
Please, Sign In to add comment