sillytavern 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +4 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/workflows/npm-publish.yml +32 -0
- package/Dockerfile +49 -0
- package/Start.bat +3 -0
- package/colab/GPU.ipynb +339 -0
- package/colab/extras_server.py +40 -0
- package/colab/globals.py +2 -0
- package/colab/models.py +77 -0
- package/docker/docker-compose.yml +12 -0
- package/docker/docker-entrypoint.sh +28 -0
- package/faq.md +208 -0
- package/package.json +49 -0
- package/poe-client.js +638 -0
- package/poe-test.js +21 -0
- package/poe_graphql/AddHumanMessageMutation.graphql +52 -0
- package/poe_graphql/AddMessageBreakMutation.graphql +17 -0
- package/poe_graphql/AutoSubscriptionMutation.graphql +7 -0
- package/poe_graphql/BioFragment.graphql +8 -0
- package/poe_graphql/ChatAddedSubscription.graphql +5 -0
- package/poe_graphql/ChatFragment.graphql +6 -0
- package/poe_graphql/ChatListPaginationQuery.graphql +316 -0
- package/poe_graphql/ChatPaginationQuery.graphql +26 -0
- package/poe_graphql/ChatViewQuery.graphql +8 -0
- package/poe_graphql/DeleteHumanMessagesMutation.graphql +7 -0
- package/poe_graphql/DeleteMessageMutation.graphql +7 -0
- package/poe_graphql/HandleFragment.graphql +8 -0
- package/poe_graphql/LoginWithVerificationCodeMutation.graphql +13 -0
- package/poe_graphql/MessageAddedSubscription.graphql +115 -0
- package/poe_graphql/MessageDeletedSubscription.graphql +8 -0
- package/poe_graphql/MessageFragment.graphql +13 -0
- package/poe_graphql/MessageRemoveVoteMutation.graphql +7 -0
- package/poe_graphql/MessageSetVoteMutation.graphql +7 -0
- package/poe_graphql/SendVerificationCodeForLoginMutation.graphql +12 -0
- package/poe_graphql/ShareMessagesMutation.graphql +9 -0
- package/poe_graphql/SignupWithVerificationCodeMutation.graphql +13 -0
- package/poe_graphql/StaleChatUpdateMutation.graphql +7 -0
- package/poe_graphql/SubscriptionsMutation.graphql +9 -0
- package/poe_graphql/SummarizePlainPostQuery.graphql +3 -0
- package/poe_graphql/SummarizeQuotePostQuery.graphql +3 -0
- package/poe_graphql/SummarizeSharePostQuery.graphql +3 -0
- package/poe_graphql/UserSnippetFragment.graphql +14 -0
- package/poe_graphql/ViewerInfoQuery.graphql +21 -0
- package/poe_graphql/ViewerMessageLimitUpdatedSubscription.graphql +81 -0
- package/poe_graphql/ViewerStateFragment.graphql +30 -0
- package/poe_graphql/ViewerStateUpdatedSubscription.graphql +63 -0
- package/public/KoboldAI Settings/Ace of Spades 13B.settings +22 -0
- package/public/KoboldAI Settings/Adventurer-NeoX-20B-Erebus.settings +54 -0
- package/public/KoboldAI Settings/Basic Coherence 13B.settings +22 -0
- package/public/KoboldAI Settings/Best Guess 6B.settings +22 -0
- package/public/KoboldAI Settings/Calibrated-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Classic-Pygmalion-2.7b.settings +46 -0
- package/public/KoboldAI Settings/Classic-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Coherent Creativity 6B.settings +22 -0
- package/public/KoboldAI Settings/Default-TavernAI.settings +22 -0
- package/public/KoboldAI Settings/DragonSlayer-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/GPU-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Genesis 13B.settings +22 -0
- package/public/KoboldAI Settings/Godlike.settings +22 -0
- package/public/KoboldAI Settings/Good Winds.settings +22 -0
- package/public/KoboldAI Settings/Lancer-OPT-2.7B-Erebus.settings +54 -0
- package/public/KoboldAI Settings/Liminal Drift.settings +22 -0
- package/public/KoboldAI Settings/Low Rider 13B.settings +22 -0
- package/public/KoboldAI Settings/Luna Moth 6B.settings +22 -0
- package/public/KoboldAI Settings/Mayday.settings +22 -0
- package/public/KoboldAI Settings/Ouroboros.settings +22 -0
- package/public/KoboldAI Settings/Pleasing Results 6B.settings +22 -0
- package/public/KoboldAI Settings/Pro Writer 13B.settings +22 -0
- package/public/KoboldAI Settings/RA - Pygmalion-1.3b.settings +46 -0
- package/public/KoboldAI Settings/Storywriter 6B.settings +22 -0
- package/public/NovelAI Settings/Classic-Euterpe.settings +14 -0
- package/public/NovelAI Settings/Classic-Krake.settings +14 -0
- package/public/OpenAI Settings/Default.settings +15 -0
- package/public/TextGen Settings/Beam Search.settings +15 -0
- package/public/TextGen Settings/Contrastive Search.settings +15 -0
- package/public/TextGen Settings/Default.settings +15 -0
- package/public/TextGen Settings/Deterministic.settings +15 -0
- package/public/TextGen Settings/Kobold (Godlike).settings +15 -0
- package/public/TextGen Settings/Kobold (Liminal Drift).settings +15 -0
- package/public/TextGen Settings/Naive.settings +15 -0
- package/public/TextGen Settings/NovelAI (Best Guess).settings +15 -0
- package/public/TextGen Settings/NovelAI (Decadence).settings +15 -0
- package/public/TextGen Settings/NovelAI (Genesis).settings +15 -0
- package/public/TextGen Settings/NovelAI (Lycaenidae).settings +15 -0
- package/public/TextGen Settings/NovelAI (Ouroboros).settings +15 -0
- package/public/TextGen Settings/NovelAI (Pleasing Results).settings +15 -0
- package/public/TextGen Settings/NovelAI (Sphinx Moth).settings +15 -0
- package/public/TextGen Settings/NovelAI (Storywriter).settings +15 -0
- package/public/TextGen Settings/Pygmalion.settings +15 -0
- package/public/css/fontawesome.css +8488 -0
- package/public/css/notes.css +46 -0
- package/public/css/solid.css +24 -0
- package/public/favicon.ico +0 -0
- package/public/img/No-Image-Placeholder.svg +309 -0
- package/public/img/addbg3.png +0 -0
- package/public/img/ai4.png +0 -0
- package/public/img/apple-icon-114x114.png +0 -0
- package/public/img/apple-icon-144x144.png +0 -0
- package/public/img/apple-icon-57x57.png +0 -0
- package/public/img/apple-icon-72x72.png +0 -0
- package/public/img/book2.png +0 -0
- package/public/img/default-expressions/admiration.png +0 -0
- package/public/img/default-expressions/amusement.png +0 -0
- package/public/img/default-expressions/anger.png +0 -0
- package/public/img/default-expressions/annoyance.png +0 -0
- package/public/img/default-expressions/approval.png +0 -0
- package/public/img/default-expressions/caring.png +0 -0
- package/public/img/default-expressions/confusion.png +0 -0
- package/public/img/default-expressions/curiosity.png +0 -0
- package/public/img/default-expressions/desire.png +0 -0
- package/public/img/default-expressions/desire1.png +0 -0
- package/public/img/default-expressions/desire2.png +0 -0
- package/public/img/default-expressions/disappointment.png +0 -0
- package/public/img/default-expressions/disapproval.png +0 -0
- package/public/img/default-expressions/disgust.png +0 -0
- package/public/img/default-expressions/embarrassment.png +0 -0
- package/public/img/default-expressions/excitement.png +0 -0
- package/public/img/default-expressions/fear.png +0 -0
- package/public/img/default-expressions/gratitude.png +0 -0
- package/public/img/default-expressions/grief.png +0 -0
- package/public/img/default-expressions/joy.png +0 -0
- package/public/img/default-expressions/love.png +0 -0
- package/public/img/default-expressions/nervousness.png +0 -0
- package/public/img/default-expressions/neutral.png +0 -0
- package/public/img/default-expressions/optimism.png +0 -0
- package/public/img/default-expressions/pride.png +0 -0
- package/public/img/default-expressions/realization.png +0 -0
- package/public/img/default-expressions/relief.png +0 -0
- package/public/img/default-expressions/remorse.png +0 -0
- package/public/img/default-expressions/sadness.png +0 -0
- package/public/img/default-expressions/surprise.png +0 -0
- package/public/img/five.png +0 -0
- package/public/img/times-circle.svg +1 -0
- package/public/img/you.png +0 -0
- package/public/index.html +1899 -0
- package/public/notes/1.html +44 -0
- package/public/notes/1.png +0 -0
- package/public/notes/10.html +20 -0
- package/public/notes/11.html +33 -0
- package/public/notes/12.html +27 -0
- package/public/notes/13.html +29 -0
- package/public/notes/13_1.html +24 -0
- package/public/notes/13_2.html +25 -0
- package/public/notes/13_3.html +89 -0
- package/public/notes/14.html +30 -0
- package/public/notes/2.html +37 -0
- package/public/notes/2.png +0 -0
- package/public/notes/3.html +37 -0
- package/public/notes/4.html +105 -0
- package/public/notes/6.html +33 -0
- package/public/notes/7.html +40 -0
- package/public/notes/8.html +19 -0
- package/public/notes/9.html +46 -0
- package/public/notes/advanced_formatting.html +91 -0
- package/public/notes/group_reply_strategy.html +63 -0
- package/public/notes/message_sound.html +33 -0
- package/public/notes/multigen.html +36 -0
- package/public/notes/oai_api_key.html +37 -0
- package/public/notes/textgen_streaming.html +29 -0
- package/public/notes/token-limits.html +68 -0
- package/public/script.js +5131 -0
- package/public/scripts/RossAscends-mods.js +750 -0
- package/public/scripts/bookmarks.js +130 -0
- package/public/scripts/extensions/backgrounds/index.js +129 -0
- package/public/scripts/extensions/backgrounds/manifest.json +11 -0
- package/public/scripts/extensions/backgrounds/style.css +45 -0
- package/public/scripts/extensions/caption/index.js +117 -0
- package/public/scripts/extensions/caption/manifest.json +13 -0
- package/public/scripts/extensions/caption/style.css +23 -0
- package/public/scripts/extensions/dice/droll.js +108 -0
- package/public/scripts/extensions/dice/index.js +96 -0
- package/public/scripts/extensions/dice/manifest.json +11 -0
- package/public/scripts/extensions/dice/style.css +26 -0
- package/public/scripts/extensions/expressions/index.js +387 -0
- package/public/scripts/extensions/expressions/manifest.json +13 -0
- package/public/scripts/extensions/expressions/style.css +115 -0
- package/public/scripts/extensions/floating-prompt/index.js +151 -0
- package/public/scripts/extensions/floating-prompt/manifest.json +11 -0
- package/public/scripts/extensions/floating-prompt/style.css +19 -0
- package/public/scripts/extensions/memory/index.js +358 -0
- package/public/scripts/extensions/memory/manifest.json +13 -0
- package/public/scripts/extensions/memory/style.css +34 -0
- package/public/scripts/extensions.js +288 -0
- package/public/scripts/f-localStorage.js +27 -0
- package/public/scripts/gpt-2-3-tokenizer/README.md +28 -0
- package/public/scripts/gpt-2-3-tokenizer/encoder.js +1 -0
- package/public/scripts/gpt-2-3-tokenizer/mod.js +169 -0
- package/public/scripts/gpt-2-3-tokenizer/vocab.bpe.js +1 -0
- package/public/scripts/gpt-3-tokenizer/array-keyed-map.js +210 -0
- package/public/scripts/gpt-3-tokenizer/gpt3-tokenizer.js +271 -0
- package/public/scripts/gpt-3-tokenizer/gpt3-tokenizer.js.map +1 -0
- package/public/scripts/group-chats.js +899 -0
- package/public/scripts/horde.js +214 -0
- package/public/scripts/jquery-3.5.1.min.js +2 -0
- package/public/scripts/jquery-cookie-1.4.1.min.js +2 -0
- package/public/scripts/jquery.transit.min.js +1 -0
- package/public/scripts/kai-settings.js +179 -0
- package/public/scripts/nai-settings.js +108 -0
- package/public/scripts/openai.js +973 -0
- package/public/scripts/poe.js +360 -0
- package/public/scripts/popper.js +2008 -0
- package/public/scripts/popper.js.map +1 -0
- package/public/scripts/power-user.js +571 -0
- package/public/scripts/purify.min.js +3 -0
- package/public/scripts/purify.min.js.map +1 -0
- package/public/scripts/showdown.min.js +3 -0
- package/public/scripts/showdown.min.js.map +1 -0
- package/public/scripts/swiped-events.js +165 -0
- package/public/scripts/textgen-settings.js +194 -0
- package/public/scripts/toolcool-color-picker.js +87 -0
- package/public/scripts/utils.js +109 -0
- package/public/scripts/world-info.js +661 -0
- package/public/sounds/message.mp3 +0 -0
- package/public/style.css +3633 -0
- package/public/webfonts/NotoSans/NotoSans-Black.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Black.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-BlackItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-BlackItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Bold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Bold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-BoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-BoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLight.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLight.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLightItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLightItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Italic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Italic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Light.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Light.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-LightItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-LightItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Medium.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Medium.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-MediumItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-MediumItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Regular.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Regular.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Thin.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Thin.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ThinItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ThinItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/stylesheet.css +162 -0
- package/public/webfonts/fa-solid-900.ttf +0 -0
- package/public/webfonts/fa-solid-900.woff2 +0 -0
- package/readme.md +187 -0
- package/server.js +2593 -0
- package/start.sh +24 -0
- package/tools/charaverter/main.mjs +110 -0
- package/tools/charaverter/package.json +10 -0
package/poe-client.js
ADDED
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Adapted and rewritten to Node based on ading2210/poe-api
|
|
3
|
+
|
|
4
|
+
ading2210/poe-api: a reverse engineered Python API wrapper for Quora's Poe
|
|
5
|
+
Copyright (C) 2023 ading2210
|
|
6
|
+
|
|
7
|
+
This program is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
This program is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
GNU General Public License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const WebSocket = require('ws');
|
|
22
|
+
const axios = require('axios');
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
const http = require('http');
|
|
26
|
+
const https = require('https');
|
|
27
|
+
|
|
28
|
+
const parent_path = path.resolve(__dirname);
|
|
29
|
+
const queries_path = path.join(parent_path, "poe_graphql");
|
|
30
|
+
let queries = {};
|
|
31
|
+
|
|
32
|
+
const cached_bots = {};
|
|
33
|
+
|
|
34
|
+
const logger = console;
|
|
35
|
+
|
|
36
|
+
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";
|
|
37
|
+
|
|
38
|
+
function extractFormKey(html) {
|
|
39
|
+
const scriptRegex = /<script>if\(.+\)throw new Error;(.+)<\/script>/;
|
|
40
|
+
const scriptText = html.match(scriptRegex)[1];
|
|
41
|
+
const keyRegex = /var .="([0-9a-f]+)",/;
|
|
42
|
+
const keyText = scriptText.match(keyRegex)[1];
|
|
43
|
+
const cipherRegex = /.\[(\d+)\]=.\[(\d+)\]/g;
|
|
44
|
+
const cipherPairs = Array.from(scriptText.matchAll(cipherRegex));
|
|
45
|
+
|
|
46
|
+
const formKeyList = new Array(cipherPairs.length).fill("");
|
|
47
|
+
for (const pair of cipherPairs) {
|
|
48
|
+
const [formKeyIndex, keyIndex] = pair.slice(1).map(Number);
|
|
49
|
+
formKeyList[formKeyIndex] = keyText[keyIndex];
|
|
50
|
+
}
|
|
51
|
+
const formKey = formKeyList.join("");
|
|
52
|
+
|
|
53
|
+
return formKey;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
function md5() {
|
|
58
|
+
function a(e, t) {
|
|
59
|
+
var r = (65535 & e) + (65535 & t);
|
|
60
|
+
return (e >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r
|
|
61
|
+
}
|
|
62
|
+
function s(e, t, r, n, i, s) {
|
|
63
|
+
var o;
|
|
64
|
+
return a((o = a(a(t, e), a(n, s))) << i | o >>> 32 - i, r)
|
|
65
|
+
}
|
|
66
|
+
function o(e, t, r, n, i, a, o) {
|
|
67
|
+
return s(t & r | ~t & n, e, t, i, a, o)
|
|
68
|
+
}
|
|
69
|
+
function l(e, t, r, n, i, a, o) {
|
|
70
|
+
return s(t & n | r & ~n, e, t, i, a, o)
|
|
71
|
+
}
|
|
72
|
+
function u(e, t, r, n, i, a, o) {
|
|
73
|
+
return s(t ^ r ^ n, e, t, i, a, o)
|
|
74
|
+
}
|
|
75
|
+
function c(e, t, r, n, i, a, o) {
|
|
76
|
+
return s(r ^ (t | ~n), e, t, i, a, o)
|
|
77
|
+
}
|
|
78
|
+
function d(e, t) {
|
|
79
|
+
e[t >> 5] |= 128 << t % 32,
|
|
80
|
+
e[(t + 64 >>> 9 << 4) + 14] = t;
|
|
81
|
+
var r, n, i, s, d, f = 1732584193, h = -271733879, p = -1732584194, _ = 271733878;
|
|
82
|
+
for (r = 0; r < e.length; r += 16)
|
|
83
|
+
n = f,
|
|
84
|
+
i = h,
|
|
85
|
+
s = p,
|
|
86
|
+
d = _,
|
|
87
|
+
f = o(f, h, p, _, e[r], 7, -680876936),
|
|
88
|
+
_ = o(_, f, h, p, e[r + 1], 12, -389564586),
|
|
89
|
+
p = o(p, _, f, h, e[r + 2], 17, 606105819),
|
|
90
|
+
h = o(h, p, _, f, e[r + 3], 22, -1044525330),
|
|
91
|
+
f = o(f, h, p, _, e[r + 4], 7, -176418897),
|
|
92
|
+
_ = o(_, f, h, p, e[r + 5], 12, 1200080426),
|
|
93
|
+
p = o(p, _, f, h, e[r + 6], 17, -1473231341),
|
|
94
|
+
h = o(h, p, _, f, e[r + 7], 22, -45705983),
|
|
95
|
+
f = o(f, h, p, _, e[r + 8], 7, 1770035416),
|
|
96
|
+
_ = o(_, f, h, p, e[r + 9], 12, -1958414417),
|
|
97
|
+
p = o(p, _, f, h, e[r + 10], 17, -42063),
|
|
98
|
+
h = o(h, p, _, f, e[r + 11], 22, -1990404162),
|
|
99
|
+
f = o(f, h, p, _, e[r + 12], 7, 1804603682),
|
|
100
|
+
_ = o(_, f, h, p, e[r + 13], 12, -40341101),
|
|
101
|
+
p = o(p, _, f, h, e[r + 14], 17, -1502002290),
|
|
102
|
+
h = o(h, p, _, f, e[r + 15], 22, 1236535329),
|
|
103
|
+
f = l(f, h, p, _, e[r + 1], 5, -165796510),
|
|
104
|
+
_ = l(_, f, h, p, e[r + 6], 9, -1069501632),
|
|
105
|
+
p = l(p, _, f, h, e[r + 11], 14, 643717713),
|
|
106
|
+
h = l(h, p, _, f, e[r], 20, -373897302),
|
|
107
|
+
f = l(f, h, p, _, e[r + 5], 5, -701558691),
|
|
108
|
+
_ = l(_, f, h, p, e[r + 10], 9, 38016083),
|
|
109
|
+
p = l(p, _, f, h, e[r + 15], 14, -660478335),
|
|
110
|
+
h = l(h, p, _, f, e[r + 4], 20, -405537848),
|
|
111
|
+
f = l(f, h, p, _, e[r + 9], 5, 568446438),
|
|
112
|
+
_ = l(_, f, h, p, e[r + 14], 9, -1019803690),
|
|
113
|
+
p = l(p, _, f, h, e[r + 3], 14, -187363961),
|
|
114
|
+
h = l(h, p, _, f, e[r + 8], 20, 1163531501),
|
|
115
|
+
f = l(f, h, p, _, e[r + 13], 5, -1444681467),
|
|
116
|
+
_ = l(_, f, h, p, e[r + 2], 9, -51403784),
|
|
117
|
+
p = l(p, _, f, h, e[r + 7], 14, 1735328473),
|
|
118
|
+
h = l(h, p, _, f, e[r + 12], 20, -1926607734),
|
|
119
|
+
f = u(f, h, p, _, e[r + 5], 4, -378558),
|
|
120
|
+
_ = u(_, f, h, p, e[r + 8], 11, -2022574463),
|
|
121
|
+
p = u(p, _, f, h, e[r + 11], 16, 1839030562),
|
|
122
|
+
h = u(h, p, _, f, e[r + 14], 23, -35309556),
|
|
123
|
+
f = u(f, h, p, _, e[r + 1], 4, -1530992060),
|
|
124
|
+
_ = u(_, f, h, p, e[r + 4], 11, 1272893353),
|
|
125
|
+
p = u(p, _, f, h, e[r + 7], 16, -155497632),
|
|
126
|
+
h = u(h, p, _, f, e[r + 10], 23, -1094730640),
|
|
127
|
+
f = u(f, h, p, _, e[r + 13], 4, 681279174),
|
|
128
|
+
_ = u(_, f, h, p, e[r], 11, -358537222),
|
|
129
|
+
p = u(p, _, f, h, e[r + 3], 16, -722521979),
|
|
130
|
+
h = u(h, p, _, f, e[r + 6], 23, 76029189),
|
|
131
|
+
f = u(f, h, p, _, e[r + 9], 4, -640364487),
|
|
132
|
+
_ = u(_, f, h, p, e[r + 12], 11, -421815835),
|
|
133
|
+
p = u(p, _, f, h, e[r + 15], 16, 530742520),
|
|
134
|
+
h = u(h, p, _, f, e[r + 2], 23, -995338651),
|
|
135
|
+
f = c(f, h, p, _, e[r], 6, -198630844),
|
|
136
|
+
_ = c(_, f, h, p, e[r + 7], 10, 1126891415),
|
|
137
|
+
p = c(p, _, f, h, e[r + 14], 15, -1416354905),
|
|
138
|
+
h = c(h, p, _, f, e[r + 5], 21, -57434055),
|
|
139
|
+
f = c(f, h, p, _, e[r + 12], 6, 1700485571),
|
|
140
|
+
_ = c(_, f, h, p, e[r + 3], 10, -1894986606),
|
|
141
|
+
p = c(p, _, f, h, e[r + 10], 15, -1051523),
|
|
142
|
+
h = c(h, p, _, f, e[r + 1], 21, -2054922799),
|
|
143
|
+
f = c(f, h, p, _, e[r + 8], 6, 1873313359),
|
|
144
|
+
_ = c(_, f, h, p, e[r + 15], 10, -30611744),
|
|
145
|
+
p = c(p, _, f, h, e[r + 6], 15, -1560198380),
|
|
146
|
+
h = c(h, p, _, f, e[r + 13], 21, 1309151649),
|
|
147
|
+
f = c(f, h, p, _, e[r + 4], 6, -145523070),
|
|
148
|
+
_ = c(_, f, h, p, e[r + 11], 10, -1120210379),
|
|
149
|
+
p = c(p, _, f, h, e[r + 2], 15, 718787259),
|
|
150
|
+
h = c(h, p, _, f, e[r + 9], 21, -343485551),
|
|
151
|
+
f = a(f, n),
|
|
152
|
+
h = a(h, i),
|
|
153
|
+
p = a(p, s),
|
|
154
|
+
_ = a(_, d);
|
|
155
|
+
return [f, h, p, _]
|
|
156
|
+
}
|
|
157
|
+
function f(e) {
|
|
158
|
+
var t, r = "", n = 32 * e.length;
|
|
159
|
+
for (t = 0; t < n; t += 8)
|
|
160
|
+
r += String.fromCharCode(e[t >> 5] >>> t % 32 & 255);
|
|
161
|
+
return r
|
|
162
|
+
}
|
|
163
|
+
function h(e) {
|
|
164
|
+
var t, r = [];
|
|
165
|
+
for (t = 0,
|
|
166
|
+
r[(e.length >> 2) - 1] = void 0; t < r.length; t += 1)
|
|
167
|
+
r[t] = 0;
|
|
168
|
+
var n = 8 * e.length;
|
|
169
|
+
for (t = 0; t < n; t += 8)
|
|
170
|
+
r[t >> 5] |= (255 & e.charCodeAt(t / 8)) << t % 32;
|
|
171
|
+
return r
|
|
172
|
+
}
|
|
173
|
+
function p(e) {
|
|
174
|
+
var t, r, n = "0123456789abcdef", i = "";
|
|
175
|
+
for (r = 0; r < e.length; r += 1)
|
|
176
|
+
i += n.charAt((t = e.charCodeAt(r)) >>> 4 & 15) + n.charAt(15 & t);
|
|
177
|
+
return i
|
|
178
|
+
}
|
|
179
|
+
function _(e) {
|
|
180
|
+
return unescape(encodeURIComponent(e))
|
|
181
|
+
}
|
|
182
|
+
function v(e) {
|
|
183
|
+
var t;
|
|
184
|
+
return f(d(h(t = _(e)), 8 * t.length))
|
|
185
|
+
}
|
|
186
|
+
function g(e, t) {
|
|
187
|
+
return function (e, t) {
|
|
188
|
+
var r, n, i = h(e), a = [], s = [];
|
|
189
|
+
for (a[15] = s[15] = void 0,
|
|
190
|
+
i.length > 16 && (i = d(i, 8 * e.length)),
|
|
191
|
+
r = 0; r < 16; r += 1)
|
|
192
|
+
a[r] = 909522486 ^ i[r],
|
|
193
|
+
s[r] = 1549556828 ^ i[r];
|
|
194
|
+
return n = d(a.concat(h(t)), 512 + 8 * t.length),
|
|
195
|
+
f(d(s.concat(n), 640))
|
|
196
|
+
}(_(e), _(t))
|
|
197
|
+
}
|
|
198
|
+
function m(e, t, r) {
|
|
199
|
+
return t ? r ? g(t, e) : p(g(t, e)) : r ? v(e) : p(v(e))
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return m;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function load_queries() {
|
|
206
|
+
const files = fs.readdirSync(queries_path);
|
|
207
|
+
for (const filename of files) {
|
|
208
|
+
const ext = path.extname(filename);
|
|
209
|
+
if (ext !== '.graphql') {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const queryName = path.basename(filename, ext);
|
|
213
|
+
const query = fs.readFileSync(path.join(queries_path, filename), 'utf-8');
|
|
214
|
+
queries[queryName] = query;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function generate_payload(query, variables) {
|
|
219
|
+
return {
|
|
220
|
+
query: queries[query],
|
|
221
|
+
variables: variables,
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function request_with_retries(method, attempts = 10) {
|
|
226
|
+
const url = '';
|
|
227
|
+
for (let i = 0; i < attempts; i++) {
|
|
228
|
+
try {
|
|
229
|
+
const response = await method();
|
|
230
|
+
if (response.status === 200) {
|
|
231
|
+
return response;
|
|
232
|
+
}
|
|
233
|
+
logger.warn(`Server returned a status code of ${response.status} while downloading ${url}. Retrying (${i + 1}/${attempts})...`);
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
console.log(err);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
throw new Error(`Failed to download ${url} too many times.`);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
class Client {
|
|
243
|
+
gql_url = "https://poe.com/api/gql_POST";
|
|
244
|
+
gql_recv_url = "https://poe.com/api/receive_POST";
|
|
245
|
+
home_url = "https://poe.com";
|
|
246
|
+
settings_url = "https://poe.com/api/settings";
|
|
247
|
+
|
|
248
|
+
formkey = "";
|
|
249
|
+
next_data = {};
|
|
250
|
+
bots = {};
|
|
251
|
+
active_messages = {};
|
|
252
|
+
message_queues = {};
|
|
253
|
+
bot_names = [];
|
|
254
|
+
ws = null;
|
|
255
|
+
ws_connected = false;
|
|
256
|
+
auto_reconnect = false;
|
|
257
|
+
use_cached_bots = false;
|
|
258
|
+
|
|
259
|
+
constructor(auto_reconnect = false, use_cached_bots = false) {
|
|
260
|
+
this.auto_reconnect = auto_reconnect;
|
|
261
|
+
this.use_cached_bots = use_cached_bots;
|
|
262
|
+
this.abortController = new AbortController();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async init(token, proxy = null) {
|
|
266
|
+
this.proxy = proxy;
|
|
267
|
+
this.session = axios.default.create({
|
|
268
|
+
timeout: 60000,
|
|
269
|
+
httpAgent: new http.Agent({ keepAlive: true }),
|
|
270
|
+
httpsAgent: new https.Agent({ keepAlive: true }),
|
|
271
|
+
signal: this.abortController.signal,
|
|
272
|
+
});
|
|
273
|
+
if (proxy) {
|
|
274
|
+
this.session.defaults.proxy = {
|
|
275
|
+
"http": proxy,
|
|
276
|
+
"https": proxy,
|
|
277
|
+
};
|
|
278
|
+
logger.info(`Proxy enabled: ${proxy}`);
|
|
279
|
+
}
|
|
280
|
+
const cookies = `p-b=${token}; Domain=poe.com`;
|
|
281
|
+
this.headers = {
|
|
282
|
+
"User-Agent": user_agent,
|
|
283
|
+
"Referrer": "https://poe.com/",
|
|
284
|
+
"Origin": "https://poe.com",
|
|
285
|
+
"Cookie": cookies,
|
|
286
|
+
};
|
|
287
|
+
this.session.defaults.headers.common = this.headers;
|
|
288
|
+
this.next_data = await this.get_next_data();
|
|
289
|
+
this.channel = await this.get_channel_data();
|
|
290
|
+
this.bots = await this.get_bots();
|
|
291
|
+
this.bot_names = this.get_bot_names();
|
|
292
|
+
this.ws_domain = `tch${Math.floor(Math.random() * 1e6)}`;
|
|
293
|
+
this.gql_headers = {
|
|
294
|
+
"poe-formkey": this.formkey,
|
|
295
|
+
"poe-tchannel": this.channel["channel"],
|
|
296
|
+
...this.headers,
|
|
297
|
+
};
|
|
298
|
+
await this.connect_ws();
|
|
299
|
+
await this.subscribe();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
async get_next_data() {
|
|
303
|
+
logger.info('Downloading next_data...');
|
|
304
|
+
|
|
305
|
+
const r = await request_with_retries(() => this.session.get(this.home_url));
|
|
306
|
+
const jsonRegex = /<script id="__NEXT_DATA__" type="application\/json">(.+?)<\/script>/;
|
|
307
|
+
const jsonText = jsonRegex.exec(r.data)[1];
|
|
308
|
+
const nextData = JSON.parse(jsonText);
|
|
309
|
+
|
|
310
|
+
this.formkey = extractFormKey(r.data);
|
|
311
|
+
this.viewer = nextData.props.pageProps.payload.viewer;
|
|
312
|
+
|
|
313
|
+
return nextData;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async get_bots() {
|
|
317
|
+
const viewer = this.next_data.props.pageProps.payload.viewer;
|
|
318
|
+
if (!viewer.availableBots) {
|
|
319
|
+
throw new Error('Invalid token.');
|
|
320
|
+
}
|
|
321
|
+
const botList = viewer.availableBots;
|
|
322
|
+
|
|
323
|
+
const bots = {};
|
|
324
|
+
for (const bot of botList.filter(x => x.deletionState == 'not_deleted')) {
|
|
325
|
+
const url = `https://poe.com/_next/data/${this.next_data.buildId}/${bot.displayName}.json`;
|
|
326
|
+
let r;
|
|
327
|
+
|
|
328
|
+
if (this.use_cached_bots && cached_bots[url]) {
|
|
329
|
+
r = cached_bots[url];
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
logger.info(`Downloading ${url}`);
|
|
333
|
+
r = await request_with_retries(() => this.session.get(url));
|
|
334
|
+
cached_bots[url] = r;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const chatData = r.data.pageProps.payload.chatOfBotDisplayName;
|
|
338
|
+
bots[chatData.defaultBotObject.nickname] = chatData;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return bots;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
get_bot_names() {
|
|
345
|
+
const botNames = {};
|
|
346
|
+
for (const botNickname in this.bots) {
|
|
347
|
+
const botObj = this.bots[botNickname].defaultBotObject;
|
|
348
|
+
botNames[botNickname] = botObj.displayName;
|
|
349
|
+
}
|
|
350
|
+
return botNames;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
async get_channel_data(channel = null) {
|
|
354
|
+
logger.info('Downloading channel data...');
|
|
355
|
+
const r = await request_with_retries(() => this.session.get(this.settings_url));
|
|
356
|
+
const data = r.data;
|
|
357
|
+
|
|
358
|
+
return data.tchannelData;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
get_websocket_url(channel = null) {
|
|
362
|
+
if (!channel) {
|
|
363
|
+
channel = this.channel;
|
|
364
|
+
}
|
|
365
|
+
const query = `?min_seq=${channel.minSeq}&channel=${channel.channel}&hash=${channel.channelHash}`;
|
|
366
|
+
return `wss://${this.ws_domain}.tch.${channel.baseHost}/up/${channel.boxName}/updates${query}`;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async send_query(queryName, variables, queryDisplayName) {
|
|
370
|
+
for (let i = 0; i < 20; i++) {
|
|
371
|
+
const payload = generate_payload(queryName, variables);
|
|
372
|
+
if (queryDisplayName) payload['queryName'] = queryDisplayName;
|
|
373
|
+
const scramblePayload = JSON.stringify(payload);
|
|
374
|
+
const _headers = this.gql_headers;
|
|
375
|
+
_headers['poe-tag-id'] = md5()(scramblePayload + this.formkey + "WpuLMiXEKKE98j56k");
|
|
376
|
+
_headers['poe-formkey'] = this.formkey;
|
|
377
|
+
const r = await request_with_retries(() => this.session.post(this.gql_url, payload, { headers: this.gql_headers }));
|
|
378
|
+
if (!r.data.data) {
|
|
379
|
+
logger.warn(`${queryName} returned an error: ${data.errors[0].message} | Retrying (${i + 1}/20)`);
|
|
380
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return r.data;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
throw new Error(`${queryName} failed too many times.`);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
async subscribe() {
|
|
391
|
+
logger.info("Subscribing to mutations")
|
|
392
|
+
await this.send_query("SubscriptionsMutation", {
|
|
393
|
+
"subscriptions": [
|
|
394
|
+
{
|
|
395
|
+
"subscriptionName": "messageAdded",
|
|
396
|
+
"query": queries["MessageAddedSubscription"]
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
"subscriptionName": "viewerStateUpdated",
|
|
400
|
+
"query": queries["ViewerStateUpdatedSubscription"]
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
"subscriptionName": "viewerMessageLimitUpdated",
|
|
404
|
+
"query": queries["ViewerMessageLimitUpdatedSubscription"]
|
|
405
|
+
},
|
|
406
|
+
]
|
|
407
|
+
},
|
|
408
|
+
'subscriptionsMutation');
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
ws_run_thread() {
|
|
412
|
+
this.ws = new WebSocket(this.get_websocket_url(), {
|
|
413
|
+
headers: {
|
|
414
|
+
"User-Agent": user_agent
|
|
415
|
+
},
|
|
416
|
+
rejectUnauthorized: false
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
this.ws.on("open", () => {
|
|
420
|
+
this.on_ws_connect(this.ws);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
this.ws.on('message', (message) => {
|
|
424
|
+
this.on_message(this.ws, message);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
this.ws.on('close', () => {
|
|
428
|
+
this.ws_connected = false;
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
this.ws.on('error', (error) => {
|
|
432
|
+
this.on_ws_error(this.ws, error);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
async connect_ws() {
|
|
437
|
+
this.ws_connected = false;
|
|
438
|
+
this.ws_run_thread();
|
|
439
|
+
while (!this.ws_connected) {
|
|
440
|
+
await new Promise(resolve => setTimeout(() => { resolve() }, 10));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
disconnect_ws() {
|
|
445
|
+
if (this.ws) {
|
|
446
|
+
this.ws.close();
|
|
447
|
+
}
|
|
448
|
+
this.ws_connected = false;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
on_ws_connect(ws) {
|
|
452
|
+
this.ws_connected = true;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
on_ws_error(ws, error) {
|
|
456
|
+
logger.warn(`Websocket returned error: ${error}`);
|
|
457
|
+
this.disconnect_ws();
|
|
458
|
+
|
|
459
|
+
if (this.auto_reconnect) {
|
|
460
|
+
this.connect_ws();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async on_message(ws, msg) {
|
|
465
|
+
try {
|
|
466
|
+
const data = JSON.parse(msg);
|
|
467
|
+
|
|
468
|
+
if (!('messages' in data)) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
for (const message_str of data["messages"]) {
|
|
473
|
+
const message_data = JSON.parse(message_str);
|
|
474
|
+
|
|
475
|
+
if (message_data["message_type"] != "subscriptionUpdate") {
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const message = message_data["payload"]["data"]["messageAdded"]
|
|
480
|
+
|
|
481
|
+
if (!message) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const copiedDict = Object.assign({}, this.active_messages);
|
|
486
|
+
for (const [key, value] of Object.entries(copiedDict)) {
|
|
487
|
+
//add the message to the appropriate queue
|
|
488
|
+
if (value === message["messageId"] && key in this.message_queues) {
|
|
489
|
+
this.message_queues[key].push(message);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
//indicate that the response id is tied to the human message id
|
|
494
|
+
else if (key !== "pending" && value === null && message["state"] !== "complete") {
|
|
495
|
+
this.active_messages[key] = message["messageId"];
|
|
496
|
+
this.message_queues[key].push(message);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
catch (err) {
|
|
502
|
+
console.log('Error occurred in onMessage', err);
|
|
503
|
+
this.disconnect_ws();
|
|
504
|
+
await this.connect_ws();
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
async *send_message(chatbot, message, with_chat_break = false, timeout = 20) {
|
|
509
|
+
//if there is another active message, wait until it has finished sending
|
|
510
|
+
while (Object.values(this.active_messages).includes(null)) {
|
|
511
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
//null indicates that a message is still in progress
|
|
515
|
+
this.active_messages["pending"] = null;
|
|
516
|
+
|
|
517
|
+
console.log(`Sending message to ${chatbot}: ${message}`);
|
|
518
|
+
|
|
519
|
+
const messageData = await this.send_query("AddHumanMessageMutation", {
|
|
520
|
+
"bot": chatbot,
|
|
521
|
+
"query": message,
|
|
522
|
+
"chatId": this.bots[chatbot]["chatId"],
|
|
523
|
+
"source": null,
|
|
524
|
+
"withChatBreak": with_chat_break
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
delete this.active_messages["pending"];
|
|
528
|
+
|
|
529
|
+
if (!messageData["data"]["messageCreateWithStatus"]["messageLimit"]["canSend"]) {
|
|
530
|
+
throw new Error(`Daily limit reached for ${chatbot}.`);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
let humanMessageId;
|
|
534
|
+
try {
|
|
535
|
+
const humanMessage = messageData["data"]["messageCreateWithStatus"];
|
|
536
|
+
humanMessageId = humanMessage["message"]["messageId"];
|
|
537
|
+
} catch (error) {
|
|
538
|
+
throw new Error(`An unknown error occured. Raw response data: ${messageData}`);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
//indicate that the current message is waiting for a response
|
|
542
|
+
this.active_messages[humanMessageId] = null;
|
|
543
|
+
this.message_queues[humanMessageId] = [];
|
|
544
|
+
|
|
545
|
+
let lastText = "";
|
|
546
|
+
let messageId;
|
|
547
|
+
while (true) {
|
|
548
|
+
try {
|
|
549
|
+
this.abortController.signal.throwIfAborted();
|
|
550
|
+
|
|
551
|
+
const message = this.message_queues[humanMessageId].shift();
|
|
552
|
+
if (!message) {
|
|
553
|
+
await new Promise(resolve => setTimeout(() => resolve(), 1000));
|
|
554
|
+
continue;
|
|
555
|
+
//throw new Error("Queue is empty");
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
//only break when the message is marked as complete
|
|
559
|
+
if (message["state"] === "complete") {
|
|
560
|
+
if (lastText && message["messageId"] === messageId) {
|
|
561
|
+
break;
|
|
562
|
+
} else {
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
//update info about response
|
|
568
|
+
message["text_new"] = message["text"].substring(lastText.length);
|
|
569
|
+
lastText = message["text"];
|
|
570
|
+
messageId = message["messageId"];
|
|
571
|
+
|
|
572
|
+
yield message;
|
|
573
|
+
} catch (error) {
|
|
574
|
+
delete this.active_messages[humanMessageId];
|
|
575
|
+
delete this.message_queues[humanMessageId];
|
|
576
|
+
throw new Error("Response timed out.");
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
delete this.active_messages[humanMessageId];
|
|
581
|
+
delete this.message_queues[humanMessageId];
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
async send_chat_break(chatbot) {
|
|
585
|
+
logger.info(`Sending chat break to ${chatbot}`);
|
|
586
|
+
const result = await this.send_query("AddMessageBreakMutation", {
|
|
587
|
+
"chatId": this.bots[chatbot]["chatId"]
|
|
588
|
+
});
|
|
589
|
+
return result["data"]["messageBreakCreate"]["message"];
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
async get_message_history(chatbot, count = 25, cursor = null) {
|
|
593
|
+
logger.info(`Downloading ${count} messages from ${chatbot}`);
|
|
594
|
+
const result = await this.send_query("ChatListPaginationQuery", {
|
|
595
|
+
"count": count,
|
|
596
|
+
"cursor": cursor,
|
|
597
|
+
"id": this.bots[chatbot]["id"]
|
|
598
|
+
});
|
|
599
|
+
return result["data"]["node"]["messagesConnection"]["edges"];
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
async delete_message(message_ids) {
|
|
603
|
+
logger.info(`Deleting messages: ${message_ids}`);
|
|
604
|
+
if (!Array.isArray(message_ids)) {
|
|
605
|
+
message_ids = [parseInt(message_ids)];
|
|
606
|
+
}
|
|
607
|
+
const result = await this.send_query("DeleteMessageMutation", {
|
|
608
|
+
"messageIds": message_ids
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
async purge_conversation(chatbot, count = -1) {
|
|
613
|
+
logger.info(`Purging messages from ${chatbot}`);
|
|
614
|
+
let last_messages = (await this.get_message_history(chatbot, 50)).reverse();
|
|
615
|
+
while (last_messages.length) {
|
|
616
|
+
const message_ids = [];
|
|
617
|
+
for (const message of last_messages) {
|
|
618
|
+
if (count === 0) {
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
count--;
|
|
622
|
+
message_ids.push(message["node"]["messageId"]);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
await this.delete_message(message_ids);
|
|
626
|
+
|
|
627
|
+
if (count === 0) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
last_messages = (await this.get_message_history(chatbot, 50)).reverse();
|
|
631
|
+
}
|
|
632
|
+
logger.info("No more messages left to delete.");
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
load_queries();
|
|
637
|
+
|
|
638
|
+
module.exports = { Client };
|
package/poe-test.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const poe = require('./poe-client');
|
|
2
|
+
|
|
3
|
+
async function test() {
|
|
4
|
+
const client = new poe.Client();
|
|
5
|
+
await client.init('pb-cookie');
|
|
6
|
+
|
|
7
|
+
const bots = client.get_bot_names();
|
|
8
|
+
console.log(bots);
|
|
9
|
+
|
|
10
|
+
await client.purge_conversation('a2', -1);
|
|
11
|
+
|
|
12
|
+
let reply;
|
|
13
|
+
for await (const mes of client.send_message('a2', 'Hello')) {
|
|
14
|
+
reply = mes.text;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
console.log(reply);
|
|
18
|
+
client.disconnect_ws();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
test();
|