Skip to content

Commit

Permalink
Merge pull request #45 from MdoubleDash/master
Browse files Browse the repository at this point in the history
Added R Collective
  • Loading branch information
Bhargav-Rao authored Sep 2, 2023
2 parents e2f5751 + 5b0c013 commit 588794c
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void main(String[] args) {
else {
rooms.add(new SOBoticsChatRoom());
rooms.add(new HeadquartersChatRoom());
rooms.add(new RPublicChatRoom());
rooms.add(new RCollectiveChatRoom());
rooms.add(new GMTsChatRoom());
rooms.add(new RaidersRoom());
rooms.add(new SeboticsRoom());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package in.bhargavrao.stackoverflow.natty.commandlists;

import in.bhargavrao.stackoverflow.natty.commands.Command;
import in.bhargavrao.stackoverflow.natty.commands.hidden.Hi;
import in.bhargavrao.stackoverflow.natty.commands.others.*;
import in.bhargavrao.stackoverflow.natty.services.RunnerService;
import in.bhargavrao.stackoverflow.natty.utils.CheckUtils;
import org.sobotics.chatexchange.chat.Message;
import org.sobotics.chatexchange.chat.Room;
import org.sobotics.chatexchange.chat.event.PingMessageEvent;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Created by MDoubleDash on 28-Aug-23.
*/
public class RCollectiveCommandsList extends CommandsList {
public void mention(Room room, PingMessageEvent event, RunnerService service, String sitename, String siteurl, boolean isReply){

if(CheckUtils.checkIfUserIsBlacklisted(event.getUserId()))
return;

Message message = event.getMessage();
List<Command> commands = new ArrayList<>(Arrays.asList(
new Alive(message),
new Check(message, sitename, siteurl),
new Hi(message, event.getUserId()),
new Help(message),
new OptIn(message),
new OptOut(message),
new Status(message, sitename, siteurl)
));
commands.add(new Commands(message,commands));

LOGGER.debug("Looking for the command to execute");
executeCommand(room, commands);
LOGGER.info(event.getMessage().getPlainContent());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package in.bhargavrao.stackoverflow.natty.printers;

import in.bhargavrao.stackoverflow.natty.model.Post;
import in.bhargavrao.stackoverflow.natty.model.PostReport;
import in.bhargavrao.stackoverflow.natty.utils.PostPrinter;
import in.bhargavrao.stackoverflow.natty.utils.PrintUtils;
import in.bhargavrao.stackoverflow.natty.utils.SentinelUtils;

/**
* Created by MDoubleDash on 28-Aug-23.
*/
public class RCollectivePostPrinter implements in.bhargavrao.stackoverflow.natty.printers.PostPrinter {

public final long roomId = 252171;

@Override
public String print(PostReport report) {

Post np =report.getPost();

String description= ("[ [Natty](" + PrintUtils.printStackAppsPost() + ") | [Sentinel](" + SentinelUtils.getSentinelMainUrl("stackoverflow") + "/posts/aid/" + report.getPost().getAnswerID() + ") ]");

PostPrinter postPrinter = new PostPrinter(np,description).addMainTag().addDescription().addUserDetails();

if(report.getNaaValue()>=7.0)
postPrinter.addMessage(" **Auto-Flagged**");

return postPrinter.print();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package in.bhargavrao.stackoverflow.natty.roomdata;

import in.bhargavrao.stackoverflow.natty.commandlists.RCollectiveCommandsList;
import in.bhargavrao.stackoverflow.natty.printers.RCollectivePostPrinter;
import in.bhargavrao.stackoverflow.natty.printers.PostPrinter;
import in.bhargavrao.stackoverflow.natty.services.ReplyHandlerService;
import in.bhargavrao.stackoverflow.natty.services.RunnerService;
import in.bhargavrao.stackoverflow.natty.validators.RCollectiveValidator;
import in.bhargavrao.stackoverflow.natty.validators.Validator;
import org.sobotics.chatexchange.chat.ChatHost;
import org.sobotics.chatexchange.chat.Room;
import org.sobotics.chatexchange.chat.event.MessageReplyEvent;
import org.sobotics.chatexchange.chat.event.UserMentionedEvent;

import java.util.function.Consumer;

/**
* Created by MDoubleDash on 28-Aug-23.
*/
public class RCollectiveChatRoom implements BotRoom{
@Override
public int getRoomId() {
return 252171;
}

@Override
public Consumer<UserMentionedEvent> getMention(Room room, RunnerService service) {
return event->new RCollectiveCommandsList().mention(room, event, service, getSiteName(), getSiteUrl(), true);
}

@Override
public Consumer<MessageReplyEvent> getReply(Room room) {
return event-> new ReplyHandlerService().reply(room, event, getSiteName(), getSiteUrl(), true);
}

@Override
public Validator getValidator() {
return new RCollectiveValidator();
}

@Override
public double getNaaValue() {
return 3.5;
}

@Override
public PostPrinter getPostPrinter() {
return new RCollectivePostPrinter();
}

@Override
public boolean getIsLogged() {
return false;
}

@Override
public ChatHost getHost() {
return ChatHost.STACK_OVERFLOW;
}

@Override
public String getSiteName() {
return "stackoverflow";
}

@Override
public String getSiteUrl() {
return "stackoverflow.com";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package in.bhargavrao.stackoverflow.natty.validators;

import in.bhargavrao.stackoverflow.natty.model.Post;

/**
* Created by MDoubleDash on 28-Aug-23.
*/
public class RCollectiveValidator implements Validator {

@Override
public boolean validate(Post post) {
return new AllowOnlyTagValidator("r").validate(post) &&
new AllowAllNewAnswersValidator().validate(post);
}

@Override
public String descriptor() {
return "Not a new answer on an old question tagged R.";
}

}

0 comments on commit 588794c

Please sign in to comment.