aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/configuration/EventsConfiguration.java
blob: 63c774fab1ee81fee61233c3bb4f769fad026c87 (plain) (blame)
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 com.juick.server.configuration;

import com.juick.server.TelegramBotManager;
import com.juick.server.XMPPBot;
import com.juick.server.component.LikeEvent;
import com.juick.server.component.MessageEvent;
import com.juick.server.component.SubscribeEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.inject.Inject;

@Configuration
public class EventsConfiguration {
    private static Logger logger = LoggerFactory.getLogger(EventsConfiguration.class);
    @Inject
    private TelegramBotManager telegramBotManager;
    @Inject
    private XMPPBot bot;
    @Bean
    ApplicationListener<MessageEvent> messageListener() {
        return event -> {
            logger.info("MessageEvent: {}", event.getMessage());
            telegramBotManager.processMessage(event.getMessage());
            bot.processMessage(event.getMessage());
        };
    }
    @Bean
    ApplicationListener<LikeEvent> likeListener() {
        return event -> {
            logger.info("LikeEvent: {} -> {}", event.getUser().getName(), event.getMessage());
            telegramBotManager.processLike(event.getUser(), event.getMessage());
        };
    }
    @Bean
    ApplicationListener<SubscribeEvent> subscribeListener() {
        return event -> {
            logger.info("SubscribeEvent: {} -> {}", event.getUser().getName(), event.getToUser().getName());
            telegramBotManager.processSubscribe(event.getUser(), event.getToUser());
        };
    }
}