mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Add addStickerPack command
This commit is contained in:
parent
133e2cc222
commit
e867c57af8
14 changed files with 159 additions and 25 deletions
|
@ -0,0 +1,62 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
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.IOErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.api.StickerPackUrl;
|
||||
import org.asamk.signal.output.OutputWriter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class AddStickerPackCommand implements JsonRpcLocalCommand {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(AddStickerPackCommand.class);
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "addStickerPack";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.help("Install a sticker pack for this account.");
|
||||
subparser.addArgument("--uri")
|
||||
.required(true)
|
||||
.nargs("+")
|
||||
.help("Specify the uri of the sticker pack. (e.g. https://signal.art/addstickers/#pack_id=XXX&pack_key=XXX)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(
|
||||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
final var uris = ns.<String>getList("uri");
|
||||
for (final var uri : uris) {
|
||||
final URI stickerUri;
|
||||
try {
|
||||
stickerUri = new URI(uri);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new UserErrorException("Sticker pack uri has invalid format: " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
var stickerPackUrl = StickerPackUrl.fromUri(stickerUri);
|
||||
m.installStickerPack(stickerPackUrl);
|
||||
} catch (IOException e) {
|
||||
logger.error("Install sticker pack failed", e);
|
||||
throw new IOErrorException("Install sticker pack failed", e);
|
||||
} catch (StickerPackUrl.InvalidStickerPackLinkException e) {
|
||||
logger.error("Invalid sticker pack link", e);
|
||||
throw new UserErrorException("Invalid sticker pack link", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ public class Commands {
|
|||
addCommand(new FinishLinkCommand());
|
||||
addCommand(new GetAttachmentCommand());
|
||||
addCommand(new GetUserStatusCommand());
|
||||
addCommand(new AddStickerPackCommand());
|
||||
addCommand(new JoinGroupCommand());
|
||||
addCommand(new JsonRpcDispatcherCommand());
|
||||
addCommand(new LinkCommand());
|
||||
|
|
|
@ -481,6 +481,11 @@ public class DbusManagerImpl implements Manager {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void installStickerPack(final StickerPackUrl url) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StickerPack> getStickerPacks() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue