@@ -35,10 +35,12 @@ public class HugemojiCommand implements SlashCommand {
35
35
36
36
private SecureRandom random ;
37
37
private SupporterCheck supporterCheck ;
38
+ private EmojisFeign emojisFeign ;
38
39
39
- public HugemojiCommand (SupporterCheck supporterCheck ) {
40
+ public HugemojiCommand (SupporterCheck supporterCheck , EmojisFeign emojisFeign ) {
40
41
random = new SecureRandom ();
41
42
this .supporterCheck = supporterCheck ;
43
+ this .emojisFeign = emojisFeign ;
42
44
}
43
45
44
46
@ Override
@@ -51,7 +53,22 @@ public MessageExecutor execute(@NotNull SlashCommandInteractionEvent event,
51
53
var emojiUnion = Emoji .fromFormatted (emojiOption );
52
54
var emojiType = emojiUnion .getType ();
53
55
if (emojiType == Type .UNICODE ) {
54
- messageExecutor .addMessageResponse (emojiUnion .asUnicode ().getName ());
56
+ var emojiCode = emojiUnion .asUnicode ().getAsCodepoints ().substring (2 );
57
+ var emojiResponse = emojisFeign .getEmoji (emojiCode );
58
+ if (emojiResponse .status () == 200 ) {
59
+ try {
60
+ event .replyFiles (FileUpload .fromData (emojiResponse .body ().asInputStream (), STR ."\{emojiCode }.png" ))
61
+ .queue ();
62
+ } catch (IOException e ) {
63
+ log .error ("Failed to get emoji image with emoji code {}. Falling back to just posting the emoji."
64
+ , emojiCode , e );
65
+ messageExecutor .addMessageResponse (emojiUnion .asUnicode ().getName ());
66
+ }
67
+ } else {
68
+ log .error ("Did not get a successful response from emojis API for emoji code {}, response code {}."
69
+ + " Falling back to just posting the emoji." , emojiCode , emojiResponse .status ());
70
+ messageExecutor .addMessageResponse (emojiUnion .asUnicode ().getName ());
71
+ }
55
72
} else if (emojiType == Type .CUSTOM ) {
56
73
var customEmoji = emojiUnion .asCustom ();
57
74
var imageFileType = customEmoji .getImageUrl ().substring (customEmoji .getImageUrl ().lastIndexOf ('.' ));
@@ -99,8 +116,7 @@ private Optional<InputStream> getImageInputStream(@NotNull SlashCommandInteracti
99
116
return Optional .of (inputStream );
100
117
}
101
118
102
- private InputStream biggifyImage (BufferedImage image , String imageFileType , boolean isSupporter )
103
- throws IOException {
119
+ private InputStream biggifyImage (BufferedImage image , String imageFileType , boolean isSupporter ) throws IOException {
104
120
var lowerBound = (int ) (Math .max (image .getHeight (), image .getWidth ()) * getLowerMultiplier (isSupporter ));
105
121
var upperBound = Math .max (image .getHeight (), image .getWidth ()) * getUpperMultiplier (isSupporter );
106
122
var randomNewSize = random .nextInt (lowerBound , upperBound );
@@ -128,7 +144,7 @@ public String getName() {
128
144
129
145
@ Override
130
146
public List <OptionData > getCommandOptions () {
131
- return List .of (new OptionData (OptionType .STRING , HugemojiCommandName .Option .EMOTE .get (), "The emote to "
132
- + "biggify." , true ));
147
+ return List .of (new OptionData (OptionType .STRING , HugemojiCommandName .Option .EMOTE .get (),
148
+ "The emote to " + "biggify." , true ));
133
149
}
134
150
}
0 commit comments