From 9f8c5acf525754eda6025abe6333de81180ba595 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 21 Nov 2019 10:39:26 +0000 Subject: [PATCH] add a way to execute commands through bitbotd (use for master-password) --- bitbotctl | 4 ++++ docs/help/setup.md | 2 +- modules/permissions/__init__.py | 10 ++++------ src/Control.py | 7 +++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/bitbotctl b/bitbotctl index 86790c0f..7e8425e8 100755 --- a/bitbotctl +++ b/bitbotctl @@ -24,6 +24,8 @@ SIMPLE = ["rehash", "reload", "stop"] if args.command == "log": arg_parser.add_argument("--level", "-l", help="Log level", default="INFO") +elif args.command == "command": + arg_parser.add_argument("subcommand") elif args.command in SIMPLE: pass else: @@ -53,6 +55,8 @@ _send("0 version 0") if args.command == "log": _send("1 log %s" % args.level) +elif args.command == "command": + _send("1 command %s" % args.subcommand) elif args.command in SIMPLE: _send("1 %s" % args.command) diff --git a/docs/help/setup.md b/docs/help/setup.md index d9ce0e22..94305ce9 100644 --- a/docs/help/setup.md +++ b/docs/help/setup.md @@ -2,7 +2,7 @@ * Move `docs/bot.conf.example` to `~/.bitbot/bot.conf` and fill in the config options you care about. Ones blank or removed will disable relevant functionality. * Run `./bitbotd -a` to add a server. -* Run `./bitbotd -m permissions -M master-password` to get the master admin password (needed to add regular admin accounts) +* Run `./bitbotctl command master-password` to get the master admin password (needed to add regular admin accounts) * Run `./bitbotd` to start the bot. * Join `#bitbot` on a server with the bot (or invite it to another channel) * `/msg register ` to register your nickname with the bot diff --git a/modules/permissions/__init__.py b/modules/permissions/__init__.py index 0311dfa3..639c1b01 100644 --- a/modules/permissions/__init__.py +++ b/modules/permissions/__init__.py @@ -23,12 +23,10 @@ class Module(ModuleManager.BaseModule): self.bot.set_setting("master-password", [hash, salt]) return master_password - def command_line(self, args: str): - if args == "master-password": - master_password = self._master_password() - print("one-time master password: %s" % master_password) - else: - raise ValueError("Unknown command-line argument") + @utils.hook("control.master-password") + def command_line(self, event): + master_password = self._master_password() + return "One-time master password: %s" % master_password @utils.hook("received.command.masterpassword", private_only=True) def master_password(self, event): """ diff --git a/src/Control.py b/src/Control.py index 6f864303..ed5a5351 100644 --- a/src/Control.py +++ b/src/Control.py @@ -104,6 +104,13 @@ class Control(PollSource.PollSource): keepalive = False elif command == "stop": self._bot.stop() + elif command == "command" and data: + subcommand, _, data = data.partition(" ") + output = self._bot._events.on("control").on(subcommand + ).call_for_result(data=data) + if not output == None: + response_data = output + keepalive = False self._send_action(client, response_action, response_data, id) if not keepalive: