- var timestamp = signal.sendMessage(messageText, attachments, recipients);
- writer.println("{}", timestamp);
- } catch (UnknownObject e) {
- throw new UserErrorException("Failed to find dbus object, maybe missing the -u flag: " + e.getMessage());
- } catch (Signal.Error.UntrustedIdentity e) {
- throw new UntrustedKeyErrorException("Failed to send message: " + e.getMessage());
- } catch (DBusExecutionException e) {
- throw new UnexpectedErrorException("Failed to send message: " + e.getMessage());
+ final var message = new Message(messageText,
+ attachments,
+ mentions,
+ Optional.ofNullable(quote),
+ Optional.ofNullable(sticker),
+ previews,
+ Optional.ofNullable((storyReply)));
+ var results = editTimestamp != null
+ ? m.sendEditMessage(message, recipientIdentifiers, editTimestamp)
+ : m.sendMessage(message, recipientIdentifiers);
+ outputResult(outputWriter, results);
+ } catch (AttachmentInvalidException | IOException e) {
+ throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
+ .getSimpleName() + ")", e);
+ } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
+ throw new UserErrorException(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
+ } catch (InvalidStickerException e) {
+ throw new UserErrorException("Failed to send sticker: " + e.getMessage(), e);
+ }
+ }
+
+ private List<Message.Mention> parseMentions(
+ final Manager m, final List<String> mentionStrings
+ ) throws UserErrorException {
+ List<Message.Mention> mentions;
+ final Pattern mentionPattern = Pattern.compile("(\\d+):(\\d+):(.+)");
+ mentions = new ArrayList<>();
+ for (final var mention : mentionStrings) {
+ final var matcher = mentionPattern.matcher(mention);
+ if (!matcher.matches()) {
+ throw new UserErrorException("Invalid mention syntax ("
+ + mention
+ + ") expected 'start:end:recipientNumber'");
+ }
+ mentions.add(new Message.Mention(CommandUtil.getSingleRecipientIdentifier(matcher.group(3),
+ m.getSelfNumber()), Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))));
+ }
+ return mentions;
+ }
+
+ private Message.Sticker parseSticker(final String stickerString) throws UserErrorException {
+ final Pattern stickerPattern = Pattern.compile("([\\da-f]+):(\\d+)");
+ final var matcher = stickerPattern.matcher(stickerString);
+ if (!matcher.matches() || matcher.group(1).length() % 2 != 0) {
+ throw new UserErrorException("Invalid sticker syntax ("
+ + stickerString
+ + ") expected 'stickerPackId:stickerId'");