Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import sqlite3
  2. import telebot
  3.  
  4. bot = telebot.TeleBot("TOKEN")
  5.  
  6.  
  7. def sendToAll():
  8.     with sqlite3.connect('db.db') as conn:
  9.         cur = conn.cursor()
  10.         cur.execute(f'SELECT `user_id` FROM `tgbot`')
  11.         rows = cur.fetchall()
  12.  
  13.         for row in rows:
  14.             bot.send_message(row[0], 'Stream started!')
  15.  
  16.  
  17. def addToDB(id):
  18.     with sqlite3.connect('db.db') as conn:
  19.         cur = conn.cursor()
  20.         cur.execute(f'SELECT COUNT(`id`) FROM `tgbot` WHERE `user_id` = {id}')
  21.  
  22.         if cur.fetchone()[0] == 0:
  23.             cur.execute(f'INSERT INTO `tgbot` (`user_id`) VALUES ({id})')
  24.             conn.commit()
  25.  
  26.  
  27. @bot.message_handler(commands=['alert'])
  28. def alert_users(message):
  29.     if message.chat.id == ADMIN_ID:
  30.         sendToAll()
  31.  
  32.  
  33. @bot.message_handler(commands=['start'])
  34. def main(message):
  35.     addToDB(message.chat.id)
  36.  
  37. bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement