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
.PinLockMissingException
;
13 import org
.asamk
.signal
.manager
.api
.PinLockedException
;
14 import org
.asamk
.signal
.output
.OutputWriter
;
16 import java
.io
.IOException
;
18 public class FinishChangeNumberCommand
implements JsonRpcLocalCommand
{
21 public String
getName() {
22 return "finishChangeNumber";
26 public void attachToSubparser(final Subparser subparser
) {
27 subparser
.help("Verify the new number using the code received via SMS or voice.");
28 subparser
.addArgument("number").help("The new phone number in E164 format.").required(true);
29 subparser
.addArgument("-v", "--verification-code")
30 .help("The verification code you received via sms or voice call.")
32 subparser
.addArgument("-p", "--pin").help("The registration lock PIN, that was set by the user (Optional)");
36 public void handleCommand(
39 final OutputWriter outputWriter
40 ) throws CommandException
{
41 final var newNumber
= ns
.getString("number");
42 final var verificationCode
= ns
.getString("verification-code");
43 final var pin
= ns
.getString("pin");
46 m
.finishChangeNumber(newNumber
, verificationCode
, pin
);
47 } catch (PinLockedException e
) {
48 throw new UserErrorException(
49 "Verification failed! This number is locked with a pin. Hours remaining until reset: "
50 + (e
.getTimeRemaining() / 1000 / 60 / 60)
51 + "\nUse '--pin PIN_CODE' to specify the registration lock PIN");
52 } catch (IncorrectPinException e
) {
53 throw new UserErrorException("Verification failed! Invalid pin, tries remaining: " + e
.getTriesRemaining());
54 } catch (PinLockMissingException e
) {
55 throw new UserErrorException("Account is pin locked, but pin data has been deleted on the server.");
56 } catch (NotPrimaryDeviceException e
) {
57 throw new UserErrorException("This command doesn't work on linked devices.");
58 } catch (IOException e
) {
59 throw new IOErrorException("Failed to change number: %s (%s)".formatted(e
.getMessage(),
60 e
.getClass().getSimpleName()), e
);