Guest User

Untitled

a guest
Jun 6th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.58 KB | None | 0 0
  1. def ready(message, content_type, mestext, caption, file_id, btns):
  2.     uid = message.from_user.id
  3.     text = message.text
  4.     if text == "Добавить кнопку":
  5.         msg = bot.send_message(uid, "Отправьте название кнопки", reply_markup=types.ReplyKeyboardRemove())
  6.         bot.register_next_step_handler(msg, add_name, content_type, mestext, caption, file_id, btns)
  7.     if text == "Отправить рассылку":
  8.         bot.send_message(uid, "Началась рассылка", reply_markup=types.ReplyKeyboardRemove())
  9.         users_file = open('users', 'r')
  10.         users = users_file.read().split('.')
  11.         users_file.close()
  12.         if btns:
  13.             markup = types.InlineKeyboardMarkup()
  14.             for name, link in btns.items():
  15.                 btn = types.InlineKeyboardButton(text=name, url=link)
  16.                 markup.add(btn)
  17.             for user in users:
  18.                 try:
  19.                     if content_type == "text":
  20.                         bot.send_message(user, mestext, reply_markup=markup, parse_mode="HTML")
  21.                         time.sleep(0.06)
  22.                     elif content_type == "photo":
  23.                         if caption:
  24.                             bot.send_photo(user, file_id, caption=caption, reply_markup=markup, parse_mode="HTML")
  25.                             time.sleep(0.06)
  26.                         else:
  27.                             bot.send_photo(user, file_id, reply_markup=markup)
  28.                             time.sleep(0.06)
  29.                     elif content_type == "video":
  30.                         if caption:
  31.                             bot.send_video(user, file_id, caption=caption, reply_markup=markup, parse_mode="HTML")
  32.                             time.sleep(0.06)
  33.                         else:
  34.                             bot.send_video(user, file_id, reply_markup=markup)
  35.                             time.sleep(0.06)
  36.                     elif content_type == "document":
  37.                         if caption:
  38.                             bot.send_document(user, file_id, caption=caption, reply_markup=markup, parse_mode="HTML")
  39.                             time.sleep(0.06)
  40.                         else:
  41.                             bot.send_document(user, file_id, reply_markup=markup)
  42.                             time.sleep(0.06)
  43.                     elif content_type == "animation":
  44.                         if caption:
  45.                             bot.send_animation(user, file_id, caption=caption, reply_markup=markup, parse_mode="HTML")
  46.                             time.sleep(0.06)
  47.                         else:
  48.                             bot.send_animation(user, file_id, reply_markup=markup)
  49.                             time.sleep(0.06)
  50.                 except:
  51.                     pass
  52.         else:
  53.             for user in users:
  54.                 try:
  55.                     if content_type == "text":
  56.                         bot.send_message(user, mestext, parse_mode="HTML")
  57.                         time.sleep(0.06)
  58.                     elif content_type == "photo":
  59.                         if caption:
  60.                             bot.send_photo(user, file_id, caption=caption, parse_mode="HTML")
  61.                             time.sleep(0.06)
  62.                         else:
  63.                             bot.send_photo(user, file_id)
  64.                             time.sleep(0.06)
  65.                     elif content_type == "video":
  66.                         if caption:
  67.                             bot.send_video(user, file_id, caption=caption, parse_mode="HTML")
  68.                             time.sleep(0.06)
  69.                         else:
  70.                             bot.send_video(user, file_id)
  71.                             time.sleep(0.06)
  72.                     elif content_type == "document":
  73.                         if caption:
  74.                             bot.send_document(user, file_id, caption=caption, parse_mode="HTML")
  75.                             time.sleep(0.06)
  76.                         else:
  77.                             bot.send_document(user, file_id)
  78.                             time.sleep(0.06)
  79.                     elif content_type == "animation":
  80.                         if caption:
  81.                             bot.send_animation(user, file_id, caption=caption, parse_mode="HTML")
  82.                             time.sleep(0.06)
  83.                         else:
  84.                             bot.send_animation(user, file_id)
  85.                             time.sleep(0.06)
  86.                 except:
  87.                     pass
  88.         bot.send_message(uid, "Рассылка прошла успешно.")
Advertisement
Add Comment
Please, Sign In to add comment