refined vbot init CLI command

main
missytake 2023-05-19 20:26:24 +02:00
parent f02baa2d4e
commit 3b770c3cc9
2 changed files with 24 additions and 17 deletions

View File

@ -28,10 +28,10 @@ where = src
[options.entry_points]
console_scripts =
verificationbot = verificationbot:main
verificationbot = verificationbot.cli:cli_main
[tox:tox]
envlist = lint, py38, py39, py310
envlist = lint, py310
isolated_build = True
[testenv:lint]
@ -39,11 +39,9 @@ skip_install = True
deps =
black
flake8
mypy
commands =
black --check --diff src tests
flake8 src tests
mypy --disallow-untyped-defs src tests
[testenv]
deps =
@ -52,4 +50,4 @@ commands =
pytest tests
[flake8]
max_line_length = 88
max_line_length = 100

View File

@ -1,23 +1,24 @@
import os
import time
import click
import deltachat
def get_control_group(ctx, ac: deltachat.account.Account) -> deltachat.chat.Chat | None:
def get_control_group(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 len(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.command()
@click.option(
"--db-path",
type=str,
help="The directory where the Delta Chat database should be stored",
default="~/.config/DeltaChat/",
default=os.getenv("HOME") + "/.config/DeltaChat/verificationbot/db.sqlite",
show_default=True,
)
@click.option(
@ -30,7 +31,7 @@ def get_control_group(ctx, ac: deltachat.account.Account) -> deltachat.chat.Chat
def init(ctx, db_path, from_backup) -> None:
ac = deltachat.account.Account(db_path)
if not ac.is_configured():
if from_backup is not " ":
if from_backup != " ":
ac.import_all(from_backup)
else:
ctx.fail(
@ -38,7 +39,7 @@ def init(ctx, db_path, from_backup) -> None:
)
# ensure that the account owner has bcc_self enabled
if ac.get_config("bcc_self") == "0":
if ac.get_config("bcc_self") != "1":
ctx.fail(
"You need to enable 'Send Copy to Self' in the Advanced settings for this bot to work."
)
@ -48,16 +49,24 @@ def init(ctx, db_path, from_backup) -> None:
ac.set_config("mdns_enabled", "0")
# create control group
if not get_control_group(ctx, ac):
if not get_control_group(ac):
ac.start_io()
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:")
# wait until message is sent out
while not control_group.get_messages()[-1].is_out_delivered():
time.sleep(0.1)
click.secho(
"Verification bot for %s was set up successfully. To start the bot, run:"
% (ac.get_config("addr"),)
)
click.secho("")
click.secho(" verificationbot run")
click.secho(" verificationbot run\n")
@click.command(
@ -65,7 +74,7 @@ def init(ctx, db_path, from_backup) -> None:
)
@click.version_option()
@click.pass_context
def cli_main(context):
def cli_main(ctx):
"""e-mail account creation admin tool and web service."""