Skip to content

Commit

Permalink
Refactored the newMessage to a different class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargav-Rao committed Jul 12, 2018
1 parent 1cc173e commit 35e58ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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<MessagePostedEvent> 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");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -102,6 +101,8 @@ public void start(){
executorService = Executors.newSingleThreadScheduledExecutor();
}



public void run() {
handle = executorService.scheduleAtFixedRate(() -> execute(), 0, presentInterval, TimeUnit.SECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 35e58ff

Please sign in to comment.