def handle(update, context): bestie_response_whitelist = [222021705, 148933790] if update.message.from_user["id"] in bestie_response_whitelist: util.log_chat("bestie", update) update.message.reply_text(random_reply())
def handle(update, context): hi_response_whitelist = ["pahagwl", "arkits", "volis2"] if update.message.from_user["username"] in hi_response_whitelist: util.log_chat("hi", update) update.message.reply_text(random_reply())
def handle(update, context): util.log_chat("chutiya", update) response = None try: reply_to_message = update.message.reply_to_message if reply_to_message is not None: og_from = update.message.reply_to_message.from_user else: og_from = update.message.from_user og_sender = extract_pretty_name(og_from) if og_sender != BOT_USERNAME: if reply_to_message is not None: update.message.reply_to_message.reply_text( text="{} is a {}".format(og_sender, acronymify("chutiya")), parse_mode=ParseMode.MARKDOWN, ) else: update.message.reply_text( text="{} is a {}".format(og_sender, acronymify("chutiya")), parse_mode=ParseMode.MARKDOWN, ) else: # DON'T INSULT CHADDI! sticker_to_send = "CAADAQADrAEAAp6M4Ahtgp9JaiLJPxYE" update.message.reply_sticker(sticker=sticker_to_send) except Exception as e: logger.error("[chutiya] Caught Error! e={} \n update.message={} ", e, update.message)
def handle(update, context): util.log_chat("gamble", update) response = gamble(update.message.from_user["id"], update.message.chat["id"], update) update.message.reply_text(response)
def handle(update, context): util.log_chat("superpower", update) response = superpower_countdown_calc() logger.info("[superpower] Returing response={}", response) update.message.reply_text(response)
def handle(update, context): util.log_chat("calc", update) query = update.message.text query = query.split(" ") try: calc_str = " ".join(query[1:]) response = calc_engine(calc_str) except Exception as e: response = str(e) finally: logger.info("[calc] calc_str='{}' ; response='{}'", calc_str, response) update.message.reply_text(response)
def handle(update, context): try: util.log_chat("mom2", update) initiator_id = update.message.from_user["id"] if initiator_id is None: logger.error("[mom2] initiator_id was None!") return if not util.paywall_user(initiator_id, COMMAND_COST): update.message.reply_text( "Sorry! You don't have enough ₹okda! Each /mom2 costs {} ₹okda." .format(COMMAND_COST)) return metrics.mom2_invoker_counter.labels( user_id=update.message.from_user["id"]).inc() protagonist = util.extract_pretty_name_from_tg_user( update.message.from_user) message = mom.extract_target_message(update) if message is None: logger.info("[mom2] message was None!") return response = mom.rake_joke(message, protagonist) logger.info("[mom2] generated response={}", response) if update.message.reply_to_message: update.message.reply_to_message.reply_text(response) metrics.mom2_victim_counter.labels( user_id=update.message.reply_to_message.from_user["id"]).inc() return else: update.message.reply_text(response) return except Exception as e: logger.error( "Caught Error in mom2.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): util.log_chat("reset", update) try: # Extract query... query = update.message.text query = query.split(" ") target = None if not util.is_admin(update.message.from_user["id"]): return # Request includes the username as a mention if update.message.entities: for entity in update.message.entities: if entity.type == "text_mention" and entity.user is not None: target = dao.get_bakchod_by_id(entity.user.id) # Last attempt... try to lookup username in DB if target is None: receiver_username = query[1] # Remove the "@" prefix if receiver_username.startswith("@"): receiver_username = receiver_username[1:] target = dao.get_bakchod_by_username(receiver_username) if target is not None: logger.info("[reset] target={}", util.extract_pretty_name_from_bakchod(target)) target.modifiers = {} dao.insert_bakchod(target) update.message.reply_text( "Reset - " + util.extract_pretty_name_from_bakchod(target)) return except Exception as e: logger.error( "Caught Error in reset.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): try: util.log_chat("aao", update) initiator_id = update.message.from_user["id"] if initiator_id is None: logger.error("[aao] initiator_id was None!") return if not util.paywall_user(initiator_id, COMMAND_COST): update.message.reply_text( "Sorry! You don't have enough ₹okda! Each /aao costs {} ₹okda." .format(COMMAND_COST)) return target_message = mom.extract_target_message(update) if target_message is None: logger.info("[aao] target_message was None!") return magic_word = extract_magic_word(target_message) if magic_word is None: logger.info("[aao] magic_word was None!") return support_word = get_support_word() response = "aao {} {}".format(magic_word, support_word) response = response.lower() logger.info("[aao] generated response={}", response) if update.message.reply_to_message: update.message.reply_to_message.reply_text(response) return else: update.message.reply_text(response) return except Exception as e: logger.error( "Caught Error in aao.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): util.log_chat("about", update) if update.message.reply_to_message: query_id = update.message.reply_to_message.from_user["id"] else: query_id = update.message.from_user["id"] bakchod = dao.get_bakchod_by_id(query_id) if bakchod is None: bakchod = Bakchod.fromUpdate(update) dao.insert_bakchod(bakchod) update.message.reply_text(text=generate_about_response(bakchod), parse_mode=ParseMode.MARKDOWN)
def handle(update, context): util.log_chat("set", update) message = update.message.text message = message.split(" ") if update.message.reply_to_message: for_bakchod = update.message.reply_to_message.from_user["id"] else: for_bakchod = update.message.from_user["id"] og_bakchod = update.message.from_user["id"] response = parse_request(message, for_bakchod, og_bakchod, update) update.message.reply_text(text=response, parse_mode=ParseMode.MARKDOWN)
def handle(update, context): try: util.log_chat("translate", update) if update.message.reply_to_message: text_to_translate = update.message.reply_to_message.text else: update.message.reply_text( "Reply to the message you want to translate!") return if len(text_to_translate) > 2000: logger.debug( "[translate] text_to_translate is too long ({})... trimming to 2000!", len(text_to_translate), ) text_to_translate = text_to_translate[:2000] if util.ratelimit_user(update, "translate", "Translator off-duty... come back later!", 2): return result = translator.translate(text_to_translate) if result.text is None: return response = "<b>Translated from {} to {}:</b> \n <code>{}</code>".format( result.src.upper(), result.dest.upper(), result.text) logger.info("[translate] completed translation! response={}", response) update.message.reply_text(text=response, parse_mode=telegram.ParseMode.HTML) except Exception as e: logger.error( "Caught Error in translate.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): try: util.log_chat("purge", update) end_message_id = update.message.message_id if not util.is_admin(update.message.from_user["id"]): safe_delete_message(context.bot, end_message_id, update.message.chat_id) return start_message_id = extract_start_message_id(update) if start_message_id is None: logger.info("[purge] end_message_id was None!") return logger.info( "[purge] start_message_id={} end_message_id={}", start_message_id, end_message_id, ) for purge_message_id in range(start_message_id, end_message_id): logger.debug( "[purge] deleting message_id={} group_id={}", purge_message_id, update.message.chat_id, ) break_the_loop = safe_delete_message(context.bot, purge_message_id, update.message.chat_id) if break_the_loop: break except Exception as e: logger.error( "Caught Error in default.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): util.log_chat("choose", update) response = None try: random_choice = choose_engine(update.message) response = "I choose... " + random_choice + "!" logger.info("[choose] random_choice={} choices={}", random_choice, update.message.text) except Exception as e: logger.error("[choose] Caught Error! e={} \n update.message={} ", e, update.message) response = """ Couldn't understand that... here is a sample `/choose a,b,c` """ update.message.reply_text(text=response, parse_mode=ParseMode.MARKDOWN)
def handle(update, context): try: util.log_chat("year", update) response = year_progress_response_generator() if response is None: return logger.info("[year] Returning response={}", response) update.message.reply_text(response) except Exception as e: logger.error( "Caught Error in year.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): util.log_chat("rokda", update) if update.message.reply_to_message: bakchod_id = update.message.reply_to_message.from_user["id"] else: bakchod_id = update.message.from_user["id"] bakchod = dao.get_bakchod_by_id(bakchod_id) if bakchod is not None: response = "💰" + util.extract_pretty_name_from_bakchod( bakchod) + " has " + str(round(bakchod.rokda, 2)) + " ₹okda!" logger.info("[rokda] Sending response " + response) update.message.reply_text(response) else: logger.info("[rokda] Couldn't find user") file_id = "CAADAwADrQADnozgCI_qxocBgD_OFgQ" sticker_to_send = file_id update.message.reply_sticker(sticker=sticker_to_send)
def handle(update, context): try: util.log_chat("daan", update) # Extract query... query = update.message.text query = query.split(" ") if len(query) < 2: update.message.reply_text( text="Haat chutiya! Syntax is `/daan @username 786`", parse_mode=ParseMode.MARKDOWN, ) return # Extract Sender by ID sender = dao.get_bakchod_by_id(update.message.from_user["id"]) if sender is None: sender = Bakchod.fromUpdate(update) dao.insert_bakchod(sender) # Extract Receiver receiver = None if update.message.reply_to_message: # Request is a reply to message... Extract receiver from ID receiver = dao.get_bakchod_by_id( update.message.reply_to_message.from_user["id"] ) # Donation can be the rest of the message donation = query[1:] else: # Request includes the username as a mention if update.message.entities: for entity in update.message.entities: if entity.type == "text_mention" and entity.user is not None: receiver = dao.get_bakchod_by_id(entity.user.id) # Last attempt... try to lookup username in DB if receiver is None: receiver_username = query[1] # Remove the "@" prefix if receiver_username.startswith("@"): receiver_username = receiver_username[1:] receiver = dao.get_bakchod_by_username(receiver_username) # Donation can be the rest of the message donation = query[2:] # Handle if receiver could be extracted if receiver is None: if receiver_username: update.message.reply_text(receiver_username + "??? Who dat???") return else: update.message.reply_text("Kisko daan do be????") return # Parse Daan amount try: daan = float("".join(donation)) daan = round(daan, 2) daan = abs(daan) except Exception as e: update.message.reply_text("Kitna ₹okda be???") return logger.info( "[daan] sender={} receiver={} daan={}", util.extract_pretty_name_from_bakchod(sender), util.extract_pretty_name_from_bakchod(receiver), daan, ) if (sender.rokda - daan) < 0: update.message.reply_text("Gareeb saale! You don't have enough ₹okda!") return if sender.id == receiver.id: file_id = "CAADAwADrQADnozgCI_qxocBgD_OFgQ" sticker_to_send = file_id update.message.reply_sticker(sticker=sticker_to_send) return # Commit Daan transaction to DB sender.rokda = sender.rokda - daan dao.insert_bakchod(sender) receiver.rokda = receiver.rokda + daan dao.insert_bakchod(receiver) daan_id = shortuuid.uuid() dao.insert_daan( daan_id, sender.id, receiver.id, daan, str(datetime.datetime.now()) ) update.message.reply_text( text="{} gave {} 🤲 a daan of {} ₹okda! 🎉 \n Daan ID - <code>{}</code>".format( util.extract_pretty_name_from_bakchod(sender), util.extract_pretty_name_from_bakchod(receiver), daan, daan_id, ), parse_mode=ParseMode.HTML, ) return except Exception as e: logger.error( "Caught Error in daan.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): try: random.seed(datetime.datetime.now()) util.log_chat("mom", update) # Get Telegram user id og_sender_id = update.message.from_user["id"] # Check if Bakchod has enough rokda to do a /mom... if check_if_user_can_riposte(og_sender_id): # Get sender's name og_sender_name = util.extract_pretty_name_from_tg_user( update.message.from_user) # Get recipient's name if update.message.reply_to_message: riposte = joke_mom(update.message.reply_to_message.text, og_sender_name) respond_to = util.extract_pretty_name_from_tg_user( update.message.reply_to_message.from_user) else: riposte = joke_mom(update.message.text, og_sender_name) respond_to = og_sender_name if respond_to not in mom_response_blacklist: if random.random() > 0.10: if update.message.reply_to_message: update.message.reply_to_message.reply_text(riposte) else: update.message.reply_text(riposte) else: # User has chance to get protected update.message.reply_text( respond_to + " is protected by a 👁️ Nazar Raksha Kavach") else: if respond_to == BOT_USERNAME: # Don't insult Chaddi! sticker_to_send = "CAADAQADrAEAAp6M4Ahtgp9JaiLJPxYE" update.message.reply_sticker(sticker=sticker_to_send) else: # Protect the users in the blacklist update.message.reply_text( respond_to + " is protected by a 👁️ Nazar Raksha Kavach") else: # Bakchod doesn't have enough rokda :( update.message.reply_text( "Sorry! You don't have enough ₹okda! Each /mom costs 50 ₹okda." ) except Exception as e: logger.error( "Caught Error in mom.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): if update.message.from_user["username"] in hi_response_whitelist: util.log_chat("hi", update) update.message.reply_text(random_reply())
def handle(update, context): util.log_chat("roll", update) try: command = extract_command_from_update(update) if command == "start": create_new_roll = False group_id = get_group_id_from_update(update) if group_id is None: update.message.reply_text(text="Roll only be used in a group!") return current_roll = dao.get_roll_by_id(group_id) if current_roll is None: create_new_roll = True else: # Pre-exisitng roll... check if expired roll_expiry = ciso8601.parse_datetime(current_roll["expiry"]) if roll_expiry <= datetime.datetime.now(): create_new_roll = True # Allow admins to create new rolls if util.is_admin(update.message.from_user["id"]): create_new_roll = True if create_new_roll: # Create new roll... # Set roll rule type rule = get_random_roll_type() # Set the number to required to win roll_number = random.randint(1, 6) # Extract victim from command param... victim = None parsed_victim_username = extract_param_from_update(update) if parsed_victim_username is not None: victim = dao.get_bakchod_by_username( parsed_victim_username) if victim is not None: logger.info( "[roll] Found passed Bakchod username={} in DB", parsed_victim_username, ) # Or else get a Random Bakchod if victim is None: victim = get_random_bakchod(group_id) if victim is None: update.message.reply_text( text="Couldn't get a random Bakchod :(") return # Set the roll winrar to None winrar = None expiry = datetime.datetime.now() + datetime.timedelta(hours=1) dao.insert_roll(group_id, rule, roll_number, victim.id, winrar, expiry) roll = dao.get_roll_by_id(group_id) if roll is None: update.message.reply_text( text="Couldn't start a new roll :(") return pretty_roll = generate_pretty_roll(roll) response = "<b>Started new roulette!</b> " + pretty_roll update.message.reply_text(text=response, parse_mode=telegram.ParseMode.HTML) return else: # Handle when not create_new_roll update.message.reply_text("Chal kat re bsdk!") return elif command == "reset": if util.is_admin(update.message.from_user["id"]): # Remove schedule reset job for job in context.job_queue.jobs(): if (job.name == "reset_roll_effects" and job.context == update.message.chat_id): logger.info( "[roll] Removing pre-scheduled reset_roll_effects job..." ) job.schedule_removal() # Schedule callback for resetting roll effects context.job_queue.run_once(reset_roll_effects, 1, context=update.message.chat_id) return else: update.message.reply_text("Chal kat re bsdk!") return else: # Return roll status for anything else group_id = get_group_id_from_update(update) if group_id is None: update.message.reply_text( text="Roll can only be used in a group!") return current_roll = dao.get_roll_by_id(group_id) if current_roll is None: update.message.reply_text( text= "No active roulette right now. <code>/roll start</code> to start one!", parse_mode=telegram.ParseMode.HTML, ) return else: # Handle expired roll roll_expiry = ciso8601.parse_datetime(current_roll["expiry"]) if roll_expiry <= datetime.datetime.now(): update.message.reply_text( text= "No active roulette right now. <code>/roll start</code> to start one!", parse_mode=telegram.ParseMode.HTML, ) return else: pretty_roll = generate_pretty_roll(current_roll) response = "<b>Current active roulette:</b> {}".format( pretty_roll) update.message.reply_text( text=response, parse_mode=telegram.ParseMode.HTML) return except Exception as e: logger.error( "Caught Error in roll.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): util.log_chat("roll", update) try: command = extract_command_from_update(update) if command == "start": create_new_roll = False group_id = get_group_id_from_update(update) if group_id is None: update.message.reply_text(text="Roll only be used in a group!") return current_roll = dao.get_roll_by_id(group_id) if current_roll is None: create_new_roll = True else: # Pre-exisitng roll... check if expired roll_expiry = ciso8601.parse_datetime(current_roll["expiry"]) if roll_expiry <= datetime.datetime.now(): create_new_roll = True # Allow admins to create new rolls if util.is_admin(update.message.from_user["id"]): create_new_roll = True if create_new_roll: roll = generate_new_roll(update, group_id) if roll is None: update.message.reply_text(text="Couldn't start a new roll :(") return metrics.rolls_started.inc() pretty_roll = generate_pretty_roll(roll) response = "<b>Started new roulette!</b> " + pretty_roll update.message.reply_text( text=response, parse_mode=telegram.ParseMode.HTML ) return else: # Handle when not create_new_roll update.message.reply_text("Chal kat re bsdk!") return elif command == "reset": if util.is_admin(update.message.from_user["id"]): # Remove schedule reset job for job in context.job_queue.jobs(): if ( job.name == "reset_roll_effects" and job.context == update.message.chat_id ): logger.info( "[roll] Removing pre-scheduled reset_roll_effects job..." ) job.schedule_removal() # Schedule callback for resetting roll effects context.job_queue.run_once( reset_roll_effects, 1, context=update.message.chat_id ) return else: update.message.reply_text("Chal kat re bsdk!") return else: # Return roll status for anything else group_id = get_group_id_from_update(update) if group_id is None: update.message.reply_text(text="Roll can only be used in a group!") return current_roll = dao.get_roll_by_id(group_id) if current_roll is None: update.message.reply_text( text="No active roulette right now. <code>/roll start</code> to start one!", parse_mode=telegram.ParseMode.HTML, ) return else: # Handle expired roll roll_expiry = ciso8601.parse_datetime(current_roll["expiry"]) if roll_expiry <= datetime.datetime.now(): update.message.reply_text( text="No active roulette right now. <code>/roll start</code> to start one!", parse_mode=telegram.ParseMode.HTML, ) return else: pretty_roll = generate_pretty_roll(current_roll) response = "<b>Current active roulette:</b> {}".format(pretty_roll) update.message.reply_text( text=response, parse_mode=telegram.ParseMode.HTML ) return except Exception as e: logger.error( "Caught Error in roll.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): try: util.log_chat("webm", update) document = update.message.document # return if the document isn't a webm if not document.file_name.endswith(".webm"): return try: # Count time taken for webm conversion time_start = datetime.datetime.now() # Download the webm file logger.info("[webm] Starting webm download - " + str(document.file_id) + ".webm") webm_file = context.bot.get_file(document.file_id) webm_file.download(WEBM_RESOURCES_DIR + str(document.file_id) + ".webm") logger.info("[webm] Finished downloading webm - " + str(document.file_id) + ".webm") # Webm to mp4 conversion via ffmpeg logger.info("[webm] Starting webm conversion with ffmpeg - " + str(document.file_id) + ".webm") ffmpeg_conversion = subprocess.run([ "ffmpeg", "-i", WEBM_RESOURCES_DIR + str(document.file_id) + ".webm", WEBM_RESOURCES_DIR + str(document.file_id) + ".mp4", ]) if ffmpeg_conversion.returncode != 0: logger.error( "[webm] ffmpeg conversion had a non-zero return code! webm={} ffmpeg_conversion={}", str(document.file_id), ffmpeg_conversion, ) update.message.reply_text( text="(。•́︿•̀。) webm conversion failed (。•́︿•̀。)") return # Calculate time taken to convert time_end = datetime.datetime.now() diff = time_end - time_start pretty_diff = util.pretty_time_delta(diff.seconds) logger.info( "[webm] ffmpeg conversion complete! webm={} time_taken={}", str(document.file_id), pretty_diff, ) original_sender = util.extract_pretty_name_from_tg_user( update.message.from_user) caption = random_webm_caption(original_sender, pretty_diff) logger.info( "[webm] sending converted video webm={} caption={}", str(document.file_id), caption, ) context.bot.send_video( chat_id=update.message.chat_id, video=open(WEBM_RESOURCES_DIR + str(document.file_id) + ".mp4", "rb"), timeout=5000, caption=caption, ) delete_file(WEBM_RESOURCES_DIR + str(document.file_id) + ".webm") delete_file(WEBM_RESOURCES_DIR + str(document.file_id) + ".mp4") except Exception as e: logger.error( "Caught Error in webm.conversion - {} \n {}", e, traceback.format_exc(), ) except Exception as e: logger.error( "Caught Error in webm.handle - {} \n {}", e, traceback.format_exc(), )
def handle(update, context): try: random.seed(datetime.datetime.now()) util.log_chat("mom", update) initiator_id = update.message.from_user["id"] if initiator_id is None: logger.error("[mom] initiator_id was None!") return # Check if Bakchod has enough rokda to do a /mom... if not util.paywall_user(initiator_id, COMMAND_COST): update.message.reply_text( "Sorry! You don't have enough ₹okda! Each /mom costs {} ₹okda." .format(COMMAND_COST)) return # Extract the protagonist - the protagonist <verb> your <victim> last night protagonist = util.extract_pretty_name_from_tg_user( update.message.from_user) # Extract the protagonist - user who shall receive the insult recipient = extract_recipient(update) if recipient is None: logger.info("[mom] recipient was None!") sticker_to_send = "CAADAQADrAEAAp6M4Ahtgp9JaiLJPxYE" update.message.reply_sticker(sticker=sticker_to_send) return # Check if recipient is in the backlist if recipient in mom_response_blacklist: if recipient == BOT_USERNAME: # Don't insult Chaddi! sticker_to_send = "CAADAQADrAEAAp6M4Ahtgp9JaiLJPxYE" update.message.reply_sticker(sticker=sticker_to_send) return else: # Protect the users in the blacklist update.message.reply_text( recipient + " is protected by a 👁️ Nazar Raksha Kavach") return # Extract the message for base the insult on message = extract_target_message(update) if message is None: logger.info("[mom] message was None!") sticker_to_send = "CAADAQADrAEAAp6M4Ahtgp9JaiLJPxYE" update.message.reply_sticker(sticker=sticker_to_send) return # Generate the response if random.random() > 0.50: logger.info( "[mom] generating response with rake - protagonist={} message={}", protagonist, message, ) response = rake_joke(message, protagonist) else: logger.info( "[mom] generating response with spacy - protagonist={} message={}", protagonist, message, ) response = spacy_joke(message, protagonist) if random.random() > 0.05: if update.message.reply_to_message: update.message.reply_to_message.reply_text(response) else: update.message.reply_text(response) else: # User has chance to get protected update.message.reply_text( recipient + " is protected by a 👁️ Nazar Raksha Kavach") # Update metrics metrics.mom_invoker_counter.labels( user_id=update.message.from_user["id"]).inc() return except Exception as e: logger.error( "Caught Error in mom.handle - {} \n {}", e, traceback.format_exc(), ) return
def handle(update, context): util.log_chat("quotes", update) try: # Extract query... query = update.message.text query = query.split(" ") command = None try: command = query[1].lower() except: command = "random" if command == "add": if update.message.reply_to_message.text: response = add_quote(update) update.message.reply_text(text=response, parse_mode=ParseMode.MARKDOWN) elif command == "remove": if util.is_admin(update.message.from_user["id"]): try: id_to_remove = query[2] except: update.message.reply_text( text="Please include the Quote ID you want to remove!", parse_mode=ParseMode.MARKDOWN, ) return response = remove_quote(id_to_remove) else: response = "Chal kat re bsdk!" update.message.reply_text(text=response, parse_mode=ParseMode.MARKDOWN) elif command == "get": response = "" try: quote_id = query[2] except: update.message.reply_text( text="Please include the Quote ID you want to get!", parse_mode=ParseMode.MARKDOWN, ) return quote = get_quote_by_id(quote_id) if quote is None: group_id = util.get_group_id_from_update(update) if group_id is None: update.message.reply_text(text="Can't run this command here!") return # Return a random quote random_quote = get_random_quote(group_id) if random_quote is None: logger.info("[quotes] No quotes found! - group_id={}", group_id) update.message.reply_text( text="No quotes found for this Group! You can add quotes with `/quotes add`", parse_mode=ParseMode.MARKDOWN, ) return response = "Couldn't find quote with ID `{}`... but here's a random one - \n".format( quote_id ) pretty_quote = generate_pretty_quote(quote) response = response + pretty_quote update.message.reply_text(text=response, parse_mode=ParseMode.MARKDOWN) elif command == "join": response = "" try: quote_id = query[2] except: update.message.reply_text( text="Please include the Quote ID you want to join!", parse_mode=ParseMode.MARKDOWN, ) return quote = get_quote_by_id(quote_id) if quote is None: update.message.reply_text( text="Couldn't find quote with ID `{}`!".format(quote_id), parse_mode=ParseMode.MARKDOWN, ) return response = join_quotes(quote, update) update.message.reply_text(text=response, parse_mode=ParseMode.MARKDOWN) else: # Enforce rate limiting on getting random quotes bakchod = dao.get_bakchod_by_id(update.message.from_user.id) history = bakchod.history if history is None: history = {} two_min_ago = datetime.datetime.now() - datetime.timedelta(minutes=2) if "random_quote_get" in history: last_time_get = ciso8601.parse_datetime(history["random_quote_get"]) if last_time_get > two_min_ago: logger.info("[quotes] request random quote too soon... skipping") update.message.reply_text( "Quotes ki dukan band hai... come back later!" ) return history["random_quote_get"] = datetime.datetime.now() bakchod.history = history dao.insert_bakchod(bakchod) group_id = util.get_group_id_from_update(update) if group_id is None: update.message.reply_text(text="Can't run this command here!") return # Return a random quote random_quote = get_random_quote(group_id) if random_quote is None: logger.info("[quotes] No quotes found! - group_id={}", group_id) update.message.reply_text( text="No quotes found for this Group! You can add quotes with `/quotes add`", parse_mode=ParseMode.MARKDOWN, ) return logger.info("[quotes] Got a random quote '{}", random_quote) pretty_quote = generate_pretty_quote(random_quote) update.message.reply_text(text=pretty_quote, parse_mode=ParseMode.MARKDOWN) return except Exception as e: logger.error( "Caught Error in quotes.handle - {} \n {}", e, traceback.format_exc(), )