diff --git a/setup.cfg b/setup.cfg index 157c671..dd23539 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,8 +19,9 @@ package_dir = = src packages = find: python_requires = >=3.8 -#install_requires = -# dependency +install_requires = + deltachat + click [options.packages.find] where = src diff --git a/src/verificationbot/cli.py b/src/verificationbot/cli.py new file mode 100644 index 0000000..c055484 --- /dev/null +++ b/src/verificationbot/cli.py @@ -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()