add a way to execute commands through bitbotd (use for master-password)

This commit is contained in:
jesopo 2019-11-21 10:39:26 +00:00
parent 352df0fa75
commit 9f8c5acf52
4 changed files with 16 additions and 7 deletions

View file

@ -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)

View file

@ -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

View file

@ -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":
@utils.hook("control.master-password")
def command_line(self, event):
master_password = self._master_password()
print("one-time master password: %s" % master_password)
else:
raise ValueError("Unknown command-line argument")
return "One-time master password: %s" % master_password
@utils.hook("received.command.masterpassword", private_only=True)
def master_password(self, event):
"""

View file

@ -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: