mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix poe
This commit is contained in:
150
poe-client.js
150
poe-client.js
@@ -33,36 +33,41 @@ const cached_bots = {};
|
|||||||
|
|
||||||
const logger = console;
|
const logger = console;
|
||||||
|
|
||||||
const user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0";
|
const user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36";
|
||||||
|
|
||||||
|
function unscrambleFormkey(c, code) {
|
||||||
|
var e;
|
||||||
|
eval(code);
|
||||||
|
return e.join('');
|
||||||
|
}
|
||||||
|
|
||||||
function queryScrambler() {
|
function queryScrambler() {
|
||||||
function a(e, t) {
|
function a(e, t) {
|
||||||
var r = (65535 & e) + (65535 & t);
|
var r = (65535 & e) + (65535 & t);
|
||||||
return (e >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r
|
return (e >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r
|
||||||
}
|
}
|
||||||
function s(e, t, r, n, i, s) {
|
function s(e, t, r, n, i, s) {
|
||||||
var o;
|
var o;
|
||||||
return a((o = a(a(t, e), a(n, s))) << i | o >>> 32 - i, r)
|
return a((o = a(a(t, e), a(n, s))) << i | o >>> 32 - i, r)
|
||||||
}
|
}
|
||||||
function o(e, t, r, n, i, a, o) {
|
function o(e, t, r, n, i, a, o) {
|
||||||
return s(t & r | ~t & n, e, t, i, a, o)
|
return s(t & r | ~t & n, e, t, i, a, o)
|
||||||
}
|
}
|
||||||
function l(e, t, r, n, i, a, o) {
|
function l(e, t, r, n, i, a, o) {
|
||||||
return s(t & n | r & ~n, e, t, i, a, o)
|
return s(t & n | r & ~n, e, t, i, a, o)
|
||||||
}
|
}
|
||||||
function u(e, t, r, n, i, a, o) {
|
function u(e, t, r, n, i, a, o) {
|
||||||
return s(t ^ r ^ n, e, t, i, a, o)
|
return s(t ^ r ^ n, e, t, i, a, o)
|
||||||
}
|
}
|
||||||
function c(e, t, r, n, i, a, o) {
|
function c(e, t, r, n, i, a, o) {
|
||||||
return s(r ^ (t | ~n), e, t, i, a, o)
|
return s(r ^ (t | ~n), e, t, i, a, o)
|
||||||
}
|
}
|
||||||
function d(e, t) {
|
function d(e, t) {
|
||||||
e[t >> 5] |= 128 << t % 32,
|
e[t >> 5] |= 128 << t % 32,
|
||||||
e[(t + 64 >>> 9 << 4) + 14] = t;
|
e[(t + 64 >>> 9 << 4) + 14] = t;
|
||||||
var r, n, i, s, d, f = 1732584193, h = -271733879, p = -1732584194, _ = 271733878;
|
var r, n, i, s, d, f = 1732584193, h = -271733879, p = -1732584194, _ = 271733878;
|
||||||
for (r = 0; r < e.length; r += 16)
|
for (r = 0; r < e.length; r += 16)
|
||||||
n = f,
|
n = f,
|
||||||
i = h,
|
i = h,
|
||||||
s = p,
|
s = p,
|
||||||
d = _,
|
d = _,
|
||||||
@@ -134,49 +139,49 @@ function queryScrambler() {
|
|||||||
h = a(h, i),
|
h = a(h, i),
|
||||||
p = a(p, s),
|
p = a(p, s),
|
||||||
_ = a(_, d);
|
_ = a(_, d);
|
||||||
return [f, h, p, _]
|
return [f, h, p, _]
|
||||||
}
|
}
|
||||||
function f(e) {
|
function f(e) {
|
||||||
var t, r = "", n = 32 * e.length;
|
var t, r = "", n = 32 * e.length;
|
||||||
for (t = 0; t < n; t += 8)
|
for (t = 0; t < n; t += 8)
|
||||||
r += String.fromCharCode(e[t >> 5] >>> t % 32 & 255);
|
r += String.fromCharCode(e[t >> 5] >>> t % 32 & 255);
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
function h(e) {
|
function h(e) {
|
||||||
var t, r = [];
|
var t, r = [];
|
||||||
for (t = 0,
|
for (t = 0,
|
||||||
r[(e.length >> 2) - 1] = void 0; t < r.length; t += 1)
|
r[(e.length >> 2) - 1] = void 0; t < r.length; t += 1)
|
||||||
r[t] = 0;
|
r[t] = 0;
|
||||||
var n = 8 * e.length;
|
var n = 8 * e.length;
|
||||||
for (t = 0; t < n; t += 8)
|
for (t = 0; t < n; t += 8)
|
||||||
r[t >> 5] |= (255 & e.charCodeAt(t / 8)) << t % 32;
|
r[t >> 5] |= (255 & e.charCodeAt(t / 8)) << t % 32;
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
function p(e) {
|
function p(e) {
|
||||||
var t, r, n = "0123456789abcdef", i = "";
|
var t, r, n = "0123456789abcdef", i = "";
|
||||||
for (r = 0; r < e.length; r += 1)
|
for (r = 0; r < e.length; r += 1)
|
||||||
i += n.charAt((t = e.charCodeAt(r)) >>> 4 & 15) + n.charAt(15 & t);
|
i += n.charAt((t = e.charCodeAt(r)) >>> 4 & 15) + n.charAt(15 & t);
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
function _(e) {
|
function _(e) {
|
||||||
return unescape(encodeURIComponent(e))
|
return unescape(encodeURIComponent(e))
|
||||||
}
|
}
|
||||||
function v(e) {
|
function v(e) {
|
||||||
var t;
|
var t;
|
||||||
return f(d(h(t = _(e)), 8 * t.length))
|
return f(d(h(t = _(e)), 8 * t.length))
|
||||||
}
|
}
|
||||||
function g(e, t) {
|
function g(e, t) {
|
||||||
return function(e, t) {
|
return function (e, t) {
|
||||||
var r, n, i = h(e), a = [], s = [];
|
var r, n, i = h(e), a = [], s = [];
|
||||||
for (a[15] = s[15] = void 0,
|
for (a[15] = s[15] = void 0,
|
||||||
i.length > 16 && (i = d(i, 8 * e.length)),
|
i.length > 16 && (i = d(i, 8 * e.length)),
|
||||||
r = 0; r < 16; r += 1)
|
r = 0; r < 16; r += 1)
|
||||||
a[r] = 909522486 ^ i[r],
|
a[r] = 909522486 ^ i[r],
|
||||||
s[r] = 1549556828 ^ i[r];
|
s[r] = 1549556828 ^ i[r];
|
||||||
return n = d(a.concat(h(t)), 512 + 8 * t.length),
|
return n = d(a.concat(h(t)), 512 + 8 * t.length),
|
||||||
f(d(s.concat(n), 640))
|
f(d(s.concat(n), 640))
|
||||||
}(_(e), _(t))
|
}(_(e), _(t))
|
||||||
}
|
}
|
||||||
function m(e, t, r) {
|
function m(e, t, r) {
|
||||||
return t ? r ? g(t, e) : p(g(t, e)) : r ? v(e) : p(v(e))
|
return t ? r ? g(t, e) : p(g(t, e)) : r ? v(e) : p(v(e))
|
||||||
}
|
}
|
||||||
@@ -284,10 +289,13 @@ class Client {
|
|||||||
|
|
||||||
const r = await request_with_retries(() => this.session.get(this.home_url));
|
const r = await request_with_retries(() => this.session.get(this.home_url));
|
||||||
const jsonRegex = /<script id="__NEXT_DATA__" type="application\/json">(.+?)<\/script>/;
|
const jsonRegex = /<script id="__NEXT_DATA__" type="application\/json">(.+?)<\/script>/;
|
||||||
|
const formKeyRegex = /var c="(.+?)",(.+?),window./;
|
||||||
const jsonText = jsonRegex.exec(r.data)[1];
|
const jsonText = jsonRegex.exec(r.data)[1];
|
||||||
|
const key = formKeyRegex.exec(r.data)[1];
|
||||||
|
const code = formKeyRegex.exec(r.data)[2];
|
||||||
const nextData = JSON.parse(jsonText);
|
const nextData = JSON.parse(jsonText);
|
||||||
|
|
||||||
this.formkey = nextData.props.formkey;
|
this.formkey = unscrambleFormkey(key, code);
|
||||||
this.viewer = nextData.props.pageProps.payload.viewer;
|
this.viewer = nextData.props.pageProps.payload.viewer;
|
||||||
|
|
||||||
return nextData;
|
return nextData;
|
||||||
@@ -304,7 +312,7 @@ class Client {
|
|||||||
for (const bot of botList.filter(x => x.deletionState == 'not_deleted')) {
|
for (const bot of botList.filter(x => x.deletionState == 'not_deleted')) {
|
||||||
const url = `https://poe.com/_next/data/${this.next_data.buildId}/${bot.displayName}.json`;
|
const url = `https://poe.com/_next/data/${this.next_data.buildId}/${bot.displayName}.json`;
|
||||||
let r;
|
let r;
|
||||||
|
|
||||||
if (this.use_cached_bots && cached_bots[url]) {
|
if (this.use_cached_bots && cached_bots[url]) {
|
||||||
r = cached_bots[url];
|
r = cached_bots[url];
|
||||||
}
|
}
|
||||||
@@ -335,7 +343,6 @@ class Client {
|
|||||||
const r = await request_with_retries(() => this.session.get(this.settings_url));
|
const r = await request_with_retries(() => this.session.get(this.settings_url));
|
||||||
const data = r.data;
|
const data = r.data;
|
||||||
|
|
||||||
this.formkey = data.formkey;
|
|
||||||
return data.tchannelData;
|
return data.tchannelData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,6 +361,7 @@ class Client {
|
|||||||
const scramblePayload = JSON.stringify(payload);
|
const scramblePayload = JSON.stringify(payload);
|
||||||
const _headers = this.gql_headers;
|
const _headers = this.gql_headers;
|
||||||
_headers['poe-tag-id'] = queryScrambler()(scramblePayload + this.formkey + "WpuLMiXEKKE98j56k");
|
_headers['poe-tag-id'] = queryScrambler()(scramblePayload + this.formkey + "WpuLMiXEKKE98j56k");
|
||||||
|
_headers['poe-formkey'] = this.formkey;
|
||||||
const r = await request_with_retries(() => this.session.post(this.gql_url, payload, { headers: this.gql_headers }));
|
const r = await request_with_retries(() => this.session.post(this.gql_url, payload, { headers: this.gql_headers }));
|
||||||
if (!r.data.data) {
|
if (!r.data.data) {
|
||||||
logger.warn(`${queryName} returned an error: ${data.errors[0].message} | Retrying (${i + 1}/20)`);
|
logger.warn(`${queryName} returned an error: ${data.errors[0].message} | Retrying (${i + 1}/20)`);
|
||||||
@@ -385,7 +393,7 @@ class Client {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'subscriptionsMutation');
|
'subscriptionsMutation');
|
||||||
}
|
}
|
||||||
|
|
||||||
ws_run_thread() {
|
ws_run_thread() {
|
||||||
@@ -452,7 +460,7 @@ class Client {
|
|||||||
for (const message_str of data["messages"]) {
|
for (const message_str of data["messages"]) {
|
||||||
const message_data = JSON.parse(message_str);
|
const message_data = JSON.parse(message_str);
|
||||||
|
|
||||||
if (message_data["message_type"] != "subscriptionUpdate"){
|
if (message_data["message_type"] != "subscriptionUpdate") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,7 +469,7 @@ class Client {
|
|||||||
if (!message) {
|
if (!message) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const copiedDict = Object.assign({}, this.active_messages);
|
const copiedDict = Object.assign({}, this.active_messages);
|
||||||
for (const [key, value] of Object.entries(copiedDict)) {
|
for (const [key, value] of Object.entries(copiedDict)) {
|
||||||
//add the message to the appropriate queue
|
//add the message to the appropriate queue
|
||||||
@@ -469,7 +477,7 @@ class Client {
|
|||||||
this.message_queues[key].push(message);
|
this.message_queues[key].push(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//indicate that the response id is tied to the human message id
|
//indicate that the response id is tied to the human message id
|
||||||
else if (key !== "pending" && value === null && message["state"] !== "complete") {
|
else if (key !== "pending" && value === null && message["state"] !== "complete") {
|
||||||
this.active_messages[key] = message["messageId"];
|
this.active_messages[key] = message["messageId"];
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
subscription MessageDeletedSubscription($chatId: BigInt!) {
|
subscription subscriptions_messageDeleted_Subscription(
|
||||||
messageDeleted(chatId: $chatId) {
|
$chatId: BigInt!
|
||||||
id
|
) {
|
||||||
messageId
|
messageDeleted(chatId: $chatId) {
|
||||||
}
|
id
|
||||||
|
messageId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,6 +62,13 @@ fragment SubscriptionMessageLimitExplanation_viewer on Viewer {
|
|||||||
|
|
||||||
fragment WebSubscriptionPaywall_viewer on Viewer {
|
fragment WebSubscriptionPaywall_viewer on Viewer {
|
||||||
...SubscriptionMessageLimitExplanation_viewer
|
...SubscriptionMessageLimitExplanation_viewer
|
||||||
|
webSubscriptionPriceInfo {
|
||||||
|
monthlyPrice
|
||||||
|
yearlyPrice
|
||||||
|
yearlyPricePerMonth
|
||||||
|
yearlyPercentageSavings
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment WebSubscriptionSuccessMessage_viewer on Viewer {
|
fragment WebSubscriptionSuccessMessage_viewer on Viewer {
|
||||||
|
Reference in New Issue
Block a user