Spaces:
Paused
Paused
Update bot.js
Browse files
bot.js
CHANGED
|
@@ -30,7 +30,7 @@ function createBot() {
|
|
| 30 |
|
| 31 |
function safeDisplayNameToString(e) {
|
| 32 |
try {
|
| 33 |
-
if (e.displayName && typeof e.displayName.toString === "function") {
|
| 34 |
return e.displayName.toString();
|
| 35 |
}
|
| 36 |
} catch (err) {
|
|
@@ -58,7 +58,6 @@ function createBot() {
|
|
| 58 |
function isBesleyiciName(name) {
|
| 59 |
if (!name) return false;
|
| 60 |
const norm = normalizeForMatch(name);
|
| 61 |
-
// Hem düz "besleyici" hem özel unicode varyasyonlarını yakalamak için
|
| 62 |
return norm.includes("besleyici") || norm.includes("ʙᴇsʟᴇʏiᴄi");
|
| 63 |
}
|
| 64 |
|
|
@@ -81,7 +80,120 @@ function createBot() {
|
|
| 81 |
}
|
| 82 |
}
|
| 83 |
|
| 84 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
function dumpEntityFull(entity) {
|
| 86 |
try {
|
| 87 |
if (!entity) {
|
|
@@ -146,18 +258,50 @@ function createBot() {
|
|
| 146 |
console.log("Minimal snapshot JSON (tek satır):");
|
| 147 |
console.log(JSON.stringify(minimal));
|
| 148 |
|
| 149 |
-
//
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
}
|
| 162 |
} catch (err) {
|
| 163 |
console.error("logDetailedEntitiesOnce hata:", err);
|
|
@@ -189,7 +333,7 @@ function createBot() {
|
|
| 189 |
setTimeout(async () => {
|
| 190 |
bot.chat(`/home`);
|
| 191 |
logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
|
| 192 |
-
// /home sonrası tek seferlik detaylı snapshot +
|
| 193 |
logDetailedEntitiesOnce();
|
| 194 |
}, 10000);
|
| 195 |
|
|
|
|
| 30 |
|
| 31 |
function safeDisplayNameToString(e) {
|
| 32 |
try {
|
| 33 |
+
if (e && e.displayName && typeof e.displayName.toString === "function") {
|
| 34 |
return e.displayName.toString();
|
| 35 |
}
|
| 36 |
} catch (err) {
|
|
|
|
| 58 |
function isBesleyiciName(name) {
|
| 59 |
if (!name) return false;
|
| 60 |
const norm = normalizeForMatch(name);
|
|
|
|
| 61 |
return norm.includes("besleyici") || norm.includes("ʙᴇsʟᴇʏiᴄi");
|
| 62 |
}
|
| 63 |
|
|
|
|
| 80 |
}
|
| 81 |
}
|
| 82 |
|
| 83 |
+
// -------------------------
|
| 84 |
+
// Güvenli derin arama (döngüsel referansları önler)
|
| 85 |
+
// -------------------------
|
| 86 |
+
// targetLower: normalize edilmiş arama hedefi (ör. "besleyici")
|
| 87 |
+
function deepSearchForString(root, targetLower) {
|
| 88 |
+
const results = [];
|
| 89 |
+
const visited = new WeakSet();
|
| 90 |
+
|
| 91 |
+
function isPrimitiveString(v) {
|
| 92 |
+
return typeof v === "string" && v.length > 0;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
function checkAndPush(value, path) {
|
| 96 |
+
try {
|
| 97 |
+
if (isPrimitiveString(value)) {
|
| 98 |
+
const norm = normalizeForMatch(value);
|
| 99 |
+
if (norm.includes(targetLower)) {
|
| 100 |
+
results.push({ path, value });
|
| 101 |
+
return true;
|
| 102 |
+
}
|
| 103 |
+
} else if (value && typeof value.toString === "function" && !(value instanceof Buffer)) {
|
| 104 |
+
// Bazı ChatMessage objeleri veya özel objeler toString ile anlamlı içerik verebilir
|
| 105 |
+
try {
|
| 106 |
+
const s = value.toString();
|
| 107 |
+
if (typeof s === "string") {
|
| 108 |
+
const norm = normalizeForMatch(s);
|
| 109 |
+
if (norm.includes(targetLower)) {
|
| 110 |
+
results.push({ path, value: s });
|
| 111 |
+
return true;
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
} catch (e) {
|
| 115 |
+
// ignore
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
} catch (e) {}
|
| 119 |
+
return false;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
function recurse(obj, path) {
|
| 123 |
+
if (!obj || typeof obj !== "object") {
|
| 124 |
+
checkAndPush(obj, path);
|
| 125 |
+
return;
|
| 126 |
+
}
|
| 127 |
+
if (visited.has(obj)) return;
|
| 128 |
+
visited.add(obj);
|
| 129 |
+
|
| 130 |
+
// If object has a displayName with toString, check it first (common case)
|
| 131 |
+
if (obj.displayName && typeof obj.displayName.toString === "function") {
|
| 132 |
+
try {
|
| 133 |
+
const s = obj.displayName.toString();
|
| 134 |
+
if (isPrimitiveString(s)) {
|
| 135 |
+
const norm = normalizeForMatch(s);
|
| 136 |
+
if (norm.includes(targetLower)) {
|
| 137 |
+
results.push({ path: path + ".displayName", value: s });
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
} catch (e) {}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
// Iterate arrays
|
| 144 |
+
if (Array.isArray(obj)) {
|
| 145 |
+
for (let i = 0; i < obj.length; i++) {
|
| 146 |
+
try {
|
| 147 |
+
recurse(obj[i], `${path}[${i}]`);
|
| 148 |
+
} catch (e) {}
|
| 149 |
+
}
|
| 150 |
+
return;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
// Iterate Maps
|
| 154 |
+
if (obj instanceof Map) {
|
| 155 |
+
let idx = 0;
|
| 156 |
+
for (const [k, v] of obj.entries()) {
|
| 157 |
+
recurse(k, `${path}.MapKey(${idx})`);
|
| 158 |
+
recurse(v, `${path}.MapValue(${idx})`);
|
| 159 |
+
idx++;
|
| 160 |
+
}
|
| 161 |
+
return;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
// Plain object: iterate keys
|
| 165 |
+
for (const key of Object.keys(obj)) {
|
| 166 |
+
// skip prototype weirdness
|
| 167 |
+
try {
|
| 168 |
+
const val = obj[key];
|
| 169 |
+
// Quick check for primitive string
|
| 170 |
+
if (isPrimitiveString(val)) {
|
| 171 |
+
const norm = normalizeForMatch(val);
|
| 172 |
+
if (norm.includes(targetLower)) {
|
| 173 |
+
results.push({ path: `${path}.${key}`, value: val });
|
| 174 |
+
// continue searching to collect all matches
|
| 175 |
+
}
|
| 176 |
+
} else if (val && typeof val === "object") {
|
| 177 |
+
recurse(val, `${path}.${key}`);
|
| 178 |
+
} else {
|
| 179 |
+
// non-object primitive: check via checkAndPush
|
| 180 |
+
checkAndPush(val, `${path}.${key}`);
|
| 181 |
+
}
|
| 182 |
+
} catch (e) {
|
| 183 |
+
// ignore property access errors
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
try {
|
| 189 |
+
recurse(root, "root");
|
| 190 |
+
} catch (e) {}
|
| 191 |
+
return results;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
// -------------------------
|
| 195 |
+
// Dump yardımcıları
|
| 196 |
+
// -------------------------
|
| 197 |
function dumpEntityFull(entity) {
|
| 198 |
try {
|
| 199 |
if (!entity) {
|
|
|
|
| 258 |
console.log("Minimal snapshot JSON (tek satır):");
|
| 259 |
console.log(JSON.stringify(minimal));
|
| 260 |
|
| 261 |
+
// -------------------------
|
| 262 |
+
// Her entity içinde derin arama yap: "besleyici"
|
| 263 |
+
// -------------------------
|
| 264 |
+
const target = "besleyici";
|
| 265 |
+
const targetNorm = normalizeForMatch(target);
|
| 266 |
|
| 267 |
+
let anyFound = false;
|
| 268 |
+
for (const e of arr) {
|
| 269 |
+
try {
|
| 270 |
+
// Öncelikle displayName/name alanlarını hızlı kontrol et
|
| 271 |
+
const name = getEntityReadableName(e);
|
| 272 |
+
if (isBesleyiciName(name)) {
|
| 273 |
+
logger.info(`[${config["bot-account"]["username"]}] Besleyici bulundu (name/displayName): ${name} (id:${e.id}) — aktive ediliyor.`);
|
| 274 |
+
safeActivateEntity(e);
|
| 275 |
+
anyFound = true;
|
| 276 |
+
break;
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
// Derin arama: entity objesinin tüm alanlarında "besleyici" arar
|
| 280 |
+
const matches = deepSearchForString(e, targetNorm);
|
| 281 |
+
if (matches && matches.length > 0) {
|
| 282 |
+
anyFound = true;
|
| 283 |
+
console.log(`*** Derin arama ile eşleşme bulundu: entity id ${e.id} name:${getEntityReadableName(e)}`);
|
| 284 |
+
matches.forEach((m, idx) => {
|
| 285 |
+
try {
|
| 286 |
+
// value'yi güvenli şekilde yazdır
|
| 287 |
+
let valStr = typeof m.value === "string" ? m.value : util.inspect(m.value, { depth: 1, colors: false });
|
| 288 |
+
console.log(` Match ${idx + 1}: path=${m.path} value=${valStr}`);
|
| 289 |
+
} catch (inner) {}
|
| 290 |
+
});
|
| 291 |
+
// Dump tam entity (isteğe bağlı, çok detaylı)
|
| 292 |
+
dumpEntityFull(e);
|
| 293 |
+
// Aktive et
|
| 294 |
+
logger.info(`[${config["bot-account"]["username"]}] Derin arama ile bulunan entity aktive ediliyor (id:${e.id}).`);
|
| 295 |
+
safeActivateEntity(e);
|
| 296 |
+
break;
|
| 297 |
+
}
|
| 298 |
+
} catch (inner) {
|
| 299 |
+
console.error("Entity derin arama sırasında hata:", inner);
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
if (!anyFound) {
|
| 304 |
+
logger.info(`[${config["bot-account"]["username"]}] /home sonrası tarama: besleyici minyon bulunamadı (derin arama yapıldı).`);
|
| 305 |
}
|
| 306 |
} catch (err) {
|
| 307 |
console.error("logDetailedEntitiesOnce hata:", err);
|
|
|
|
| 333 |
setTimeout(async () => {
|
| 334 |
bot.chat(`/home`);
|
| 335 |
logger.info(`[${config["bot-account"]["username"]}] Home konumuna ışınlanma komutu kullanıldı.`);
|
| 336 |
+
// /home sonrası tek seferlik detaylı snapshot + derin arama
|
| 337 |
logDetailedEntitiesOnce();
|
| 338 |
}, 10000);
|
| 339 |
|