コード例 #1
0
    def unload(update: Update, context: CallbackContext):
        if not user_is_admin(update.message.from_user.id):
            update.message.reply_text(
                "Error: You are not authorized to unload modules")
            return

        try:
            module_name = update.message.text.split(' ', 1)[1]
        except IndexError:
            update.message.reply_text("Error: Module name not provided")
            return

        if module_name == "core":
            update.message.reply_text(
                "Error: You can't unload module used for loading/unloading modules"
            )
            return

        modules = context.dispatcher.modules
        for module in modules:
            if module_name == module.name:
                context.dispatcher.unload_module(module)
                update.message.reply_text(f"Module {module_name} unloaded")
                return

        update.message.reply_text("Error: Module not found")
コード例 #2
0
ファイル: __init__.py プロジェクト: ender1324/fluid-homebot
    def shell(update: Update, context: CallbackContext):
        if not user_is_admin(update.message.from_user.id):
            update.message.reply_text(
                "Error: You are not authorized to load modules")
            return

        if len(update.message.text.split(' ', 1)) < 2:
            update.message.reply_text("No command provided")
            return

        command = update.message.text.split(' ', 1)[1]
        try:
            process = subprocess.check_output(command,
                                              shell=True,
                                              executable="/bin/bash",
                                              stderr=subprocess.STDOUT,
                                              universal_newlines=True)
        except subprocess.CalledProcessError as e:
            returncode = e.returncode
            output = e.output
        else:
            returncode = 0
            output = process

        update.message.reply_text(f"Command: {command}\n"
                                  f"Return code: {returncode}\n\n"
                                  f"Output:\n"
                                  f"{output}\n")
コード例 #3
0
ファイル: __init__.py プロジェクト: HyperNotAryanX97/HomeBot
	def ci(update: Update, context: CallbackContext):
		if not user_is_admin(update.message.from_user.id):
			update.message.reply_text("Error: You are not authorized to use CI function of this bot.\n"
									  "Ask to who host this bot to add you to the authorized people list")
			return

		if get_config("CI_CHANNEL_ID") == "":
			update.message.reply_text("Error: CI channel or user ID not defined")
			LOGE("CI channel or user ID not defined")
			return

		parser = CIParser(prog="/ci")
		parser.set_output(update.message.reply_text)
		parser.add_argument('project', help='CI project',
							nargs='?', default=None,)
		parser.add_argument('-s', '--status',
							action='store_true', help='show queue status')

		args, project_args = parser.parse_known_args(context.args)

		if args.status:
			update.message.reply_text(queue_manager.get_formatted_queue_list())
			return

		if args.project is None:
			parser.error("Please specify a project")

		try:
			project_class = import_module(f"homebot.modules.ci.projects.{args.project}", package="Project").Project
		except ModuleNotFoundError:
			update.message.reply_text(f"Error: Project script not found")
			return
		except Exception as e:
			text = "Error: Error while importing project:"
			text += format_exception(e)
			update.message.reply_text(text)
			LOGE(text)
			return

		try:
			project = project_class(update, context, project_args)
		except Exception as e:
			text = "Error: Project class initialization failed:\n"
			text += format_exception(e)
			update.message.reply_text(text)
			LOGE(text)
			return

		workflow = Workflow(project)
		queue_manager.put(workflow)
		update.message.reply_text("Workflow added to the queue")
		LOGI("Workflow added to the queue")