1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.OutputWriter
;
7 import org
.asamk
.signal
.PlainTextWriter
;
8 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
9 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
10 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
11 import org
.asamk
.signal
.manager
.Manager
;
12 import org
.asamk
.signal
.manager
.StickerPackInvalidException
;
13 import org
.slf4j
.Logger
;
14 import org
.slf4j
.LoggerFactory
;
17 import java
.io
.IOException
;
19 public class UploadStickerPackCommand
implements LocalCommand
{
21 private final static Logger logger
= LoggerFactory
.getLogger(UploadStickerPackCommand
.class);
24 public String
getName() {
25 return "uploadStickerPack";
29 public void attachToSubparser(final Subparser subparser
) {
30 subparser
.help("Upload a new sticker pack, consisting of a manifest file and the stickers images.");
31 subparser
.addArgument("path")
32 .help("The path of the manifest.json or a zip file containing the sticker pack you wish to upload.");
36 public void handleCommand(
37 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
38 ) throws CommandException
{
39 final var writer
= (PlainTextWriter
) outputWriter
;
40 var path
= new File(ns
.getString("path"));
43 var url
= m
.uploadStickerPack(path
);
44 writer
.println("{}", url
);
45 } catch (IOException e
) {
46 throw new IOErrorException("Upload error (maybe image size too large):" + e
.getMessage());
47 } catch (StickerPackInvalidException e
) {
48 throw new UserErrorException("Invalid sticker pack: " + e
.getMessage());