1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.impl
.Arguments
;
4 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
5 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
7 import org
.asamk
.signal
.manager
.RegistrationManager
;
8 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.CaptchaRequiredException
;
10 import java
.io
.IOException
;
12 public class RegisterCommand
implements RegistrationCommand
{
15 public void attachToSubparser(final Subparser subparser
) {
16 subparser
.addArgument("-v", "--voice")
17 .help("The verification should be done over voice, not sms.")
18 .action(Arguments
.storeTrue());
19 subparser
.addArgument("--captcha")
20 .help("The captcha token, required if registration failed with a captcha required error.");
24 public int handleCommand(final Namespace ns
, final RegistrationManager m
) {
25 final boolean voiceVerification
= ns
.getBoolean("voice");
26 final var captcha
= ns
.getString("captcha");
29 m
.register(voiceVerification
, captcha
);
31 } catch (CaptchaRequiredException e
) {
32 if (captcha
== null) {
33 System
.err
.println("Captcha required for verification, use --captcha CAPTCHA");
34 System
.err
.println("To get the token, go to https://signalcaptchas.org/registration/generate.html");
35 System
.err
.println("Check the developer tools (F12) console for a failed redirect to signalcaptcha://");
36 System
.err
.println("Everything after signalcaptcha:// is the captcha token.");
38 System
.err
.println("Invalid captcha given.");
41 } catch (IOException e
) {
42 System
.err
.println("Request verify error: " + e
.getMessage());