diff --git a/src/main/java/in/bhargavrao/stackoverflow/natty/services/NewMessageHandlerService.java b/src/main/java/in/bhargavrao/stackoverflow/natty/services/NewMessageHandlerService.java new file mode 100644 index 0000000..a3f089d --- /dev/null +++ b/src/main/java/in/bhargavrao/stackoverflow/natty/services/NewMessageHandlerService.java @@ -0,0 +1,26 @@ +package in.bhargavrao.stackoverflow.natty.services; + +import org.sobotics.chatexchange.chat.Room; +import org.sobotics.chatexchange.chat.event.MessagePostedEvent; + +import java.util.function.Consumer; + +public class NewMessageHandlerService { + + public Consumer getMessagePostedEventConsumer(Room finalChatroom) { + return event-> newMessage(finalChatroom, event, false); + } + + + private static void newMessage(Room room, MessagePostedEvent event, boolean b) { + String message = event.getMessage().getPlainContent(); + int cp = Character.codePointAt(message, 0); + if(message.trim().startsWith("@bots alive")){ + room.send("Whadya think?"); + } + else if (cp == 128642 || (cp>=128644 && cp<=128650)){ + room.send("\uD83D\uDE83"); + } + } + +} diff --git a/src/main/java/in/bhargavrao/stackoverflow/natty/services/RunnerService.java b/src/main/java/in/bhargavrao/stackoverflow/natty/services/RunnerService.java index 2056d20..2ffce19 100644 --- a/src/main/java/in/bhargavrao/stackoverflow/natty/services/RunnerService.java +++ b/src/main/java/in/bhargavrao/stackoverflow/natty/services/RunnerService.java @@ -19,8 +19,6 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import static in.bhargavrao.stackoverflow.natty.utils.PostUtils.newMessage; - /** * Created by bhargav.h on 28-Dec-16. */ @@ -61,7 +59,8 @@ public void start(){ PropertyService service = new PropertyService(); Room finalChatroom = chatroom; - chatroom.addEventListener(EventType.MESSAGE_POSTED, event-> newMessage(finalChatroom, event, false)); + chatroom.addEventListener(EventType.MESSAGE_POSTED, + new NewMessageHandlerService().getMessagePostedEventConsumer(finalChatroom)); BlacklistDataService blacklistDataService = new BlacklistDataService(finalChatroom); blacklistDataService.start(); @@ -102,6 +101,8 @@ public void start(){ executorService = Executors.newSingleThreadScheduledExecutor(); } + + public void run() { handle = executorService.scheduleAtFixedRate(() -> execute(), 0, presentInterval, TimeUnit.SECONDS); } diff --git a/src/main/java/in/bhargavrao/stackoverflow/natty/utils/PostUtils.java b/src/main/java/in/bhargavrao/stackoverflow/natty/utils/PostUtils.java index 7cf134c..576cfae 100644 --- a/src/main/java/in/bhargavrao/stackoverflow/natty/utils/PostUtils.java +++ b/src/main/java/in/bhargavrao/stackoverflow/natty/utils/PostUtils.java @@ -8,8 +8,6 @@ import in.bhargavrao.stackoverflow.natty.model.autocomments.AutoComment; import in.bhargavrao.stackoverflow.natty.services.*; import org.jetbrains.annotations.NotNull; -import org.sobotics.chatexchange.chat.Room; -import org.sobotics.chatexchange.chat.event.MessagePostedEvent; import java.io.IOException; import java.time.Instant; @@ -181,18 +179,6 @@ public static long addSentinel(PostReport report, String sitename, String siteur - public static void newMessage(Room room, MessagePostedEvent event, boolean b) { - String message = event.getMessage().getPlainContent(); - int cp = Character.codePointAt(message, 0); - if(message.trim().startsWith("@bots alive")){ - room.send("Whadya think?"); - } - else if (cp == 128642 || (cp>=128644 && cp<=128650)){ - room.send("\uD83D\uDE83"); - } - } - - public static SavedReport getReport(Post np, PostReport report){ SavedReport savedReport = new SavedReport();