aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2019-11-21 10:39:26 +0000
committerGravatar jesopo2019-11-21 10:39:26 +0000
commit9f8c5acf525754eda6025abe6333de81180ba595 (patch)
tree09d9a620797ba0bfbd09ebf62635b9273b51e18c
parentsupport "$$" as a literal "$" in alias arg replacements (diff)
add a way to execute commands through bitbotd (use for master-password)
-rwxr-xr-xbitbotctl4
-rw-r--r--docs/help/setup.md2
-rw-r--r--modules/permissions/__init__.py10
-rw-r--r--src/Control.py7
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 <bot> register <password here>` 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: