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
.exceptions
.EncapsulatedExceptions
;
13 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
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
.handleInvalidNumberException
;
23 import static org
.asamk
.signal
.util
.ErrorUtils
.handleNotAGroupMemberException
;
25 public class SendReactionCommand
implements LocalCommand
{
28 public void attachToSubparser(final Subparser subparser
) {
29 subparser
.help("Send reaction to a previously received or sent message.");
30 subparser
.addArgument("-g", "--group")
31 .help("Specify the recipient group ID.");
32 subparser
.addArgument("recipient")
33 .help("Specify the recipients' phone number.")
35 subparser
.addArgument("-e", "--emoji")
37 .help("Specify the emoji, should be a single unicode grapheme cluster.");
38 subparser
.addArgument("-a", "--target-author")
40 .help("Specify the number of the author of the message to which to react.");
41 subparser
.addArgument("-t", "--target-timestamp")
44 .help("Specify the timestamp of the message to which to react.");
45 subparser
.addArgument("-r", "--remove")
46 .help("Remove a reaction.")
47 .action(Arguments
.storeTrue());
51 public int handleCommand(final Namespace ns
, final Manager m
) {
52 if (!m
.isRegistered()) {
53 System
.err
.println("User is not registered.");
57 if ((ns
.getList("recipient") == null || ns
.getList("recipient").size() == 0) && ns
.getString("group") == null) {
58 System
.err
.println("No recipients given");
59 System
.err
.println("Aborting sending.");
63 String emoji
= ns
.getString("emoji");
64 boolean isRemove
= ns
.getBoolean("remove");
65 String targetAuthor
= ns
.getString("target_author");
66 long targetTimestamp
= ns
.getLong("target_timestamp");
69 if (ns
.getString("group") != null) {
70 byte[] groupId
= Util
.decodeGroupId(ns
.getString("group"));
71 m
.sendGroupMessageReaction(emoji
, isRemove
, targetAuthor
, targetTimestamp
, groupId
);
73 m
.sendMessageReaction(emoji
, isRemove
, targetAuthor
, targetTimestamp
, ns
.getList("recipient"));
76 } catch (IOException e
) {
79 } catch (EncapsulatedExceptions e
) {
80 handleEncapsulatedExceptions(e
);
82 } catch (AssertionError e
) {
83 handleAssertionError(e
);
85 } catch (GroupNotFoundException e
) {
86 handleGroupNotFoundException(e
);
88 } catch (NotAGroupMemberException e
) {
89 handleNotAGroupMemberException(e
);
91 } catch (GroupIdFormatException e
) {
92 handleGroupIdFormatException(e
);
94 } catch (InvalidNumberException e
) {
95 handleInvalidNumberException(e
);