Skip to content

Commit

Permalink
Merge pull request #168 from SOBotics/release/1.2.0
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
FelixSFD authored Apr 12, 2018
2 parents 61ba1be + 6bbd174 commit f123323
Show file tree
Hide file tree
Showing 25 changed files with 385 additions and 104 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>de.felixsfd.stackoverflow</groupId>
<artifactId>guttenberg</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>

<dependencies>
<dependency>
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/org/sobotics/guttenberg/clients/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import java.util.List;
import java.util.Properties;

import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sobotics.redunda.DataService;
import org.sobotics.redunda.PingService;
import org.sobotics.guttenberg.commands.Status;
import org.sobotics.guttenberg.roomdata.BotRoom;
import org.sobotics.guttenberg.roomdata.SEBoticsChatRoom;
import org.sobotics.guttenberg.roomdata.SOBoticsChatRoom;
import org.sobotics.guttenberg.roomdata.SOGuttenbergTestingFacility;
import org.sobotics.guttenberg.roomdata.SOBoticsWorkshopChatRoom;
import org.sobotics.guttenberg.services.RunnerService;
import org.sobotics.guttenberg.utils.FilePathUtils;
import org.sobotics.guttenberg.utils.StatusUtils;
Expand All @@ -35,8 +38,22 @@ private Client(){
}

