def unmute_everyone(): mwelog.info("Unmuting everyone") all_users = get_all_users() for user in all_users: user.muted = False session = database.get_session() database.commit(session)
def send_review_worth_more(self, context: CallbackContext): self._clear_old_notifications() for user in get_all_users(): self._send_notification(context, user.id, user.language.get(Token.REVIEW_WORTH_MORE), NotificationType.REVIEW_WORTH_MORE, THUMBS_UP_STICKER, ParseMode.HTML) time.sleep(0.3)
def stats(update: Update, context: CallbackContext): message = update.message.text.replace("/announce ", "") if len(message) > 10: for user in get_all_users(): try: send_message_to_user(context.bot, user, message) time.sleep(0.3) except Exception as ex: mwelog.exception(ex)
def clear_scores_for_today(): mwelog.info("Clearing scores for today") all_users = get_all_users() for user in all_users: user.score_today_en = 0 user.score_today_tr = 0 user.score_today_it = 0 session = database.get_session() database.commit(session) scoreboard.clear()
def send_i_need_x_examples(self, context: CallbackContext): self._clear_old_notifications() language = mwexpress_config.language todays_mwe = get_todays_mwe(language) session = database.get_session() submission_count_now = session.query(Submission).filter( Submission.mwe == todays_mwe).count() if submission_count_now < 100: for user in get_all_users(): self._send_notification( context, user.id, user.language.get(Token.TODAYS_TARGET) % (100 - submission_count_now), NotificationType.I_NEED_X_EXAMPLES, SAD_RAIN_STICKER) time.sleep(0.3)
def claim_email_announcement(update: Update, context: CallbackContext): mwelog.info("Sending claim email announcement to champions") user = get_user_from_update(update) if user.id == mwexpress_config.moderator or user.id == 1065263859: for user in get_all_users(): if user.became_champion: try: mwelog.info( f"Sending claim email message to {user.username}") context.bot.send_sticker(user.id, EXCITED_STICKER) context.bot.send_message( user.id, user.language.get(Token.CHAMP_BUT_NO_EMAIL)) time.sleep(0.5) except Exception as ex: mwelog.exception(str(ex))
def send_game_started_again_with_awards(update: Update, context: CallbackContext): mwelog.info("Sending game started again message to all users") user = get_user_from_update(update) if user.id == mwexpress_config.moderator or user.id == 1065263859: for user in get_all_users(): try: mwelog.info( f"Sending game started again message to {user.username}") context.bot.send_sticker(user.id, EXCITED_STICKER) send_message_to_user( context.bot, user, user.language.get(Token.GAME_STARTED_AGAIN_ANNOUNCEMENT)) time.sleep(0.5) except Exception as ex: mwelog.exception(str(ex))
def send_game_starting_message_to_all() -> None: mwelog.info("Sending game started message to all users") unmute_everyone() all_users = get_all_users() for user in all_users: try: mwexpress_bot.bot.send_sticker(user.id, GOOD_MORNING_STICKER) send_message_to_user(mwexpress_bot.bot, user, user.language.get(Token.GAME_STARTED)) todays_mwe = get_todays_mwe(user.language) send_message_to_user( mwexpress_bot.bot, user, user.language.get(Token.TODAYS_MWE_REPLY_TEXT) % (todays_mwe.name, todays_mwe.meaning), reply_markup=Keyboard.main(user), parse_mode=ParseMode.HTML) time.sleep(0.3) except Exception as ex: mwelog.exception(str(ex)) mwelog.info("Sent game started message to all users")