def _add_to_whitelist_callback_handler(self, update, context): delete_callback_message(update, context) send_message(update, context, self._res.ADD_TO_WHITELIST_TEXT, parse_mode=ParseMode.MARKDOWN) return self.ADD_USER
def _edit_script_menu_new_script(self, update, context): delete_callback_message(update, context) if self._check_permission(update): context.chat_data["current_script"] = Script( "script name", "cd", "script description", True) self._edit_script_menu_show_script(update, context) return self.EDIT_SCRIPT send_message(update, context, self._res.ACCESS_DENIED_TEXT) return ConversationHandler.END
def _action_cancelled_handler(self, update, context): delete_callback_message(update, context) if self._check_permission(update): send_message(update, context, self._res.CANCEL_TEXT) if context.chat_data["menu"] is not None: return context.chat_data["menu"](update, context) else: send_message(update, context, self._res.ACCESS_DENIED_TEXT) return ConversationHandler.END
def _edit_script_text_field_handler(self, update, context): delete_callback_message(update, context) field = update.callback_query.data.replace("change_", "") context.chat_data["argument"] = field send_message(update, context, text="`{}`".format( context.chat_data["current_script"].__dict__[field]), parse_mode=ParseMode.MARKDOWN) return self.EDIT_SCRIPT_TEXTFIELD
def _remove_script(self, update, context): delete_callback_message(update, context) script_name = context.chat_data["argument"] script = Script.get_script_from_name(self._scripts, script_name) self._scripts.remove(script) send_message(update, context, text=self._res.SCRIPT_SUCCESSFULLY_REMOVED_TEXT.format( script_name)) save_scripts_json(self._scripts)
def _edit_script_save(self, update, context): delete_callback_message(update, context) if self._check_permission(update): context.chat_data["current_script"].save(self._scripts) save_scripts_json(self._scripts) send_message(update, context, text=self._res.SCRIPT_SUCCESSFULLY_SAVED_TEXT, parse_mode=ParseMode.MARKDOWN) self._edit_script_menu_show_script(update, context) else: send_message(update, context, self._res.ACCESS_DENIED_TEXT) return ConversationHandler.END
def _remove_script_callback_handler(self, update, context): delete_callback_message(update, context) if len(self._scripts) == 0: send_message(update, context, text=self._res.NO_SCRIPTS_TEXT, parse_mode=ParseMode.MARKDOWN) return self._options_command_handler(update, context) send_message(update, context, text=self._res.REMOVE_SCRIPT_TEXT, keyboard=get_inline_keyboard_from_script_list( self._scripts)) return self.REMOVE_SCRIPT
def _remove_from_whitelist_handler(self, update, context): delete_callback_message(update, context) if self._check_permission(update): user_id = update.callback_query.data self._send_confirmation( update, context, self._remove_from_whitelist, argument=user_id, current_menu=self._options_command_handler, ) else: send_message(update, context, self._res.ACCESS_DENIED_TEXT) return ConversationHandler.END
def _show_scripts_callback_handler(self, update, context): delete_callback_message(update, context) if len(self._scripts) == 0: send_message(update, context, self._res.NO_SCRIPTS_TEXT, parse_mode=ParseMode.MARKDOWN) else: for script in self._scripts: send_message(update, context, str(script), parse_mode=ParseMode.MARKDOWN) self._options_command_handler(update, context)
def _remove_from_whitelist_callback_handler(self, update, context): delete_callback_message(update, context) if self._whiteList is None: send_message(update, context, self._res.NO_USERS_IN_WHITELIST_TEXT, parse_mode=ParseMode.MARKDOWN) return self._options_command_handler(update, context) send_message( update, context, self._res.REMOVE_FROM_WHITELIST_TEXT, parse_mode=ParseMode.MARKDOWN, keyboard=get_inline_keyboard_from_string_list(self._whiteList), ) return self.REMOVE_USER
def _remove_script_handler(self, update, context): delete_callback_message(update, context) if self._check_permission(update): send_message(update, context, text=str( Script.get_script_from_name( self._scripts, update.callback_query.data)), parse_mode=ParseMode.MARKDOWN) self._send_confirmation(update, context, self._remove_script, argument=update.callback_query.data, current_menu=self._options_command_handler) else: send_message(update, context, self._res.ACCESS_DENIED_TEXT) return ConversationHandler.END
def _handle_script(self, update, context): """ handle the execution of a script """ if self._check_permission(update): script = Script.get_script_from_name(self._scripts, update.callback_query.data) if script.verbose: for command in script.body.split("\n"): self._handle_shell_input(update, context, command) else: for command in script.body.split("\n"): self.shell.execute_command(command) send_message(update, context, self._res.SCRIPT_DONE_TEXT.format(script.name)) else: send_message(update, context, self._res.ACCESS_DENIED_TEXT) delete_callback_message(update, context) return ConversationHandler.END
def _edit_script_menu_load_script_handler(self, update, context): delete_callback_message(update, context) if self._check_permission(update): if len(self._scripts) != 0: delete_callback_message(update, context) send_message(update, context, text=self._res.SCRIPTS_SHOW_ALL_TEXT, keyboard=get_inline_keyboard_from_script_list( self._scripts)) return self.LOAD_SCRIPT else: send_message(update, context, text=self._res.NO_SCRIPTS_TEXT, parse_mode=ParseMode.MARKDOWN) return self._options_command_handler(update, context) send_message(update, context, self._res.ACCESS_DENIED_TEXT) return ConversationHandler.END
def _edit_script_back(self, update, context): delete_callback_message(update, context) return self._options_command_handler(update, context)
def _toggle_script_verbose_handler(self, update, context): delete_callback_message(update, context) context.chat_data["current_script"].verbose = not context.chat_data[ "current_script"].verbose self._edit_script_menu_show_script(update, context)
def _end_conversation_handler(self, update, context): delete_callback_message(update, context) send_message(update, context, self._res.END_TEXT) return ConversationHandler.END