mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-09-23 06:39:04 +00:00
Add sendStory command for posting stories via CLI and JSON-RPC
Implements SendStoryCommand to allow users to post stories through the CLI and JSON-RPC interfaces. Command accepts an attachment file path (required) and optional --no-replies flag to disable replies on the story. Handles AttachmentInvalidException and IOException appropriately and outputs results using SendMessageResultUtils. Registered in Commands.java in alphabetical order.
This commit is contained in:
parent
862567ac93
commit
1208fdb143
@ -52,6 +52,7 @@ public class Commands {
|
|||||||
addCommand(new SendPollTerminateCommand());
|
addCommand(new SendPollTerminateCommand());
|
||||||
addCommand(new SendReactionCommand());
|
addCommand(new SendReactionCommand());
|
||||||
addCommand(new SendReceiptCommand());
|
addCommand(new SendReceiptCommand());
|
||||||
|
addCommand(new SendStoryCommand());
|
||||||
addCommand(new SendSyncRequestCommand());
|
addCommand(new SendSyncRequestCommand());
|
||||||
addCommand(new SendTypingCommand());
|
addCommand(new SendTypingCommand());
|
||||||
addCommand(new SendUnpinMessageCommand());
|
addCommand(new SendUnpinMessageCommand());
|
||||||
|
|||||||
@ -0,0 +1,57 @@
|
|||||||
|
package org.asamk.signal.commands;
|
||||||
|
|
||||||
|
import net.sourceforge.argparse4j.impl.Arguments;
|
||||||
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
|
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||||
|
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.api.AttachmentInvalidException;
|
||||||
|
import org.asamk.signal.output.OutputWriter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.asamk.signal.util.SendMessageResultUtils.outputResult;
|
||||||
|
|
||||||
|
public class SendStoryCommand implements JsonRpcLocalCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "sendStory";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attachToSubparser(final Subparser subparser) {
|
||||||
|
subparser.help("Post a story to your Story.");
|
||||||
|
subparser.addArgument("-a", "--attachment")
|
||||||
|
.required(true)
|
||||||
|
.help("Specify the file path to the image or video to post as a story.");
|
||||||
|
subparser.addArgument("--no-replies")
|
||||||
|
.action(Arguments.storeTrue())
|
||||||
|
.help("Disable replies on this story.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCommand(
|
||||||
|
final Namespace ns,
|
||||||
|
final Manager m,
|
||||||
|
final OutputWriter outputWriter
|
||||||
|
) throws CommandException {
|
||||||
|
final var attachment = ns.getString("attachment");
|
||||||
|
if (attachment == null || attachment.isEmpty()) {
|
||||||
|
throw new UserErrorException("An attachment is required for sending a story.");
|
||||||
|
}
|
||||||
|
|
||||||
|
final var noReplies = Boolean.TRUE.equals(ns.getBoolean("no-replies"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
final var results = m.sendStory(attachment, !noReplies);
|
||||||
|
outputResult(outputWriter, results);
|
||||||
|
} catch (AttachmentInvalidException | IOException e) {
|
||||||
|
throw new UnexpectedErrorException("Failed to send story: " + e.getMessage() + " (" + e.getClass()
|
||||||
|
.getSimpleName() + ")", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user