Skip to content

Commit 4a17c88

Browse files
committed
Use "!" syntax when image URL does not end with file extension
1 parent f857777 commit 4a17c88

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/main/java/oakbot/command/ReactGiphyCommand.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,16 @@ public ChatActions onMessage(ChatCommand chatCommand, IBot bot) {
5858
return reply("404 human emotion not found.", chatCommand);
5959
}
6060

61-
/*
62-
* URL must end in a file extension in order for chat to display the
63-
* image.
64-
*/
65-
if (!imageUrl.endsWith(".gif")) {
66-
imageUrl += "&a=.gif";
67-
}
68-
6961
//@formatter:off
7062
var condensedMessage = new ChatBuilder()
7163
.append("Reaction: ")
7264
.link(content, imageUrl)
7365
.append(" (powered by ").link("GIPHY", "https://giphy.com").append(")");
7466

7567
return ChatActions.create(
76-
new PostMessage(imageUrl).bypassFilters(true).condensedMessage(condensedMessage)
68+
new PostMessage(new ChatBuilder().image(imageUrl))
69+
.bypassFilters(true)
70+
.condensedMessage(condensedMessage)
7771
);
7872
//@formatter:on
7973
} catch (Exception e) {

src/main/java/oakbot/util/ChatBuilder.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ public ChatBuilder fixedWidth() {
5757
return this;
5858
}
5959

60+
/**
61+
* <p>
62+
* Inserts an image into the message using explicit syntax. Note that images
63+
* and text cannot be mixed.
64+
* </p>
65+
* <p>
66+
* This method must be used if the image URL does not end with the file
67+
* extension of a supported image format (e.g. ".jpg", ".gif"). If the URL
68+
* ends with such as extension, then this syntax is not necessary.
69+
* </p>
70+
* @param url the image URL
71+
* @return this
72+
*/
73+
public ChatBuilder image(CharSequence url) {
74+
return append('!').append(url);
75+
}
76+
6077
/**
6178
* Appends the character sequence for "blockquote". This must go at the
6279
* beginning of the string.

0 commit comments

Comments
 (0)