-
-
Notifications
You must be signed in to change notification settings - Fork 10
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 #6 from SOBotics/bugfix/4-use-less-quota
Bugfix/4 use less quota
- Loading branch information
Showing
7 changed files
with
219 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
language: java | ||
jdk: | ||
- oraclejdk8 | ||
deploy: | ||
provider: releases | ||
api_key: "FLKt5pVsysQnhXEk3umg" | ||
file: "Guttenberg.jar" | ||
skip_cleanup: true | ||
on: | ||
tags: true |
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
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
51 changes: 51 additions & 0 deletions
51
src/main/java/org/sobotics/guttenberg/commands/Pfiatdi.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,51 @@ | ||
package org.sobotics.guttenberg.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import org.sobotics.guttenberg.utils.CommandUtils; | ||
|
||
import fr.tunaki.stackoverflow.chat.Message; | ||
import fr.tunaki.stackoverflow.chat.Room; | ||
|
||
/** | ||
* Created by bhargav.h on 30-Sep-16. | ||
*/ | ||
public class Pfiatdi implements SpecialCommand { | ||
|
||
private Message message; | ||
|
||
public Pfiatdi(Message message) { | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public boolean validate() { | ||
return CommandUtils.checkForCommand(message.getPlainContent(),"cya") || | ||
CommandUtils.checkForCommand(message.getPlainContent(),"o/") || | ||
CommandUtils.checkForCommand(message.getPlainContent(),"bye"); | ||
} | ||
|
||
@Override | ||
public void execute(Room room) { | ||
List<String> array = new ArrayList<String>(); | ||
array.add("[Pfiat di!](http://german.stackexchange.com/q/254) o/"); | ||
array.add("[Pfiats eich!](http://german.stackexchange.com/q/254)"); | ||
array.add("[Pfüad di Gott](http://german.stackexchange.com/q/254) o/"); | ||
|
||
int rnd = new Random().nextInt(array.size()); | ||
|
||
room.send(array.get(rnd)); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Psscht. Hier derfsch it naluaga!"; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "secret"; | ||
} | ||
} |
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
98 changes: 98 additions & 0 deletions
98
src/main/java/org/sobotics/guttenberg/finders/RelatedAnswersFinder.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,98 @@ | ||
package org.sobotics.guttenberg.finders; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import org.sobotics.guttenberg.utils.ApiUtils; | ||
import org.sobotics.guttenberg.utils.FilePathUtils; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
|
||
/** | ||
* Collects all related answers in less API calls | ||
* */ | ||
public class RelatedAnswersFinder { | ||
/** | ||
* The question_ids of the targeted answers | ||
* */ | ||
List<Integer> targedIds; | ||
|
||
public RelatedAnswersFinder(List<Integer> ids) { | ||
this.targedIds = ids; | ||
} | ||
|
||
|
||
public List<JsonObject> fetchRelatedAnswers() { | ||
//The question_ids of all the new answers | ||
String idString = ""; | ||
int n = 0; | ||
for (Integer id : this.targedIds) { | ||
idString += n++ == 0 ? id : ";"+id; | ||
} | ||
|
||
System.out.println(idString); | ||
|
||
Properties prop = new Properties(); | ||
|
||
try{ | ||
prop.load(new FileInputStream(FilePathUtils.loginPropertiesFile)); | ||
} | ||
catch (IOException e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
System.out.println("Fetch the linked/related questions..."); | ||
|
||
try { | ||
JsonObject relatedQuestions = ApiUtils.getRelatedQuestionsByIds(idString, "stackoverflow", prop.getProperty("apikey", "")); | ||
JsonObject linkedQuestions = ApiUtils.getLinkedQuestionsByIds(idString, "stackoverflow", prop.getProperty("apikey", "")); | ||
|
||
String relatedIds = ""; | ||
|
||
for (JsonElement question : relatedQuestions.get("items").getAsJsonArray()) { | ||
int id = question.getAsJsonObject().get("question_id").getAsInt(); | ||
//System.out.println("Add: "+id); | ||
relatedIds += id+";"; | ||
} | ||
|
||
for (JsonElement question : linkedQuestions.get("items").getAsJsonArray()) { | ||
int id = question.getAsJsonObject().get("question_id").getAsInt(); | ||
//System.out.println("Add: "+id); | ||
relatedIds += id+";"; | ||
} | ||
|
||
if (relatedIds.length() > 0) { | ||
relatedIds = relatedIds.substring(0, relatedIds.length()-1); | ||
|
||
List<JsonObject> relatedFinal = new ArrayList<JsonObject>(); | ||
|
||
JsonObject relatedAnswers = ApiUtils.getAnswersToQuestionsByIdString(relatedIds, "stackoverflow", prop.getProperty("apikey", "")); | ||
//System.out.println(relatedAnswers); | ||
for (JsonElement answer : relatedAnswers.get("items").getAsJsonArray()) { | ||
JsonObject answerObject = answer.getAsJsonObject(); | ||
relatedFinal.add(answerObject); | ||
} | ||
|
||
System.out.println("Collected "+relatedFinal.size()+" answers"); | ||
return relatedFinal; | ||
} else { | ||
System.out.println("No ids found!"); | ||
} | ||
|
||
|
||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
|
||
return null; | ||
} | ||
|
||
|
||
} |
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