def mention(self, update, context: CallbackContext): Queue.add(update.message.chat.id, update.message.message_id) chat_id = update.message.chat.id team = update.message.text if not re.match(f'^({HandlerHelpers.make_teams_regex(chat_id)})$', team): message = update.message.reply_text(f'Team "{team}" wasn\'t found, try again') Queue.add(message.chat.id, message.message_id) return Mention.MENTION members = HandlerHelpers.get_team_members(chat_id, team) if members: update.message.reply_text( ' '.join(members), reply_markup=ReplyKeyboardRemove(remove_keyboard=True) ) else: message = update.message.reply_text( 'Members weren\'t found or something went wrong', reply_markup=ReplyKeyboardRemove(remove_keyboard=True) ) Queue.add(message.chat.id, message.message_id) Queue.clean(update.message.chat.id, timeout=30) return Mention.CHOOSING_END
def start(self, update: Update, context: CallbackContext): Queue.add(update.message.chat.id, update.message.message_id) chat_id = update.message.chat.id if not HandlerHelpers.check_teams_existence(update): return AddMembers.CHOOSING_END markup = ReplyKeyboardMarkup(map(lambda x: [x], HandlerHelpers.get_teams(chat_id)), one_time_keyboard=True) message = update.message.reply_text( f'Choose a team', reply_markup=markup ) Queue.add(message.chat.id, message.message_id) return AddMembers.CHOOSING_TEAM
def get(self, update: Update, context: CallbackContext): Queue.add(update.message.chat.id, update.message.message_id) chat_id = update.message.chat.id teams = HandlerHelpers.get_teams(chat_id) if len(teams) > 0: message = update.message.reply_text(', '.join(teams)) Queue.add(message.chat.id, message.message_id, timeout=300) else: message = update.message.reply_text('No teams were found') Queue.add(message.chat.id, message.message_id) Queue.clean(update.message.chat.id) return GetTeams.GETTING_END
def choose_members(self, update, context: CallbackContext): Queue.add(update.message.chat.id, update.message.message_id) chat_id = update.message.chat.id team = context.user_data['team'] members = list( filter( lambda x: x.startswith('@') and x in HandlerHelpers.get_team_members(chat_id, team), update.message.text.split(' '))) if members: App.db.get_teams().find_one_and_update( { 'chat_id': chat_id, 'name': team, }, { '$pull': { 'members': { '$in': members, }, }, }) message = update.message.reply_text( f'Members who were removed from "{team}" team: {" ".join(members)}' ) Queue.add(message.chat.id, message.message_id) else: message = update.message.reply_text( f'No members were removed from the team "{team}"') Queue.add(message.chat.id, message.message_id) Queue.clean(update.message.chat.id, timeout=30) return RemoveMembers.CHOOSING_END
def choose_members(self, update: Update, context: CallbackContext): Queue.add(update.message.chat.id, update.message.message_id) chat_id = update.message.chat.id team = context.user_data['team'] # set is used to remove duplicated members = list( set(filter( lambda x: re.match(r'^@[0-9a-z._-]{5,32}$', x.lower(), re.IGNORECASE) and x not in HandlerHelpers.get_team_members(chat_id, team), update.message.text.split(' ') )) ) if members: App.db.get_teams().find_one_and_update({ 'chat_id': chat_id, 'name': team, }, { '$push': { 'members': { '$each': members, }, }, }) message = update.message.reply_text( f'Greeting new members of the "{team}" team: {" ".join(members)}' ) Queue.add(message.chat.id, message.message_id) else: message = update.message.reply_text( f'No members were added to the team "{team}"' ) Queue.add(message.chat.id, message.message_id) Queue.clean(update.message.chat.id, timeout=30) return AddMembers.CHOOSING_END