Skip to content

Commit

Permalink
✨ Add summary param for OneBotMedia to support custom image desc #217
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomujin authored Apr 30, 2024
1 parent 3faa0fe commit 6b47e99
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 24 additions & 2 deletions src/main/java/com/mikuac/shiro/common/utils/OneBotMedia.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class OneBotMedia {
*/
private Integer timeout;

/**
* 自定义文本
*/
private String summary;

/**
* <p>builder.</p>
*
Expand All @@ -46,7 +51,7 @@ public static OneBotMedia builder() {
*/
public String escape() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("file=").append(this.file);
stringBuilder.append("file=").append(ShiroUtils.escape(this.file));
if (this.cache != null) {
stringBuilder.append(",cache=").append(Boolean.TRUE.equals(this.cache) ? 1 : 0);
}
Expand All @@ -56,6 +61,9 @@ public String escape() {
if (this.timeout != null) {
stringBuilder.append(",timeout=").append(this.timeout);
}
if (this.summary != null) {
stringBuilder.append(",summary=").append(ShiroUtils.escape(this.summary));
}
return stringBuilder.toString();
}

Expand All @@ -70,6 +78,9 @@ public void escape(Map<String, String> map) {
if (this.timeout != null) {
map.put("timeout", this.timeout.toString());
}
if (this.summary != null) {
map.put("summary", this.summary);
}
}

/**
Expand All @@ -79,7 +90,7 @@ public void escape(Map<String, String> map) {
* @return {@link OneBotMedia}
*/
public OneBotMedia file(String file) {
this.file = ShiroUtils.escape(file);
this.file = file;
return this;
}

Expand Down Expand Up @@ -116,4 +127,15 @@ public OneBotMedia timeout(Integer timeout) {
return this;
}

/**
* <p>summary.</p>
*
* @param summary 自定义文本
* @return {@link OneBotMedia}
*/
public OneBotMedia summary(String summary) {
this.summary = summary;
return this;
}

}
4 changes: 2 additions & 2 deletions src/test/java/com/mikuac/shiro/common/utils/MsgUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class MsgUtilsTest {

@Test
void oneBotMediaTest() {
val media = OneBotMedia.builder().file("https://a.com/1.jpg").cache(false).proxy(false).timeout(10);
val media = OneBotMedia.builder().file("https://a.com/1.jpg").cache(false).proxy(false).timeout(10).summary("看看猫");
val msg = MsgUtils.builder().img(media).build();
val stringMsg = "[CQ:image,file=https://a.com/1.jpg,cache=0,proxy=0,timeout=10]";
val stringMsg = "[CQ:image,file=https://a.com/1.jpg,cache=0,proxy=0,timeout=10,summary=看看猫]";
assertEquals(stringMsg, msg);
}

Expand Down

0 comments on commit 6b47e99

Please sign in to comment.