implemented verificationbot init CLI command
This commit is contained in:
parent
616b7fced9
commit
f02baa2d4e
|
@ -19,8 +19,9 @@ package_dir =
|
||||||
= src
|
= src
|
||||||
packages = find:
|
packages = find:
|
||||||
python_requires = >=3.8
|
python_requires = >=3.8
|
||||||
#install_requires =
|
install_requires =
|
||||||
# dependency
|
deltachat
|
||||||
|
click
|
||||||
|
|
||||||
[options.packages.find]
|
[options.packages.find]
|
||||||
where = src
|
where = src
|
||||||
|
|
76
src/verificationbot/cli.py
Normal file
76
src/verificationbot/cli.py
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
import click
|
||||||
|
import deltachat
|
||||||
|
|
||||||
|
|
||||||
|
def get_control_group(ctx, ac: deltachat.account.Account) -> deltachat.chat.Chat | None:
|
||||||
|
for chat in ac.get_chats():
|
||||||
|
if chat.get_contacts() == 1 and chat.is_protected() and chat.is_group():
|
||||||
|
if chat.get_name() == "verification bot control group":
|
||||||
|
return chat
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@click.command(
|
||||||
|
cls=click.Group, context_settings={"help_option_names": ["-h", "--help"]}
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--db-path",
|
||||||
|
type=str,
|
||||||
|
help="The directory where the Delta Chat database should be stored",
|
||||||
|
default="~/.config/DeltaChat/",
|
||||||
|
show_default=True,
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--from-backup",
|
||||||
|
type=str,
|
||||||
|
help="Specify backup file of your account to initialize account",
|
||||||
|
default=" ",
|
||||||
|
)
|
||||||
|
@click.pass_context
|
||||||
|
def init(ctx, db_path, from_backup) -> None:
|
||||||
|
ac = deltachat.account.Account(db_path)
|
||||||
|
if not ac.is_configured():
|
||||||
|
if from_backup is not " ":
|
||||||
|
ac.import_all(from_backup)
|
||||||
|
else:
|
||||||
|
ctx.fail(
|
||||||
|
"Account not configured. Please specify a backup file with --from-backup"
|
||||||
|
)
|
||||||
|
|
||||||
|
# ensure that the account owner has bcc_self enabled
|
||||||
|
if ac.get_config("bcc_self") == "0":
|
||||||
|
ctx.fail(
|
||||||
|
"You need to enable 'Send Copy to Self' in the Advanced settings for this bot to work."
|
||||||
|
)
|
||||||
|
|
||||||
|
# disable read receipts; we don't want the bot to send out read receipts if the actual account
|
||||||
|
# owner didn't read the message yet
|
||||||
|
ac.set_config("mdns_enabled", "0")
|
||||||
|
|
||||||
|
# create control group
|
||||||
|
if not get_control_group(ctx, ac):
|
||||||
|
control_group = ac.create_group_chat(
|
||||||
|
"verification bot control group", verified=True
|
||||||
|
)
|
||||||
|
control_group.send_text(
|
||||||
|
"This is the control group for the verification bot. Send /help for available commands."
|
||||||
|
)
|
||||||
|
click.secho("Verification bot for %s was set up successfully. To start the bot, run:")
|
||||||
|
click.secho("")
|
||||||
|
click.secho(" verificationbot run")
|
||||||
|
|
||||||
|
|
||||||
|
@click.command(
|
||||||
|
cls=click.Group, context_settings={"help_option_names": ["-h", "--help"]}
|
||||||
|
)
|
||||||
|
@click.version_option()
|
||||||
|
@click.pass_context
|
||||||
|
def cli_main(context):
|
||||||
|
"""e-mail account creation admin tool and web service."""
|
||||||
|
|
||||||
|
|
||||||
|
cli_main.add_command(init)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
cli_main()
|
Loading…
Reference in a new issue