Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- import telebot
- bot = telebot.TeleBot("TOKEN")
- def sendToAll():
- with sqlite3.connect('db.db') as conn:
- cur = conn.cursor()
- cur.execute(f'SELECT `user_id` FROM `tgbot`')
- rows = cur.fetchall()
- for row in rows:
- bot.send_message(row[0], 'Stream started!')
- def addToDB(id):
- with sqlite3.connect('db.db') as conn:
- cur = conn.cursor()
- cur.execute(f'SELECT COUNT(`id`) FROM `tgbot` WHERE `user_id` = {id}')
- if cur.fetchone()[0] == 0:
- cur.execute(f'INSERT INTO `tgbot` (`user_id`) VALUES ({id})')
- conn.commit()
- @bot.message_handler(commands=['alert'])
- def alert_users(message):
- if message.chat.id == ADMIN_ID:
- sendToAll()
- @bot.message_handler(commands=['start'])
- def main(message):
- addToDB(message.chat.id)
- bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement