/
Notify.java
52 lines (44 loc) · 1.6 KB
/
Notify.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.example.telegrambot.ability;
import com.example.telegrambot.bot.Bot;
import lombok.ToString;
import org.apache.log4j.Logger;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.methods.send.SendSticker;
@ToString
public class Notify implements Runnable {
private static final Logger log = Logger.getLogger(Notify.class);
private static final int MILLISEC_IN_SEC = 1000;
Bot bot;
long delayInMillisec;
String chatID;
public Notify(Bot bot, String chatID, long delayInMillisec) {
this.bot = bot;
this.chatID = chatID;
this.delayInMillisec = delayInMillisec;
log.debug("CREATE. " + toString());
}
@Override
public void run() {
log.info("RUN. " + toString());
bot.sendQueue.add(getFirstMessage());
try {
Thread.sleep(delayInMillisec);
bot.sendQueue.add(getSecondSticker());
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
}
log.info("FIHISH. " + toString());
}
private SendMessage getFirstMessage() {
return new SendMessage(chatID, "I will send you notify after " + delayInMillisec / MILLISEC_IN_SEC + "sec");
}
private SendSticker getSecondSticker() {
SendSticker sendSticker = new SendSticker();
sendSticker.setSticker("CAADBQADiQMAAukKyAPZH7wCI2BwFxYE");
sendSticker.setChatId(chatID);
return sendSticker;
}
private SendMessage getSecondMessage() {
return new SendMessage(chatID, "This is notify message. Thanks for using :)");
}
}