Future-proof a bit

This commit is contained in:
lilyissillyyy
2025-08-24 11:01:51 -04:00
parent e8aa75b084
commit a0401a0783
+5 -9
View File
@@ -1,5 +1,5 @@
const request = require('node-superfetch'); const request = require('node-superfetch');
const { decode: decodeHTML } = require('html-entities'); const cheerio = require('cheerio');
const regions = ['en', 'ar', 'cn', 'de', 'es', 'fr', 'il', 'it', 'jp', 'kr', 'nl', 'pt', 'ru', 'tr', 'id']; const regions = ['en', 'ar', 'cn', 'de', 'es', 'fr', 'il', 'it', 'jp', 'kr', 'nl', 'pt', 'ru', 'tr', 'id'];
const answers = ['Yes', 'No', 'Don\'t know', 'Probably', 'Probably not']; const answers = ['Yes', 'No', 'Don\'t know', 'Probably', 'Probably not'];
@@ -27,16 +27,12 @@ class Akinator {
sid: '1', sid: '1',
cm: this.childMode cm: this.childMode
}); });
this.question = text.match(/<p class="question-text" id="question-label">(.+)<\/p>/)[1]; const $ = cheerio.load(text);
this.question = $('.question-text').text();
this.session = text.match(/session: '(.+)'/)[1]; this.session = text.match(/session: '(.+)'/)[1];
this.signature = text.match(/signature: '(.+)'/)[1]; this.signature = text.match(/signature: '(.+)'/)[1];
this.answers = [ this.answers = [];
decodeHTML(text.match(/<a class="li-game" href="#" id="a_yes" data-index="0">(.+)<\/a>/)[1]), $('.li-game').each((i, elem) => this.answers.push($(elem).text()));
decodeHTML(text.match(/<a class="li-game" href="#" id="a_no" data-index="1">(.+)<\/a>/)[1]),
decodeHTML(text.match(/<a class="li-game" href="#" id="a_dont_know" data-index="2">(.+)<\/a>/)[1]),
decodeHTML(text.match(/<a class="li-game" href="#" id="a_probably" data-index="3">(.+)<\/a>/)[1]),
decodeHTML(text.match(/<a class="li-game" href="#" id="a_probaly_not" data-index="4">(.+)<\/a>/)[1])
];
return this; return this;
} }