-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e8c56e8
commit 2bd0e3b
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
plugin/src/main/groovy/org/bot4j/telegram/message/NotifyBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |