mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 04:20:38 +00:00
Added the isRegistered command
This commit is contained in:
parent
67f62947c6
commit
938b2a2b9d
4 changed files with 93 additions and 0 deletions
|
@ -124,6 +124,15 @@ Only works, if this is the master device.
|
|||
Specify the device you want to remove.
|
||||
Use listDevices to see the deviceIds.
|
||||
|
||||
=== isRegistered
|
||||
|
||||
Checks if a list of users are registered on Signal or not.
|
||||
|
||||
[NUMBER [NUMBER ...]]::
|
||||
One or more numbers to check.
|
||||
*--json*::
|
||||
Output received messages in json format, one object per line.
|
||||
|
||||
=== send
|
||||
|
||||
Send a message to another user or group.
|
||||
|
|
|
@ -11,6 +11,7 @@ public class Commands {
|
|||
addCommand("addDevice", new AddDeviceCommand());
|
||||
addCommand("block", new BlockCommand());
|
||||
addCommand("daemon", new DaemonCommand());
|
||||
addCommand("isRegistered", new IsRegisteredCommand());
|
||||
addCommand("link", new LinkCommand());
|
||||
addCommand("listContacts", new ListContactsCommand());
|
||||
addCommand("listDevices", new ListDevicesCommand());
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import net.sourceforge.argparse4j.impl.Arguments;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IsRegisteredCommand implements LocalCommand {
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.addArgument("number").help("Phone number").nargs("+");
|
||||
subparser.help("Check if the specified phone number/s have been registered");
|
||||
subparser.addArgument("--json")
|
||||
.help("Output received messages in json format, one json object per line.")
|
||||
.action(Arguments.storeTrue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int handleCommand(final Namespace ns, final Manager m) {
|
||||
if (!m.isRegistered()) {
|
||||
System.err.println("User is not registered.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ObjectMapper jsonProcessor = new ObjectMapper();
|
||||
jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); // disable autodetect
|
||||
jsonProcessor.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
|
||||
|
||||
for (String phone_number : ns.<String>getList("number")) {
|
||||
try {
|
||||
boolean isRegistered = m.isUserRegistered(phone_number);
|
||||
if (ns.getBoolean("json")) {
|
||||
JsonIsReceived object = new JsonIsReceived(phone_number, isRegistered);
|
||||
System.out.println(jsonProcessor.writeValueAsString(object));
|
||||
} else {
|
||||
System.out.println(phone_number + ": " + isRegistered);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private class JsonIsReceived {
|
||||
String name;
|
||||
boolean isRegistered;
|
||||
|
||||
public JsonIsReceived(String name, boolean isRegistered) {
|
||||
this.name = name;
|
||||
this.isRegistered = isRegistered;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -345,6 +345,22 @@ public class Manager implements Closeable {
|
|||
return account.isRegistered();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used for checking if someone else's number is registered on Signal
|
||||
*
|
||||
* @param number The phone number in question
|
||||
* @return True if registered, false otherwise
|
||||
* @throws IOException if its unable to check if the user is registered
|
||||
*/
|
||||
public boolean isUserRegistered(String number) throws IOException {
|
||||
ContactTokenDetails details = this.accountManager.getContact(number).orNull();
|
||||
if (details == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void register(boolean voiceVerification, String captcha) throws IOException {
|
||||
account.setPassword(KeyUtils.createPassword());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue