Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. import telebot
  2. import time
  3. import schedule
  4. import threading
  5.  
  6. def thread(my_func):
  7.     def wrapper(*args, **kwargs):
  8.         my_thread = threading.Thread(target=my_func, args=args, kwargs=kwargs)
  9.         my_thread.start()
  10.     return wrapper
  11.  
  12. def job_usluga():
  13.     for client_id in get_all_ids("ids.txt"):
  14.         try:
  15.             markup_spam = types.InlineKeyboardMarkup()
  16.             item_spam = types.InlineKeyboardButton("Кнопка", callback_data="spam")
  17.             markup_spam.add(item_spam)
  18.             bot.send_message(int(client_id), text="""Тут текст!""", reply_markup=markup_spam)
  19.         except Exception as e:
  20.             print(repr(e))
  21.             print("Неудачка_услуга\nПользователь добавил бота в Черный Список...\n")
  22.  
  23. @thread
  24. def vremya_usluga():
  25.     schedule.every().tuesday.at("18:17").do(job_usluga)
  26.  
  27. vremya_usluga()
  28.  
  29. def get_all_ids(filename: str) -> bool:
  30.     try:
  31.         with open(filename, "r") as f_read:
  32.             return [id_n.strip() for id_n in f_read.readlines()]
  33.     except FileNotFoundError:
  34.         return False
  35.  
  36. @bot.message_handler(commands=['start'], func=lambda call: call.data in ['spam'])
  37. def welcome(message):
  38.  
  39.     # База данных
  40.     user_id = message.from_user.id
  41.     print(user_id)
  42.     def add_id(filename: str, client_id: str) -> None:
  43.         ids = set()
  44.         try:
  45.             with open(filename, "r") as f_read:
  46.                 ids.update([id_n.strip() for id_n in f_read.readlines()])
  47.         except FileNotFoundError:
  48.             pass
  49.  
  50.         ids.update([client_id])
  51.  
  52.         with open(filename, "w") as f_write:
  53.             f_write.writelines([new_id + "\n" for new_id in ids])
  54.  
  55.     def check_id(filename: str, client_id: str) -> bool:
  56.         try:
  57.             with open(filename, "r") as f_read:
  58.                 return client_id in [id_n.strip() for id_n in f_read.readlines()]
  59.         except FileNotFoundError:
  60.             return False
  61.  
  62.     add_id("ids.txt", str(user_id))
  63.  
  64. @bot.callback_query_handler(func=lambda call: True)
  65. def callback_inline(call):
  66.     if call.data == "spam":
  67.         print("OK")
  68.  
  69. bot.polling(none_stop=True, interval=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement