-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
45 lines (38 loc) · 1.29 KB
/
Main.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
package chat.tamtam.echobot;
import chat.tamtam.bot.exceptions.TamTamBotException;
import chat.tamtam.bot.longpolling.LongPollingBot;
import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
public class Main {
private static final Options OPTIONS = new Options();
public static void main(String[] args) {
OptionSet optionSet;
try {
optionSet = OPTIONS.parse(args);
} catch (OptionException e) {
System.err.println(e.getMessage());
System.exit(1);
return;
}
String accessToken = OPTIONS.accessToken.value(optionSet);
LongPollingBot bot = new EchoBot(accessToken);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("Stopping bot…");
bot.stop();
}));
try {
bot.start();
} catch (TamTamBotException e) {
System.err.println("Failed to start bot: " + e.getMessage());
System.exit(1);
}
}
private static class Options extends OptionParser {
OptionSpec<String> accessToken = accepts("token")
.withRequiredArg()
.required()
.ofType(String.class);
}
}