Skip to content

Commit

Permalink
♻️ refactor: update notify builder #5 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jul 7, 2024
1 parent e8c56e8 commit 2bd0e3b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public abstract class MessageFactory {
/**
* Create a MarkdownBuilder instance.
*
* @return MarkdownBuilder instance
* @return MarkdownBuilder instance, class {@link MarkdownBuilder}
*/
public static MarkdownBuilder markdown() {
return new MarkdownBuilder();
Expand All @@ -14,9 +14,27 @@ public static MarkdownBuilder markdown() {
/**
* Create a HtmlBuilder instance.
*
* @return HtmlBuilder instance
* @return HtmlBuilder instance, class {@link HtmlBuilder}
*/
public static HtmlBuilder html() {
return new HtmlBuilder();
}

/**
* Create a HttpBuilder instance.
*
* @return HttpBuilder instance, class {@link HttpBuilder}
*/
public static HttpBuilder http() {
return new HttpBuilder();
}

/**
* Create a HttpBuilder instance.
*
* @return HttpBuilder instance, class {@link NotifyBuilder}
*/
public static NotifyBuilder reveal() {
return new NotifyBuilder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.bot4j.telegram.message;

import org.alpha4j.common.Map4j;

public class NotifyBuilder extends MarkdownBuilder {
protected final Map4j<String, Object> placeholders;

public NotifyBuilder() {
super();
this.placeholders = new Map4j<>();
}

protected static class Index {
public static final String CAUSE_INDEX = "cause_index";
}

public NotifyBuilder cause(Throwable e) {
if (e == null) {
return this;
}
this.placeholders.put(Index.CAUSE_INDEX, e.getMessage());
return this;
}

@Override
public String toString() {
if (this.placeholders.containsKey(Index.CAUSE_INDEX)) {
this.line().bold("Cause:")
.preformatted("bash", (String) this.placeholders.get(Index.CAUSE_INDEX))
.line();
}
return super.toString();
}
}

0 comments on commit 2bd0e3b

Please sign in to comment.