Advertisement
y2kbug

Untitled

May 31st, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. @run_async
  2. def request_acceptable_price(bot, update):
  3. do_stuff()
  4.  
  5. job_queue.run_once(wait_for_price, when=1, context={
  6. 'client': get_uber_client(update.message.chat.id),
  7. 'chat_id': update.message.chat.id,
  8. 'message_id': data['last_message_id'],
  9. 'from_latitude': data['from_latitude'],
  10. 'from_longitude': data['from_longitude'],
  11. 'to_latitude': data['to_latitude'],
  12. 'to_longitude': data['to_longitude'],
  13. 'capacity': data['wait']['capacity'],
  14. 'price': price,
  15. 'msg_ln': msg_ln
  16. }, name=update.message.chat.id)
  17.  
  18. return CANCEL_REQ
  19.  
  20.  
  21. def wait_for_price(bot, job):
  22. do_stuff()
  23.  
  24. job_queue.run_once(wait_for_price, when=10, context=job.context, name=int(job.context['chat_id']))
  25.  
  26. return CANCEL_REQ
  27.  
  28.  
  29. @run_async
  30. def cancel_request(bot, update):
  31. connection = persist.connection()
  32. cursor = connection.cursor()
  33. cursor.execute("SELECT `data` FROM `chat` WHERE `chat_id` = %s LIMIT 1", [
  34. update.callback_query.message.chat.id
  35. ])
  36. data = json.loads(cursor.fetchone()[0])
  37.  
  38. if 'ride' in data:
  39. client = get_uber_client(update.callback_query.message.chat.id)
  40. client.cancel_current_ride()
  41. else:
  42. jobs = job_queue.get_jobs_by_name(name=update.callback_query.message.chat.id)
  43. for job in jobs:
  44. job.schedule_removal()
  45.  
  46. updater.bot.edit_message_text(
  47. chat_id=update.callback_query.message.chat.id,
  48. message_id=data['last_message_id'],
  49. text=EMOJI_STATUS + 'You have cancelled'
  50. )
  51.  
  52. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement