Skip to content

Commit b5b07ae

Browse files
authored
add time command to retrieve current time on server (#120)
Signed-off-by: Spolti <[email protected]>
1 parent 769c00f commit b5b07ae

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package xyz.rebasing.rebot.telegram.api.internal.commands;
2+
3+
import java.lang.invoke.MethodHandles;
4+
import java.time.ZonedDateTime;
5+
import java.util.Optional;
6+
7+
import javax.enterprise.context.ApplicationScoped;
8+
import javax.inject.Inject;
9+
10+
import org.jboss.logging.Logger;
11+
import xyz.rebasing.rebot.api.conf.BotConfig;
12+
import xyz.rebasing.rebot.api.domain.MessageUpdate;
13+
import xyz.rebasing.rebot.api.i18n.I18nHelper;
14+
import xyz.rebasing.rebot.api.spi.administrative.AdministrativeCommandProvider;
15+
16+
@ApplicationScoped
17+
public class TimeCommand implements AdministrativeCommandProvider {
18+
19+
private final Logger log = Logger.getLogger(MethodHandles.lookup().lookupClass().getName());
20+
21+
@Inject
22+
BotConfig config;
23+
24+
@Override
25+
public void load() {
26+
log.debugv("Enabling administrative command {0}", this.name());
27+
}
28+
29+
@Override
30+
public Object execute(Optional<String> key, MessageUpdate messageUpdate, String locale) {
31+
StringBuilder response = new StringBuilder();
32+
response.append("<b>Current time/date:</b> <code>" + ZonedDateTime.now() + "</code>");
33+
return response.toString();
34+
}
35+
36+
@Override
37+
public String name() {
38+
return "/time";
39+
}
40+
41+
@Override
42+
public String help(String locale) {
43+
return this.name() + " " + this.description(locale);
44+
}
45+
46+
@Override
47+
public String description(String locale) {
48+
return I18nHelper.resource("Administrative", locale, "time.command.description");
49+
}
50+
51+
@Override
52+
public boolean deleteMessage() {
53+
return config.deleteMessages();
54+
}
55+
56+
@Override
57+
public long deleteMessageTimeout() {
58+
return config.deleteMessagesAfter();
59+
}
60+
}

rebot-telegram-api/rebot-telegram-api/src/main/resources/Administrative_en_US.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ internal.help.response=\n&#60;command&#62; help: returns the command's help. \
5656
\n&#60;command&#62; disable: disable the current plugin/command in the given chat.
5757

5858

59+
# time command
60+
time.command.description=returns the current time in the current timezone
61+
62+
5963
required.parameter=Parameter is required

rebot-telegram-api/rebot-telegram-api/src/main/resources/Administrative_pt_BR.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@ list.command.no.items.found=Nenhum ítem encontrado.
5454
internal.help.response=\n&#60;comando&#62; ajuda: retorna a ajuda do comando.
5555

5656

57+
# time command
58+
time.command.description=retorna a hora atual no fuso-horário corrente.
59+
60+
5761
required.parameter=Parâmetro obrigatório

0 commit comments

Comments
 (0)