diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/KickChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/KickChatMember.java index 99dcda52..252126b1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/KickChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/KickChatMember.java @@ -1,5 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; @@ -9,6 +10,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; +import java.time.ZonedDateTime; import java.util.Objects; import static com.google.common.base.Preconditions.checkNotNull; @@ -81,11 +85,25 @@ public class KickChatMember extends BotApiMethod { return untilDate; } - public KickChatMember setUntilDate(Integer untilDate) { - this.untilDate = untilDate; + public KickChatMember setUntilDate(Integer untilDateInSeconds) { + this.untilDate = untilDateInSeconds; return this; } + @JsonIgnore + public KickChatMember setUntilDate(Instant instant) { + return setUntilDate((int) instant.getEpochSecond()); + } + + @JsonIgnore + public KickChatMember setUntilDate(ZonedDateTime date) { + return setUntilDate(date.toInstant()); + } + + public KickChatMember forTimePeriod(Duration duration) { + return setUntilDate(Instant.now().plusMillis(duration.toMillis())); + } + @Override public String getMethod() { return PATH; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java index feeca4eb..49cdedb5 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/groupadministration/RestrictChatMember.java @@ -1,5 +1,6 @@ package org.telegram.telegrambots.meta.api.methods.groupadministration; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import org.telegram.telegrambots.meta.api.methods.BotApiMethod; @@ -8,6 +9,9 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; +import java.time.ZonedDateTime; import java.util.Objects; import static com.google.common.base.Preconditions.checkNotNull; @@ -89,11 +93,25 @@ public class RestrictChatMember extends BotApiMethod { return untilDate; } - public RestrictChatMember setUntilDate(Integer untilDate) { - this.untilDate = untilDate; + public RestrictChatMember setUntilDate(Integer untilDateInSeconds) { + this.untilDate = untilDateInSeconds; return this; } + @JsonIgnore + public RestrictChatMember setUntilDate(Instant instant) { + return setUntilDate((int) instant.getEpochSecond()); + } + + @JsonIgnore + public RestrictChatMember setUntilDate(ZonedDateTime date) { + return setUntilDate(date.toInstant()); + } + + public RestrictChatMember forTimePeriod(Duration duration) { + return setUntilDate(Instant.now().plusMillis(duration.toMillis())); + } + public Boolean getCanSendMessages() { return canSendMessages; } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java index c22f29d0..c1996172 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; +import java.time.Instant; + /** * @author Ruben Bermudez * @version 1.0 @@ -77,6 +79,13 @@ public class ChatMember implements BotApiObject { return untilDate; } + public Instant getUntilDateAsInstant() { + if (untilDate == null) { + return null; + } + return Instant.ofEpochSecond(untilDate); + } + public Boolean getCanBeEdited() { return canBeEdited; }