Skip to content

Commit

Permalink
♻️ refactor: update codebase #5 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jul 6, 2024
1 parent 75cfea6 commit a66d962
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 7 deletions.
40 changes: 38 additions & 2 deletions plugin/src/main/groovy/org/bot4j/telegram/message/HtmlBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import java.util.Date;
import java.util.TimeZone;

public class HtmlBuilder {
// @formatter:off
public class HtmlBuilder implements MessageBuilder<HtmlBuilder> {
protected final StringBuilder message;

public HtmlBuilder() {
this.message = new StringBuilder();
}

@Override
public HtmlBuilder icon(TelegramIconMode mode) {
if (mode == null) {
return this;
Expand All @@ -25,6 +27,7 @@ public HtmlBuilder icon(TelegramIconMode mode) {
return this.space();
}

@Override
public HtmlBuilder icon(TelegramIconMode mode, int repeat) {
if (mode == null) {
return this;
Expand All @@ -33,48 +36,58 @@ public HtmlBuilder icon(TelegramIconMode mode, int repeat) {
return this.space();
}

@Override
public HtmlBuilder timestamp(Date date, TimeZone timezone) {
return this.code(Time4j.format(date, timezone));
}

@Override
public HtmlBuilder timestamp(Date date, TimeZone timezone, String format) {
return this.code(Time4j.format(date, timezone, format));
}

@Override
public HtmlBuilder timestamp(Date date, TimezoneType timezone) {
return this.code(Time4j.format(date, timezone));
}

@Override
public HtmlBuilder timestamp(Date date, TimezoneType timezone, String format) {
return this.code(Time4j.format(date, timezone, format));
}

@Override
public HtmlBuilder timestamp(Date date, String format) {
return this.code(Time4j.format(date, format));
}

@Override
public HtmlBuilder timestamp(Date date) {
return this.code(Time4j.format(date, TimeFormatText.BIBLIOGRAPHY_COMPLETE_EPOCH_PATTERN));
}

@Override
public HtmlBuilder timestamp() {
return this.timestamp(new Date());
}

@Override
public HtmlBuilder vertical(String text) {
message.append(String4j.repeat(Ascii.Symbol.VERTICAL_LINE, 2))
.append(text)
.append(String4j.repeat(Ascii.Symbol.VERTICAL_LINE, 2));
return this.space();
}

@Override
public HtmlBuilder vertical(Object value) {
if (value == null) {
return this;
}
return this.vertical(Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

@Override
public HtmlBuilder bold(String text) {
message.append(Ascii.Symbol.LESS_THAN_SIGN)
.append(Ascii.Lowercase.LATIN_SMALL_LETTER_B)
Expand All @@ -87,6 +100,7 @@ public HtmlBuilder bold(String text) {
return this.space();
}

@Override
public HtmlBuilder bold(Object value) {
if (value == null) {
return this;
Expand All @@ -113,6 +127,7 @@ public HtmlBuilder strong(Object value) {
return this.strong(Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

@Override
public HtmlBuilder italic(String text) {
message.append(Ascii.Symbol.LESS_THAN_SIGN)
.append(Ascii.Lowercase.LATIN_SMALL_LETTER_I)
Expand All @@ -125,6 +140,7 @@ public HtmlBuilder italic(String text) {
return this.space();
}

@Override
public HtmlBuilder italic(Object value) {
if (value == null) {
return this;
Expand All @@ -151,6 +167,7 @@ public HtmlBuilder em(Object value) {
return this.em(Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

@Override
public HtmlBuilder underline(String text) {
message.append(Ascii.Symbol.LESS_THAN_SIGN)
.append(Ascii.Lowercase.LATIN_SMALL_LETTER_U)
Expand All @@ -163,6 +180,7 @@ public HtmlBuilder underline(String text) {
return this.space();
}

@Override
public HtmlBuilder underline(Object value) {
if (value == null) {
return this;
Expand All @@ -189,6 +207,7 @@ public HtmlBuilder ins(Object value) {
return this.ins(Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

@Override
public HtmlBuilder strikethrough(String text) {
message.append(Ascii.Symbol.LESS_THAN_SIGN)
.append(Ascii.Lowercase.LATIN_SMALL_LETTER_S)
Expand All @@ -201,6 +220,7 @@ public HtmlBuilder strikethrough(String text) {
return this.space();
}

@Override
public HtmlBuilder strikethrough(Object value) {
if (value == null) {
return this;
Expand Down Expand Up @@ -265,7 +285,8 @@ public HtmlBuilder spoiler(Object value) {
return this.spoiler(Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

public HtmlBuilder inlineUrl(String text, String url) {
@Override
public HtmlBuilder link(String text, String url) {
message.append(Ascii.Symbol.LESS_THAN_SIGN)
.append(Ascii.Lowercase.LATIN_SMALL_LETTER_A)
.append(Ascii.Punctuation.SPACE)
Expand All @@ -284,6 +305,7 @@ public HtmlBuilder inlineUrl(String text, String url) {
return this.space();
}

@Override
public HtmlBuilder code(String text) {
message.append(Ascii.Symbol.LESS_THAN_SIGN)
.append("code")
Expand All @@ -296,13 +318,15 @@ public HtmlBuilder code(String text) {
return this.space();
}

@Override
public HtmlBuilder code(Object value) {
if (value == null) {
return this;
}
return this.code(Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

@Override
public HtmlBuilder code(Path filename) {
try {
String data = Os4j.readFileKeepFormat(filename);
Expand All @@ -312,6 +336,7 @@ public HtmlBuilder code(Path filename) {
}
}

@Override
public HtmlBuilder preformatted(String text) {
message.append(Ascii.Symbol.LESS_THAN_SIGN)
.append("pre")
Expand All @@ -324,13 +349,15 @@ public HtmlBuilder preformatted(String text) {
return this.space();
}

@Override
public HtmlBuilder preformatted(Object value) {
if (value == null) {
return this;
}
return this.preformatted(Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

@Override
public HtmlBuilder preformatted(String lang, String text) {
message.append(Ascii.Symbol.LESS_THAN_SIGN)
.append("pre")
Expand All @@ -356,13 +383,15 @@ public HtmlBuilder preformatted(String lang, String text) {
return this.space();
}

@Override
public HtmlBuilder preformatted(String lang, Object value) {
if (value == null) {
return this;
}
return this.preformatted(lang, Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

@Override
public HtmlBuilder preformatted(String lang, Path filename) {
try {
String data = Os4j.readFileKeepFormat(filename);
Expand All @@ -372,31 +401,37 @@ public HtmlBuilder preformatted(String lang, Path filename) {
}
}

@Override
public HtmlBuilder text(String text) {
message.append(text);
return this.space();
}

@Override
public HtmlBuilder text(Object value) {
if (value == null) {
return this;
}
return this.text(Class4j.isPrimitive(value.getClass()) ? value.toString() : Json4j.toJson(value));
}

@Override
public HtmlBuilder line() {
return this.text(System.lineSeparator());
}

@Override
public HtmlBuilder line(int repeat) {
return this.text(String4j.repeat(System.lineSeparator(), repeat));
}

@Override
public HtmlBuilder space() {
message.append(Ascii.Punctuation.SPACE);
return this;
}

@Override
public HtmlBuilder space(int repeat) {
message.append(String4j.repeat(Ascii.Punctuation.SPACE, repeat));
return this;
Expand All @@ -407,3 +442,4 @@ public String toString() {
return this.message.toString();
}
}
// @formatter:on
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.bot4j.telegram.message;

public class HttpMessageBuilder {
}
Loading

0 comments on commit a66d962

Please sign in to comment.