mut.addArgument("--message-from-stdin")
.action(Arguments.storeTrue())
.help("Read the message from standard input.");
- subparser.addArgument("-a", "--attachment").nargs("*").help("Add an attachment. "
- + "Can be either a file path or a data URI. Data URI encoded attachments must follow the RFC 2397. Additionally a file name can be added, e.g. "
- + "data:<MIME-TYPE>;filename=<FILENAME>;base64,<BASE64 ENCODED DATA>.");
+ subparser.addArgument("-a", "--attachment")
+ .nargs("*")
+ .help("Add an attachment. "
+ + "Can be either a file path or a data URI. Data URI encoded attachments must follow the RFC 2397. Additionally a file name can be added, e.g. "
+ + "data:<MIME-TYPE>;filename=<FILENAME>;base64,<BASE64 ENCODED DATA>.");
subparser.addArgument("-e", "--end-session", "--endsession")
.help("Clear session state and send end session message.")
.action(Arguments.storeTrue());
var messageText = ns.getString("message");
final var readMessageFromStdin = ns.getBoolean("message-from-stdin") == Boolean.TRUE;
- if (readMessageFromStdin || (messageText == null && sticker == null)) {
+ if (readMessageFromStdin) {
logger.debug("Reading message from stdin...");
try {
messageText = IOUtils.readAll(System.in, IOUtils.getConsoleCharset());
} catch (IOException e) {
throw new UserErrorException("Failed to read message from stdin: " + e.getMessage());
}
+ } else if (messageText == null) {
+ messageText = "";
}
List<String> attachments = ns.getList("attachment");
previews = List.of();
}
+ if (messageText.isEmpty() && attachments.isEmpty() && sticker == null && quote == null) {
+ throw new UserErrorException(
+ "Sending empty message is not allowed, either a message, attachment or sticker must be given.");
+ }
+
try {
- var results = m.sendMessage(new Message(messageText == null ? "" : messageText,
+ var results = m.sendMessage(new Message(messageText,
attachments,
mentions,
Optional.ofNullable(quote),