Skip to content

Commit 1248b6b

Browse files
committed
Fix some configuration and cleanup
1 parent 866e0f1 commit 1248b6b

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

duga-core/src/main/java/net/zomis/duga/chat/StackExchangeChatBot.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,22 @@ public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, Ht
8888
request.addHeader("Referer", configuration.getRootUrl() + "/users/chat-login");
8989
}
9090
});
91-
this.executorService.submit(() -> {
92-
try {
93-
start();
94-
System.out.println("Start draining");
95-
drainMessagesQueue();
96-
} catch (Exception ex) {
97-
System.out.println("Error!! " + ex);
98-
ex.printStackTrace();
99-
}
100-
});
101-
10291
}
10392

10493
public void start() {
94+
this.executorService.submit(() -> {
95+
try {
96+
startBackground();
97+
System.out.println("Start draining");
98+
drainMessagesQueue();
99+
} catch (Exception ex) {
100+
System.out.println("Error!! " + ex);
101+
ex.printStackTrace();
102+
}
103+
});
104+
}
105+
106+
private void startBackground() {
105107
login();
106108

107109
String deployGreeting = ""; // TODO: configService.getConfig("deployGreeting", "");
@@ -282,10 +284,6 @@ public void stop() {
282284
this.executorService.shutdown();
283285
}
284286

285-
public void destroy() throws Exception {
286-
this.stop();
287-
}
288-
289287
private void drainMessagesQueue() {
290288
try {
291289
while (true) {

duga-core/src/test/java/net/zomis/duga/DugaTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ public class DugaTest {
1616

1717
public static void main(String[] args) {
1818

19-
if (true) {
20-
System.out.println(new File("").getAbsolutePath());
21-
// return;
22-
}
23-
2419
BotConfiguration config = new BotConfiguration();
2520

2621
config.setRootUrl("http://stackexchange.com");
@@ -44,7 +39,7 @@ public static void main(String[] args) {
4439
Scanner scanner = new Scanner(System.in);
4540
StackExchangeChatBot bot = new StackExchangeChatBot(config);
4641
System.out.println("Press enter to start bot");
47-
// bot.start();
42+
bot.start();
4843
while (true) {
4944
String input = scanner.nextLine();
5045
if (input.isEmpty()) {
@@ -54,6 +49,7 @@ public static void main(String[] args) {
5449
bot.postMessages(WebhookParameters.toRoom("16134"),
5550
Collections.singletonList(input));
5651
}
52+
bot.stop();
5753
scanner.close();
5854
}
5955

grails-app/services/net/zomis/duga/DugaBotService.groovy

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ class DugaBotService implements ChatBot, InitializingBean {
3535

3636
@Override
3737
void afterPropertiesSet() throws Exception {
38-
bot = new StackExchangeChatBot(new BotConfiguration().init(environment))
38+
def config = new BotConfiguration()
39+
config.rootUrl = environment.getProperty('rootUrl')
40+
config.chatUrl = 'http://chat.stackexchange.com'
41+
config.botEmail = environment.getProperty('email')
42+
config.botPassword = environment.getProperty('password')
43+
config.chatThrottle = 10000
44+
config.chatMaxBurst = 2
45+
config.chatMinimumDelay = 500
46+
bot = new StackExchangeChatBot(config)
47+
bot.start()
3948
}
4049

4150
String fkey() {

0 commit comments

Comments
 (0)