Update bot.js
Browse files
bot.js
CHANGED
|
@@ -175,7 +175,8 @@ let botActions = {
|
|
| 175 |
openCiftciAndSellAllManual: null,
|
| 176 |
goToIslandManual: null,
|
| 177 |
sendSkyblockManual: null,
|
| 178 |
-
antiBotMove: null
|
|
|
|
| 179 |
};
|
| 180 |
|
| 181 |
function formatDurationMs(ms) {
|
|
@@ -1060,6 +1061,89 @@ async function createBot() {
|
|
| 1060 |
}
|
| 1061 |
}
|
| 1062 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1063 |
async function antiBotMove() {
|
| 1064 |
if (!bot || !botIsReady) return;
|
| 1065 |
try {
|
|
@@ -1611,7 +1695,8 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1611 |
botActions.openCiftciAndSellAllManual = openCiftciAndSellAllManual;
|
| 1612 |
botActions.goToIslandManual = goToIsland;
|
| 1613 |
botActions.sendSkyblockManual = sendSkyblockCommand;
|
| 1614 |
-
botActions.antiBotMove = antiBotMove
|
|
|
|
| 1615 |
|
| 1616 |
startKaziciPeriodic();
|
| 1617 |
startCiftciPeriodic();
|
|
@@ -1800,6 +1885,8 @@ function activateEntityAtNoLook(entity, position) {
|
|
| 1800 |
botActions.openCiftciAndSellAllManual = null;
|
| 1801 |
botActions.goToIslandManual = null;
|
| 1802 |
botActions.sendSkyblockManual = null;
|
|
|
|
|
|
|
| 1803 |
|
| 1804 |
safeDestroyAllConnections();
|
| 1805 |
|
|
@@ -2168,6 +2255,30 @@ app.get("/bot/antibotmove", (req, res) => {
|
|
| 2168 |
}
|
| 2169 |
});
|
| 2170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2171 |
app.get("/", (req, res) => res.send("Bot Aktif"));
|
| 2172 |
|
| 2173 |
app.get("/messages", (req, res) => {
|
|
@@ -2403,4 +2514,4 @@ process.stderr.write = function (chunk, encoding, callback) {
|
|
| 2403 |
return true;
|
| 2404 |
}
|
| 2405 |
return originalStderrWrite.apply(process.stderr, arguments);
|
| 2406 |
-
};
|
|
|
|
| 175 |
openCiftciAndSellAllManual: null,
|
| 176 |
goToIslandManual: null,
|
| 177 |
sendSkyblockManual: null,
|
| 178 |
+
antiBotMove: null,
|
| 179 |
+
sendMoneyToNick: null
|
| 180 |
};
|
| 181 |
|
| 182 |
function formatDurationMs(ms) {
|
|
|
|
| 1061 |
}
|
| 1062 |
}
|
| 1063 |
|
| 1064 |
+
// --- SENDMONEY: /money oku, bakiyeden 1000 eksiğini ilgili nick'e /pay ile gönder ---
|
| 1065 |
+
const MONEY_BALANCE_REGEX = /bakiyen:\s*([\d.,]+)\s*TL/i;
|
| 1066 |
+
const MONEY_RESPONSE_TIMEOUT_MS = 8000;
|
| 1067 |
+
|
| 1068 |
+
function parseBalanceToAdjustedAmount(rawBalanceStr) {
|
| 1069 |
+
// "444,626.89" -> virgülleri kaldır -> "444626.89" -> noktadan öncesini al -> "444626"
|
| 1070 |
+
const noCommas = rawBalanceStr.replace(/,/g, "");
|
| 1071 |
+
const beforeDot = noCommas.split(".")[0];
|
| 1072 |
+
const intValue = parseInt(beforeDot, 10);
|
| 1073 |
+
if (isNaN(intValue)) return null;
|
| 1074 |
+
return intValue - 1000;
|
| 1075 |
+
}
|
| 1076 |
+
|
| 1077 |
+
async function sendMoneyToNick(nick) {
|
| 1078 |
+
if (!bot || !botIsReady) {
|
| 1079 |
+
return { success: false, message: "Bot hazır değil." };
|
| 1080 |
+
}
|
| 1081 |
+
if (!nick || typeof nick !== "string" || nick.trim().length === 0) {
|
| 1082 |
+
return { success: false, message: "nick parametresi zorunlu." };
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
return new Promise((resolve) => {
|
| 1086 |
+
let finished = false;
|
| 1087 |
+
let timeoutHandle = null;
|
| 1088 |
+
|
| 1089 |
+
const cleanup = () => {
|
| 1090 |
+
if (finished) return;
|
| 1091 |
+
finished = true;
|
| 1092 |
+
clearTimeout(timeoutHandle);
|
| 1093 |
+
bot.removeListener('message', onMessage);
|
| 1094 |
+
};
|
| 1095 |
+
|
| 1096 |
+
const onMessage = (jsonMsg) => {
|
| 1097 |
+
try {
|
| 1098 |
+
const chatMessage = bot.chat.ChatMessage ? new bot.chat.ChatMessage(jsonMsg) : jsonMsg;
|
| 1099 |
+
const text = typeof chatMessage.toString === 'function' ? chatMessage.toString() : String(jsonMsg);
|
| 1100 |
+
const plain = stripColorCodes(text);
|
| 1101 |
+
|
| 1102 |
+
const match = plain.match(MONEY_BALANCE_REGEX);
|
| 1103 |
+
if (match) {
|
| 1104 |
+
const adjusted = parseBalanceToAdjustedAmount(match[1]);
|
| 1105 |
+
cleanup();
|
| 1106 |
+
|
| 1107 |
+
if (adjusted == null) {
|
| 1108 |
+
logger.error(`[Sendmoney] Bakiye ayrıştırılamadı: "${plain}"`);
|
| 1109 |
+
resolve({ success: false, message: "Bakiye mesajı ayrıştırılamadı." });
|
| 1110 |
+
return;
|
| 1111 |
+
}
|
| 1112 |
+
|
| 1113 |
+
try {
|
| 1114 |
+
const payCommand = `/pay ${nick} ${adjusted}`;
|
| 1115 |
+
bot.chat(payCommand);
|
| 1116 |
+
logger.info(`[Sendmoney] Bakiye okundu: ${match[1]} -> Gönderilecek: ${adjusted}. Komut: ${payCommand}`);
|
| 1117 |
+
resolve({ success: true, message: "Para gönderildi.", balance_raw: match[1], amount_sent: adjusted, nick });
|
| 1118 |
+
} catch (err) {
|
| 1119 |
+
logger.error(`[Sendmoney] /pay komutu gönderilemedi: ${err && err.message ? err.message : err}`);
|
| 1120 |
+
resolve({ success: false, message: "/pay komutu gönderilirken hata oluştu." });
|
| 1121 |
+
}
|
| 1122 |
+
}
|
| 1123 |
+
} catch (err) {
|
| 1124 |
+
logger.error(`[Sendmoney] Mesaj işlenirken hata: ${err && err.message ? err.message : err}`);
|
| 1125 |
+
}
|
| 1126 |
+
};
|
| 1127 |
+
|
| 1128 |
+
bot.on('message', onMessage);
|
| 1129 |
+
|
| 1130 |
+
timeoutHandle = setTimeout(() => {
|
| 1131 |
+
cleanup();
|
| 1132 |
+
logger.warn(`[Sendmoney] ${formatDurationMs(MONEY_RESPONSE_TIMEOUT_MS)} içinde bakiye mesajı gelmedi.`);
|
| 1133 |
+
resolve({ success: false, message: "Zaman aşımı: bakiye mesajı alınamadı." });
|
| 1134 |
+
}, MONEY_RESPONSE_TIMEOUT_MS);
|
| 1135 |
+
|
| 1136 |
+
try {
|
| 1137 |
+
bot.chat("/money");
|
| 1138 |
+
logger.info(`[Sendmoney] /money komutu gönderildi, bakiye mesajı bekleniyor...`);
|
| 1139 |
+
} catch (err) {
|
| 1140 |
+
cleanup();
|
| 1141 |
+
logger.error(`[Sendmoney] /money komutu gönderilemedi: ${err && err.message ? err.message : err}`);
|
| 1142 |
+
resolve({ success: false, message: "/money komutu gönderilirken hata oluştu." });
|
| 1143 |
+
}
|
| 1144 |
+
});
|
| 1145 |
+
}
|
| 1146 |
+
|
| 1147 |
async function antiBotMove() {
|
| 1148 |
if (!bot || !botIsReady) return;
|
| 1149 |
try {
|
|
|
|
| 1695 |
botActions.openCiftciAndSellAllManual = openCiftciAndSellAllManual;
|
| 1696 |
botActions.goToIslandManual = goToIsland;
|
| 1697 |
botActions.sendSkyblockManual = sendSkyblockCommand;
|
| 1698 |
+
botActions.antiBotMove = antiBotMove;
|
| 1699 |
+
botActions.sendMoneyToNick = sendMoneyToNick;
|
| 1700 |
|
| 1701 |
startKaziciPeriodic();
|
| 1702 |
startCiftciPeriodic();
|
|
|
|
| 1885 |
botActions.openCiftciAndSellAllManual = null;
|
| 1886 |
botActions.goToIslandManual = null;
|
| 1887 |
botActions.sendSkyblockManual = null;
|
| 1888 |
+
botActions.antiBotMove = null;
|
| 1889 |
+
botActions.sendMoneyToNick = null;
|
| 1890 |
|
| 1891 |
safeDestroyAllConnections();
|
| 1892 |
|
|
|
|
| 2255 |
}
|
| 2256 |
});
|
| 2257 |
|
| 2258 |
+
app.get("/bot/sendmoney", (req, res) => {
|
| 2259 |
+
if (!bot || !botIsReady || !botActions.sendMoneyToNick) {
|
| 2260 |
+
return res.status(503).send({ success: false, message: "Bot hazır değil." });
|
| 2261 |
+
}
|
| 2262 |
+
|
| 2263 |
+
const nick = req.query.nick;
|
| 2264 |
+
if (!nick || typeof nick !== "string" || nick.trim().length === 0) {
|
| 2265 |
+
return res.status(400).send({ success: false, message: "nick query parametresi zorunlu." });
|
| 2266 |
+
}
|
| 2267 |
+
|
| 2268 |
+
botActions.sendMoneyToNick(nick)
|
| 2269 |
+
.then((result) => {
|
| 2270 |
+
if (result.success) {
|
| 2271 |
+
res.send(result);
|
| 2272 |
+
} else {
|
| 2273 |
+
res.status(500).send(result);
|
| 2274 |
+
}
|
| 2275 |
+
})
|
| 2276 |
+
.catch((err) => {
|
| 2277 |
+
logger.error(`[/bot/sendmoney Hatası] ${err && err.stack ? err.stack : err}`);
|
| 2278 |
+
res.status(500).send({ success: false, message: "Beklenmeyen bir hata oluştu." });
|
| 2279 |
+
});
|
| 2280 |
+
});
|
| 2281 |
+
|
| 2282 |
app.get("/", (req, res) => res.send("Bot Aktif"));
|
| 2283 |
|
| 2284 |
app.get("/messages", (req, res) => {
|
|
|
|
| 2514 |
return true;
|
| 2515 |
}
|
| 2516 |
return originalStderrWrite.apply(process.stderr, arguments);
|
| 2517 |
+
};
|