Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- import time
- import schedule
- import threading
- def thread(my_func):
- def wrapper(*args, **kwargs):
- my_thread = threading.Thread(target=my_func, args=args, kwargs=kwargs)
- my_thread.start()
- return wrapper
- def job_usluga():
- for client_id in get_all_ids("ids.txt"):
- try:
- markup_spam = types.InlineKeyboardMarkup()
- item_spam = types.InlineKeyboardButton("Кнопка", callback_data="spam")
- markup_spam.add(item_spam)
- bot.send_message(int(client_id), text="""Тут текст!""", reply_markup=markup_spam)
- except Exception as e:
- print(repr(e))
- print("Неудачка_услуга\nПользователь добавил бота в Черный Список...\n")
- @thread
- def vremya_usluga():
- schedule.every().tuesday.at("18:17").do(job_usluga)
- vremya_usluga()
- def get_all_ids(filename: str) -> bool:
- try:
- with open(filename, "r") as f_read:
- return [id_n.strip() for id_n in f_read.readlines()]
- except FileNotFoundError:
- return False
- @bot.message_handler(commands=['start'], func=lambda call: call.data in ['spam'])
- def welcome(message):
- # База данных
- user_id = message.from_user.id
- print(user_id)
- def add_id(filename: str, client_id: str) -> None:
- ids = set()
- try:
- with open(filename, "r") as f_read:
- ids.update([id_n.strip() for id_n in f_read.readlines()])
- except FileNotFoundError:
- pass
- ids.update([client_id])
- with open(filename, "w") as f_write:
- f_write.writelines([new_id + "\n" for new_id in ids])
- def check_id(filename: str, client_id: str) -> bool:
- try:
- with open(filename, "r") as f_read:
- return client_id in [id_n.strip() for id_n in f_read.readlines()]
- except FileNotFoundError:
- return False
- add_id("ids.txt", str(user_id))
- @bot.callback_query_handler(func=lambda call: True)
- def callback_inline(call):
- if call.data == "spam":
- print("OK")
- bot.polling(none_stop=True, interval=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement