1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
7 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
8 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
9 import org
.asamk
.signal
.manager
.Manager
;
10 import org
.asamk
.signal
.manager
.api
.IncorrectPinException
;
11 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
12 import org
.asamk
.signal
.manager
.api
.PinLockedException
;
13 import org
.asamk
.signal
.output
.OutputWriter
;
15 import java
.io
.IOException
;
17 public class FinishChangeNumberCommand
implements JsonRpcLocalCommand
{
20 public String
getName() {
21 return "finishChangeNumber";
25 public void attachToSubparser(final Subparser subparser
) {
26 subparser
.help("Verify the new number using the code received via SMS or voice.");
27 subparser
.addArgument("number").help("The new phone number in E164 format.").required(true);
28 subparser
.addArgument("-v", "--verification-code")
29 .help("The verification code you received via sms or voice call.")
31 subparser
.addArgument("-p", "--pin").help("The registration lock PIN, that was set by the user (Optional)");
35 public void handleCommand(
38 final OutputWriter outputWriter
39 ) throws CommandException
{
40 final var newNumber
= ns
.getString("number");
41 final var verificationCode
= ns
.getString("verification-code");
42 final var pin
= ns
.getString("pin");
45 m
.finishChangeNumber(newNumber
, verificationCode
, pin
);
46 } catch (PinLockedException e
) {
47 throw new UserErrorException(
48 "Verification failed! This number is locked with a pin. Hours remaining until reset: "
49 + (e
.getTimeRemaining() / 1000 / 60 / 60)
50 + "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
51 } catch (IncorrectPinException e
) {
52 throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e
.getTriesRemaining());
53 } catch (NotPrimaryDeviceException e
) {
54 throw new UserErrorException("This command doesn't work on linked devices.");
55 } catch (IOException e
) {
56 throw new IOErrorException("Failed to change number: %s (%s)".formatted(e
.getMessage(),
57 e
.getClass().getSimpleName()), e
);