- long timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
- System.out.println(timestamp);
- return 0;
- } catch (AssertionError e) {
- handleAssertionError(e);
- return 1;
- } catch (DBusExecutionException e) {
- System.err.println("Failed to send message: " + e.getMessage());
- return 1;
+ var results = m.sendMessage(new Message(messageText, attachments, mentions, Optional.ofNullable(quote)),
+ 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.");
+ }
+ }
+
+ private List<Message.Mention> parseMentions(
+ final Manager m, final List<String> mentionStrings
+ ) throws UserErrorException {
+ List<Message.Mention> mentions;
+ final Pattern mentionPattern = Pattern.compile("([0-9]+):([0-9]+):(.+)");
+ 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))));