public static void main(String[] args) {
LOGGER.info("Hello, World!");
LOGGER.info("Load properties...");
Properties loggerProperties = new Properties();
try{
loggerProperties.load(new FileInputStream(FilePathUtils.loggerPropertiesFile));

String levelStr = loggerProperties.getProperty("level");
Level newLevel = Level.toLevel(levelStr, Level.ERROR);
LogManager.getRootLogger().setLevel(newLevel);
}
catch (Throwable e){
LOGGER.error("Could not load logger.properties! Using default log-level ERROR.", e);
}

LOGGER.info("============================");
LOGGER.info("=== Launching Guttenberg ===");
LOGGER.info("============================");
LOGGER.info("Loading properties...");

Properties prop = new Properties();

Expand All @@ -52,12 +69,13 @@ public static void main(String[] args) {

Guttenberg.setLoginProperties(prop);

LOGGER.info("Initialize chat...");
LOGGER.info("Initializing chat...");
StackExchangeClient seClient = new StackExchangeClient(prop.getProperty("email"), prop.getProperty("password"));

List<BotRoom> rooms = new ArrayList<>();
rooms.add(new SOBoticsChatRoom());
rooms.add(new SOGuttenbergTestingFacility());
rooms.add(new SOBoticsWorkshopChatRoom());
//rooms.add(new SEBoticsChatRoom());

//get current version
Properties guttenbergProperties = new Properties();
Expand All @@ -66,6 +84,7 @@ public static void main(String[] args) {
InputStream is = Status.class.getResourceAsStream("/guttenberg.properties");
guttenbergProperties.load(is);
version = guttenbergProperties.getProperty("version", "0.0.0");
LOGGER.info("Running on version " + version);
}
catch (IOException e){
LOGGER.error("Could not load properties", e);
Expand Down Expand Up @@ -100,14 +119,14 @@ public static void main(String[] args) {
redunda.start();


LOGGER.info("Launch Guttenberg...");
LOGGER.debug("Initialize RunnerService...");

RunnerService runner = new RunnerService(seClient, rooms);

runner.start();

StatusUtils.startupDate = Instant.now();
LOGGER.info(StatusUtils.startupDate + " - Successfully launched Guttenberg!");
LOGGER.info("Successfully launched Guttenberg!");
}

}
20 changes: 10 additions & 10 deletions src/main/java/org/sobotics/guttenberg/clients/Guttenberg.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ public void secureExecute() {
try {
execute();
} catch (Throwable e) {
LOGGER.error("Error throws in execute()", e);
LOGGER.error("Error thrown in execute()", e);
}
}

public void execute() throws Throwable {
boolean standbyMode = PingService.standby.get();
if (standbyMode == true) {
LOGGER.info("STANDBY - " + Instant.now());
LOGGER.info("STANDBY - Abort execute()");
return;
}

Instant startTime = Instant.now();
Properties props = new Properties();
LOGGER.info("Executing at - "+startTime);
LOGGER.info("Starting Guttenberg.execute() ...");

try {
props.load(new FileInputStream(FilePathUtils.generalPropertiesFile));
Expand Down Expand Up @@ -95,23 +95,23 @@ public void execute() throws Throwable {
return;
}

LOGGER.info("Add the answers to the PlagFinders...");
LOGGER.debug("Add the answers to the PlagFinders...");
//add relatedAnswers to the PlagFinders
for (PlagFinder finder : plagFinders) {
Integer targetId = finder.getTargetAnswerId();
//System.out.println("TargetID: "+targetId);
LOGGER.trace("Check targetID: " + targetId);

for (Post relatedItem : relatedAnswersUnsorted) {
//System.out.println(relatedItem);
LOGGER.trace("Related item: " + relatedItem);
if (relatedItem.getAnswerID() != null && relatedItem.getAnswerID() != targetId) {
finder.relatedAnswers.add(relatedItem);
//System.out.println("Added answer: "+relatedItem);
LOGGER.trace("Added answer: " + relatedItem);
}
}
}

LOGGER.info("There are "+plagFinders.size()+" PlagFinders");
LOGGER.info("Find the duplicates...");
LOGGER.debug("There are "+plagFinders.size()+" PlagFinders");
LOGGER.debug("Find the duplicates...");
//Let PlagFinders find the best match
List<PostMatch> allMatches = new ArrayList<PostMatch>();
for (PlagFinder finder : plagFinders) {
Expand All @@ -138,7 +138,7 @@ public void execute() throws Throwable {

StatusUtils.lastSucceededExecutionStarted = startTime;
StatusUtils.lastExecutionFinished = Instant.now();
LOGGER.info("Finished at - "+StatusUtils.lastExecutionFinished);
LOGGER.info("Guttenberg.execute() finished");
}

public static Properties getLoginProperties() {
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/sobotics/guttenberg/clients/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Updater() {
LOGGER.error("Could not load properties", e);
}

LOGGER.info("Loaded properties");
LOGGER.debug("Loaded properties");

String versionString = guttenbergProperties.getProperty("version", "0.0.0");
this.currentVersion = new Version(versionString);
Expand All @@ -49,24 +49,23 @@ public Updater() {
for (File file : files) {
if (file.isFile()) {
String name = file.getName();
//LOGGER.info("File: "+name);
LOGGER.debug("File: "+name);
Matcher matcher = pattern.matcher(name);
matcher.find();
//LOGGER.info("Init matcher");
LOGGER.debug("Init matcher");
String v = "";

try {
v = matcher.group(1);
} catch (Exception e) {
//LOGGER.error("ERROR", e);
LOGGER.warn("Filename " + name + " didn't match the pattern.", e);
}


//LOGGER.info("Matched");
if (v != null && v.length() > 0) {

LOGGER.debug("Matched");
Version version = new Version(v);

LOGGER.debug("Found version " + version.get());
if (this.currentVersion.compareTo(version) == -1) {
//higher than current version
if (this.newVersion.compareTo(version) == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void mention(Room room, PingMessageEvent event, boolean isReply, RunnerSe
new Check(message),
new ClearHelp(message),
new Feedback(message, event, room),
new LogLevel(message),
//new OptIn(message),
//new OptOut(message),
new Quota(message),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sobotics/guttenberg/commands/Alive.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean validate() {

@Override
public void execute(Room room, RunnerService instance) {
LOGGER.info("Someone wants to know, if I'm alive");
LOGGER.warn("Someone wants to know, if I'm alive");
room.send("The instance "+PingService.location+ " is running.\nStandby: "+PingService.standby.toString());
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/sobotics/guttenberg/commands/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public boolean validate() {
@Override
public void execute(Room room, RunnerService instance) {
String word = CommandUtils.extractData(message.getPlainContent()).trim();
Integer returnValue = 0;

if(word.contains(" ")){
String parts[] = word.split(" ");
}

if(word.contains("/"))
{
word = CommandUtils.getAnswerId(word);
Expand All @@ -65,10 +61,13 @@ public void execute(Room room, RunnerService instance) {
try {
JsonObject answer = ApiUtils.getAnswerDetailsById(answerId, "stackoverflow", prop.getProperty("apikey", ""));
JsonObject target = answer.get("items").getAsJsonArray().get(0).getAsJsonObject();
LOGGER.trace("Checking answer: " + target.toString());
PlagFinder finder = new PlagFinder(target);
finder.collectData();
List<PostMatch> matches = finder.matchesForReasons(true);

LOGGER.trace("Found " + matches.size() + " PostMatches");

if (matches.size() > 0) {
//sort the matches
Collections.sort(matches,
Expand All @@ -91,7 +90,7 @@ public void execute(Room room, RunnerService instance) {
room.replyTo(message.getId(), "No similar posts found.");
}
} catch (IOException e) {
LOGGER.error("ERROR", e);
LOGGER.error("Error while executing the \"check\"-command!", e);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/sobotics/guttenberg/commands/Feedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ public void execute(Room room, RunnerService instance) {
}

try {
reportId = Integer.parseInt(word);
reportId = CommandUtils.getPostIdFromUrl(word);
} catch (Exception e) {
LOGGER.info("Invalid report-ID", e);
LOGGER.error("Report-URL could not be parsed!", e);
}

if (reportId == -1)
return;

LOGGER.debug("Sending feedback " + type + " for report " + reportId);

try {
if (type.equalsIgnoreCase("tp") || type.equalsIgnoreCase("k")) {
if (!isSELink) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/sobotics/guttenberg/commands/Kill.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.sobotics.guttenberg.commands;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sobotics.guttenberg.services.RunnerService;
import org.sobotics.guttenberg.utils.CommandUtils;

Expand All @@ -9,6 +11,8 @@

public class Kill implements SpecialCommand {

private static final Logger LOGGER = LoggerFactory.getLogger(Kill.class);

private static final String CMD = "kill";
private final Message message;

Expand All @@ -26,11 +30,12 @@ public void execute(Room room, RunnerService instance) {
User user = message.getUser();

if (!user.isModerator() && !user.isRoomOwner()) {
LOGGER.warn("User " + user.getName() + " tried to kill the bot!");
room.replyTo(message.getId(), "Sorry, but only room-owners and moderators can use this command (@FelixSFD)");
return;
}

System.out.println("KILLED BY "+user.getName());
LOGGER.error("KILLED BY "+user.getName());
System.exit(0);
}

Expand Down
Loading

0 comments on commit f123323

Please sign in to comment.