beast-agent 0.26.2 → 0.26.3
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/package.json +1 -1
- package/src/agent/discord.js +70 -26
package/package.json
CHANGED
package/src/agent/discord.js
CHANGED
|
@@ -23,9 +23,11 @@ const INTENTS = 1 | 512 | 4096 | 32768;
|
|
|
23
23
|
/* AĞ ARA YAZILIMI (antivirüs SSL taraması / proxy / ağ filtresi) Discord
|
|
24
24
|
trafiğine araya girip SELF-SIGNED sertifika sunarsa Node varsayılan olarak
|
|
25
25
|
bağlantıyı reddeder ("self signed certificate") ve bot hiç bağlanamaz.
|
|
26
|
-
Çözüm
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
Çözüm iki katman:
|
|
27
|
+
1) REST istekleri ÖNCE Electron/Chromium ağ yığınından (net.fetch) geçer —
|
|
28
|
+
sistem CA + sistem proxy otomatik tanınır (tarayıcının çalıştığı yol).
|
|
29
|
+
2) Zorlanırsa Node https'e düşülür; self-signed tespit edilirse bu köprü
|
|
30
|
+
için TLS doğrulaması esnetilir — YALNIZ Discord bağlantıları etkilenir. */
|
|
29
31
|
let tlsRelaxed = false;
|
|
30
32
|
const CERT_ERR_RE = /self[ -]?signed|unable to verify the first certificate|depth zero|err_tls|certificate has expired|cert_has_expired|unable_to_get_issuer|self signed certificate/i;
|
|
31
33
|
|
|
@@ -33,6 +35,19 @@ function isCertError(e) {
|
|
|
33
35
|
return CERT_ERR_RE.test(String((e && (e.message || e.code)) || e || ''));
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
/* Electron main process'te Chromium ağ yığını (sistem CA + proxy); düz Node
|
|
39
|
+
(testler) için require('electron') path string döndürür → net tanımsız kalır */
|
|
40
|
+
let _electronNet = null;
|
|
41
|
+
try {
|
|
42
|
+
const el = require('electron');
|
|
43
|
+
if (el && el.net && typeof el.net.fetch === 'function') _electronNet = el.net;
|
|
44
|
+
} catch {}
|
|
45
|
+
|
|
46
|
+
function bodySnippet(data) {
|
|
47
|
+
const s = String(data || '').replace(/\s+/g, ' ').trim();
|
|
48
|
+
return s ? ` — gövde: ${s.slice(0, 140)}` : '';
|
|
49
|
+
}
|
|
50
|
+
|
|
36
51
|
class DiscordBridge {
|
|
37
52
|
constructor({ token, emit, onIncoming }) {
|
|
38
53
|
this.token = String(token || '').trim();
|
|
@@ -54,18 +69,57 @@ class DiscordBridge {
|
|
|
54
69
|
this.emit({ type: 'status', status, user: user || null });
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
/* REST çağrısı — JSON (token: "Bot <token>").
|
|
58
|
-
|
|
72
|
+
/* REST çağrısı — JSON (token: "Bot <token>").
|
|
73
|
+
Yol 1: Chromium (net.fetch — sistem CA/proxy). Yol 2: Node https (+esnek TLS). */
|
|
59
74
|
api(method, path, body, attempt = 0) {
|
|
75
|
+
return this._api(method, path, body).catch((e) => {
|
|
76
|
+
if (isCertError(e) && !tlsRelaxed) {
|
|
77
|
+
tlsRelaxed = true;
|
|
78
|
+
this.emit({
|
|
79
|
+
type: 'warn',
|
|
80
|
+
text: 'ağ ara yazılımı (antivirüs/proxy) self-signed sertifikası tespit edildi — Discord bağlantısı esnek TLS ile devam ediyor',
|
|
81
|
+
});
|
|
82
|
+
if (attempt < 1) return this.api(method, path, body, attempt + 1);
|
|
83
|
+
}
|
|
84
|
+
throw e;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async _api(method, path, body) {
|
|
89
|
+
const payload = body ? JSON.stringify(body) : null;
|
|
90
|
+
const headers = { 'Content-Type': 'application/json', Authorization: 'Bot ' + this.token };
|
|
91
|
+
const url = API_BASE + path;
|
|
92
|
+
|
|
93
|
+
/* YOL 1 — Chromium ağ yığını (varsa): sistem sertifikaları + sistem proxy */
|
|
94
|
+
if (_electronNet) {
|
|
95
|
+
try {
|
|
96
|
+
const res = await _electronNet.fetch(url, {
|
|
97
|
+
method,
|
|
98
|
+
headers,
|
|
99
|
+
...(payload ? { body: payload } : {}),
|
|
100
|
+
});
|
|
101
|
+
const data = await res.text();
|
|
102
|
+
let j = null;
|
|
103
|
+
try { j = data ? JSON.parse(data) : null; } catch {}
|
|
104
|
+
if (res.ok) return j;
|
|
105
|
+
throw new Error(
|
|
106
|
+
`discord ${path}: HTTP ${res.status}${j && j.message ? ' ' + j.message : ''}${bodySnippet(data)}`
|
|
107
|
+
);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
/* kendi formatladığımız API hatasıysa yukarı taşı; transport hatasıysa
|
|
110
|
+
Node https yoluna düş (orada esnek TLS şansı var) */
|
|
111
|
+
if (/^discord /.test(String((e && e.message) || ''))) throw e;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* YOL 2 — Node https (+ gerektiğinde esnek TLS) */
|
|
60
116
|
return new Promise((resolve, reject) => {
|
|
61
|
-
const payload = body ? JSON.stringify(body) : null;
|
|
62
117
|
const req = https.request(
|
|
63
|
-
|
|
118
|
+
url,
|
|
64
119
|
{
|
|
65
120
|
method,
|
|
66
121
|
headers: {
|
|
67
|
-
|
|
68
|
-
Authorization: 'Bot ' + this.token,
|
|
122
|
+
...headers,
|
|
69
123
|
...(payload ? { 'Content-Length': Buffer.byteLength(payload) } : {}),
|
|
70
124
|
},
|
|
71
125
|
timeout: 15000,
|
|
@@ -76,13 +130,14 @@ class DiscordBridge {
|
|
|
76
130
|
res.setEncoding('utf8');
|
|
77
131
|
res.on('data', (c) => (data += c));
|
|
78
132
|
res.on('end', () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
reject(new Error(`discord ${path}: bozuk yanıt`));
|
|
133
|
+
const ctype = String(res.headers['content-type'] || '');
|
|
134
|
+
let j = null;
|
|
135
|
+
try { j = data ? JSON.parse(data) : null; } catch {}
|
|
136
|
+
if (res.statusCode >= 200 && res.statusCode < 300 && j !== null) return resolve(j);
|
|
137
|
+
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
138
|
+
return reject(new Error(`discord ${path}: bozuk yanıt (HTTP ${res.statusCode}${ctype ? ', ' + ctype : ''})${bodySnippet(data)}`));
|
|
85
139
|
}
|
|
140
|
+
reject(new Error(`discord ${path}: HTTP ${res.statusCode} ${(j && j.message) || ''}`.trim() + bodySnippet(data)));
|
|
86
141
|
});
|
|
87
142
|
}
|
|
88
143
|
);
|
|
@@ -90,17 +145,6 @@ class DiscordBridge {
|
|
|
90
145
|
req.on('error', reject);
|
|
91
146
|
if (payload) req.write(payload);
|
|
92
147
|
req.end();
|
|
93
|
-
}).catch((e) => {
|
|
94
|
-
/* ara yazılım sertifikası tespit: esnet ve aynı isteği bir kez daha dene */
|
|
95
|
-
if (isCertError(e) && !tlsRelaxed) {
|
|
96
|
-
tlsRelaxed = true;
|
|
97
|
-
this.emit({
|
|
98
|
-
type: 'warn',
|
|
99
|
-
text: 'ağ ara yazılımı (antivirüs/proxy) self-signed sertifikası tespit edildi — Discord bağlantısı esnek TLS ile devam ediyor',
|
|
100
|
-
});
|
|
101
|
-
if (attempt < 1) return this.api(method, path, body, attempt + 1);
|
|
102
|
-
}
|
|
103
|
-
throw e;
|
|
104
148
|
});
|
|
105
149
|
}
|
|
106
150
|
|