def mark_user_as_present(self, bot, update): """Save User status has present.""" chat = update.callback_query.message.chat user = User.objects(id=chat.id).first() status = Status(state=HERE, reason="Present", user_id=chat.id, user_name=user.name) Report.objects.add_status(date=datetime.now().date(), status=status) bot.edit_message_text( chat_id=chat.id, message_id=update.callback_query.message.message_id, text=emojize("*Here* :wink:", use_aliases=True), parse_mode=ParseMode.MARKDOWN) reply_markup = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup update.callback_query.message. \ reply_text(emojize(":thumbsup:", use_aliases=True), reply_markup=reply_markup) return STATES.END
def update_group_manager_keyboard(self, bot, manager, group_name): markup = ManuKeyboard(admin=manager.is_admin, manager=manager.is_manager).markup bot.send_message(chat_id=manager.id, text='From now on you are manager of {group_name}'. format(group_name=group_name), reply_markup=markup)
def _callback(self, bot, update, user): """Send a message when the command /start is issued.""" message = update.message name_message = ":guardsman: {name}".format(name=user.name) keyboard = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup message.reply_text(emojize(name_message, use_aliases=True), reply_markup=keyboard)
def status_message_response(self, update, date, state, reason, user): message = self.STATUS_MESSAGE_FORMAT.format(date=date, state=state, reason=reason) reply_markup = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup update.message.reply_text(text=emojize(message, use_aliases=True), parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup)
def validate_password(self, bot, update): message = update.message chat = message.chat user = User.objects(id=chat.id).first() if user: if message.text.strip() == self.PASSWORD.strip(): user.is_admin = True user.save() messagge = ":tada::confetti_ball::tada::confetti_ball: " \ "YOU ARE ADMIN " \ ":tada::confetti_ball::tada::confetti_ball:" markup = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup message.reply_text(emojize(messagge, use_aliases=True), reply_markup=markup) else: markup = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup message.reply_text( emojize(":gun: Wrong Password :gun:", use_aliases=True), reply_markup=markup) else: markup = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup message.reply_text("You should mount as a user first, type /start", reply_markup=markup) return STATES.END
def add_group_items(self, bot, update, chat_data): group = chat_data["group"] message_text = update.message.text if message_text == "Remove": update.message.reply_text(emojize(":thumbsup:", use_aliases=True)) if len(group.items) != 0: group.items.pop() self.send_group_items(group, update) return if message_text == "Done": markup = ManuKeyboard(admin=chat_data["admin"].is_admin, manager=chat_data["admin"].is_manager).markup update.message.reply_text(emojize(":thumbsup:", use_aliases=True), reply_markup=markup) group.manager.save() group.save() chat_data.clear() self.update_group_manager_keyboard(bot, group.manager, group.name) return STATES.END if message_text not in self.posibole_items(group): update.message.reply_text( emojize('This option is not possible:tired_face:', use_aliases=True)) return id = int(message_text.split("/")[-1]) if group.type == "Users" \ else message_text item = None if group.type == "Users": item = User.objects(id=id).first() if group.type == "Groups": item = Group.objects(name=id).first() if item is None: update.message.reply_text( emojize(':shit:Not exist please select from the ' 'keyboard:shit:', use_aliases=True)) return group.items.append(item) self.send_group_items(group, update)
def _callback(self, bot, update, user): self.logger.debug("got message: %s", update.message.text) if user.is_admin is False: print("Unauthorized admin access denied for {}.".format(user.id)) return here, not_here, not_specified = self.get_users_status() statuses = [] if len(here) != 0: users = [ "\u200E\t\t\t:bust_in_silhouette: {name}".format( name=user_name) for user_name in here ] statuses.append( self.STATUS_PATTERN.format(symbol=":heavy_check_mark:", status="Here", users="\n".join(users))) if len(not_here) != 0: users = [ "\u200E\t\t\t:bust_in_silhouette: {name}\n\u200E\t\t\t\t\t\t\t:pencil2:{reason}" .format(name=user_name, reason=reason) for user_name, reason in not_here ] statuses.append( self.STATUS_PATTERN.format(symbol=":x:", status="Not Here", users="\n".join(users))) if len(not_specified) != 0: users = [ "\u200E\t\t\t:bust_in_silhouette: {name}".format( name=user_name) for user_name in not_specified ] statuses.append( self.STATUS_PATTERN.format(symbol=":question:", status="Not Specified", users="\n".join(users))) reply_markup = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup user_status_report = "\n".join(statuses) update.message.reply_text(emojize(user_status_report, use_aliases=True), reply_markup=reply_markup)
def send_users_guoup_status(self, group, update): here, not_here, not_specified = self.get_users_group_status(group) statuses = [] if len(here) != 0: users = [ "\t\t\t:bust_in_silhouette: {name}".format(name=user_name) for user_name in here ] statuses.append( self.STATUS_PATTERN.format(symbol=":heavy_check_mark:", status="Here", users="\n".join(users))) if len(not_here) != 0: users = [ "\t\t\t:bust_in_silhouette: {name}:\n\t\t\t\t:pencil2:{reason}" .format(name=user_name, reason=reason) for user_name, reason in not_here ] statuses.append( self.STATUS_PATTERN.format(symbol=":x:", status="Not Here", users="\n".join(users))) if len(not_specified) != 0: users = [ "\t\t\t:bust_in_silhouette: {name}".format(name=user_name) for user_name in not_specified ] statuses.append( self.STATUS_PATTERN.format(symbol=":question:", status="Not Specified", users="\n".join(users))) reply_markup = ManuKeyboard(admin=group.manager.is_admin, manager=group.manager.is_manager).markup user_group_status_report = \ "{group_name}\n".format(group_name=group.name) + "\n".join(statuses) update.message.reply_text(emojize(user_group_status_report, use_aliases=True), reply_markup=reply_markup)
def save_not_here_reason(self, bot, update): """Save user state as 'not here' with given reason.""" chat = update.message.chat user = User.objects(id=chat.id).first() status = Status(state=NOT_HERE, reason=update.message.text, user_id=chat.id, user_name=user.name) Report.objects.add_status(date=datetime.now().date(), status=status) reply_markup = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup message = emojize('got it!! thanks :punch:', use_aliases=True) update.message.reply_text(message) update.message.reply_text(text=emojize(":thumbsup:", use_aliases=True), reply_markup=reply_markup) return STATES.END
def send_message(self, bot, update, chat_data): admin = chat_data["admin"] message = emojize(self.BROADCAST_MESSAGE.format( user_name=admin.name, message=update.message.text), use_aliases=True) for user_id in User.objects.values_list("id"): self.logger.debug("Send message to %s by Broadcast from %s", user_id, admin.name) bot.send_message(chat_id=user_id, text=message, parse_mode=ParseMode.MARKDOWN) reply_markup = ManuKeyboard(admin=admin.is_admin, manager=admin.is_manager).markup update.message.reply_text(emojize("Done:thumbsup:", use_aliases=True), reply_markup=reply_markup) return STATES.END
def _callback(self, bot, update): """Send a message when the command /start is issued.""" self.logger.debug("got message: %s", update.message.text) chat = update.message.chat name = self.USER_NAME_FORMAT.format(first_name=chat.first_name, last_name=chat.last_name) \ if chat.last_name else chat.first_name user = User.objects(id=chat.id).modify(upsert=True, new=True, name=name) self.logger.debug("Saving user details on db") user.save() self.logger.debug("Successfully saved user") keyboard = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup update.message.reply_text('You have been mounted successfully', reply_markup=keyboard)
def set_user_name(self, bot, update): message = update.message chat = message.chat user = User.objects(id=chat.id).modify(upsert=True, name=message.text) name_header = ":paperclip: Your name have been set" name = ":guardsman: *{name}*".encode("utf-8").format( name=message.text.encode("utf-8")) name_message = self.USER_NAME_MESSAGE_FORMAT.format( header=name_header.decode("utf-8"), name=name.decode("utf-8")) reply_markup = ManuKeyboard(admin=user.is_admin, manager=user.is_manager).markup update.message.reply_text(text=emojize(name_message, use_aliases=True), parse_mode=ParseMode.MARKDOWN, reply_markup=reply_markup) return STATES.END
def group_status(self, bot, update, chat_data): self.logger.debug("got message: %s", update.message.text) manager = chat_data["manager"] groups = Group.objects(manager=manager) if len(groups) == 0: reply_markup = ManuKeyboard(admin=manager.is_admin, manager=manager.is_manager).markup update.message.reply_text(text="You have no groups", reply_markup=reply_markup) return STATES.END if len(groups) == 1: self.send_users_guoup_status(groups[0], update) return STATES.END optional_groups = [group.name for group in groups] markup = GeneralKeyboard(option_list=optional_groups).markup update.message.reply_text(emojize( 'OK, select group name' ':grey_exclamation::grey_exclamation:', use_aliases=True), reply_markup=markup) return STATES.SELECT_GROUP