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
.GroupIdFormatException
;
8 import org
.asamk
.signal
.GroupNotFoundException
;
9 import org
.asamk
.signal
.NotAGroupMemberException
;
10 import org
.asamk
.signal
.manager
.Manager
;
11 import org
.asamk
.signal
.util
.Util
;
12 import org
.whispersystems
.signalservice
.api
.push
.SignalServiceAddress
;
13 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.EncapsulatedExceptions
;
15 import java
.io
.IOException
;
17 import static org
.asamk
.signal
.util
.ErrorUtils
.handleAssertionError
;
18 import static org
.asamk
.signal
.util
.ErrorUtils
.handleEncapsulatedExceptions
;
19 import static org
.asamk
.signal
.util
.ErrorUtils
.handleGroupIdFormatException
;
20 import static org
.asamk
.signal
.util
.ErrorUtils
.handleGroupNotFoundException
;
21 import static org
.asamk
.signal
.util
.ErrorUtils
.handleIOException
;
22 import static org
.asamk
.signal
.util
.ErrorUtils
.handleNotAGroupMemberException
;
24 public class SendReactionCommand
implements LocalCommand
{
27 public void attachToSubparser(final Subparser subparser
) {
28 subparser
.help("Send reaction to a previously received or sent message.");
29 subparser
.addArgument("-g", "--group")
30 .help("Specify the recipient group ID.");
31 subparser
.addArgument("recipient")
32 .help("Specify the recipients' phone number.")
34 subparser
.addArgument("-e", "--emoji")
36 .help("Specify the emoji, should be a single unicode grapheme cluster.");
37 subparser
.addArgument("-a", "--target-author")
39 .help("Specify the number of the author of the message to which to react.");
40 subparser
.addArgument("-t", "--target-timestamp")
43 .help("Specify the timestamp of the message to which to react.");
44 subparser
.addArgument("-r", "--remove")
45 .help("Remove a reaction.")
46 .action(Arguments
.storeTrue());
50 public int handleCommand(final Namespace ns
, final Manager m
) {
51 if (!m
.isRegistered()) {
52 System
.err
.println("User is not registered.");
56 if ((ns
.getList("recipient") == null || ns
.getList("recipient").size() == 0) && ns
.getString("group") == null) {
57 System
.err
.println("No recipients given");
58 System
.err
.println("Aborting sending.");
62 String emoji
= ns
.getString("emoji");
63 boolean isRemove
= ns
.getBoolean("remove");
64 SignalServiceAddress targetAuthor
= new SignalServiceAddress(null, ns
.getString("target_author"));
65 long targetTimestamp
= ns
.getLong("target_timestamp");
68 if (ns
.getString("group") != null) {
69 byte[] groupId
= Util
.decodeGroupId(ns
.getString("group"));
70 m
.sendGroupMessageReaction(emoji
, isRemove
, targetAuthor
, targetTimestamp
, groupId
);
72 m
.sendMessageReaction(emoji
, isRemove
, targetAuthor
, targetTimestamp
, ns
.getList("recipient"));
75 } catch (IOException e
) {
78 } catch (EncapsulatedExceptions e
) {
79 handleEncapsulatedExceptions(e
);
81 } catch (AssertionError e
) {
82 handleAssertionError(e
);
84 } catch (GroupNotFoundException e
) {
85 handleGroupNotFoundException(e
);
87 } catch (NotAGroupMemberException e
) {
88 handleNotAGroupMemberException(e
);
90 } catch (GroupIdFormatException e
) {
91 handleGroupIdFormatException(e
);