Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var es = new EventSource(eventFeed + nextGame.id, init);
- es.onopen = function() {
- console.log("Connected!");
- }
- es.addEventListener("QuestionStart", function(e) {
- processQuestion(JSON.parse(e.data));
- });
- es.addEventListener("error", function(err) {
- console.log("Error: " + JSON.stringify(err));
- });
- }
- });
- function processQuestion(json) {
- var nextCounter = 0;
- AMentions = 0;
- BMentions = 0;
- CMentions = 0;
- console.log("-- " + json.question + " --");
- console.log("> Attempting to fetch answer...");
- var question = json.question;
- var questionLowercase = json.question;
- var questionSearch = questionLowercase;
- var questionNumber = json.number;
- var answer = 1;
- var notDetected = false;
- if (utilities.stringContains(questionSearch, "Which of these")) {
- questionSearch = questionSearch.replace("Which of these", "what");
- }
- if (utilities.stringContains(question, " not ")) {
- notDetected = true;
- console.log("Possible anti-bot question detected!");
- }
- var AMentions = 0;
- var BMentions = 0;
- var CMentions = 0;
- google(questionSearch, function(err, res) {
- if (err) {
- console.log("Failed to fetch answer!");
- return;
- }
- for (var i = 0; i < res.links.length; ++i) {
- var link = res.links[i];
- var body = res.body;
- if (link.title.indexOf(json.choices[0].choice) != -1) {
- AMentions++;
- }
- if (link.title.indexOf(json.choices[1].choice) != -1) {
- BMentions++;
- }
- if (link.title.indexOf(json.choices[2].choice) != -1) {
- CMentions++;
- }
- if (link.description.toLowerCase().indexOf(json.choices[0].choice.toLowerCase()) != -1) {
- AMentions++;
- }
- if (link.description.toLowerCase().indexOf(json.choices[1].choice.toLowerCase()) != -1) {
- BMentions++;
- }
- if (link.description.toLowerCase().indexOf(json.choices[2].choice.toLowerCase()) != -1) {
- CMentions++;
- }
- if (nextCounter < 4) {
- nextCounter += 1;
- if (res.next) res.next();
- }
- }
- if (!notDetected) {
- var highest = Math.max(AMentions, BMentions, CMentions);
- if (AMentions == highest) {
- answer = 1;
- } el
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement