-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from MdoubleDash/master
Added R Collective
- Loading branch information
Showing
5 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/in/bhargavrao/stackoverflow/natty/commandlists/RCollectiveCommandsList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/in/bhargavrao/stackoverflow/natty/printers/RCollectivePostPrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/in/bhargavrao/stackoverflow/natty/roomdata/RCollectiveChatRoom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/in/bhargavrao/stackoverflow/natty/validators/RCollectiveValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."; | ||
} | ||
|
||
} |