Advertisement
are_you_sure

Untitled

May 26th, 2022
758
335 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def say_hello_mass(context: CallbackContext):
  2.     """React on command"""
  3.     # context.bot_data.data = collections.deque([[message_to_user1, user1], [message_to_user2, user2]])
  4.     context.bot_data.users = {...}  # some data inside already
  5.     context.bot_data.users.update({user1.id: "Hello", user2.id: "Bye"})
  6.     context.job_queue.run_once(callback=say_hello_mass_job, when=0)
  7.  
  8.  
  9. def say_hello_mass_job(update: Update, context: CallbackContext):
  10.     """Here need to be vigilant to no overwrite a dict/queue with a new call,
  11.       so preferable thar the dict/queue item will contain every required data.
  12.       Therefore, it should be created during app startup and in future only append to it
  13.    """
  14.     for text, user in context.bot_data.users.items():  # Not sure if enumerate will work here
  15.         say_hello_personal_job(user, text, context)
  16.  
  17.  
  18. def say_hello_personal_job(user, text, context):
  19.     if user.conversation_data is not None and user is not None:
  20.         context.bot.send_message(chat_id=user.id, message=context.job.context)
  21.         context.bot_data.data[user.id] = None  # Delete are preferable but may break the order
  22.         time.sleep(1)  # UPD
  23.  
  24.  
  25. def end_conversation(context):
  26.     context.job_queue.run_once(callback=say_hello_personal_job, when=0)  # In
  27.     return CH.END
  28.  
Advertisement
RAW Paste Data Copied
Advertisement