ddbot.js-0374 3.0.0 → 3.1.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/package.json +1 -1
- package/src/bot/bot.js +11 -9
package/package.json
CHANGED
package/src/bot/bot.js
CHANGED
|
@@ -20,7 +20,7 @@ class BotManager extends EventEmitter {
|
|
|
20
20
|
*/
|
|
21
21
|
constructor(teeWorlds = null) {
|
|
22
22
|
super();
|
|
23
|
-
if (typeof teeWorlds ===
|
|
23
|
+
if (typeof teeWorlds === "object") {
|
|
24
24
|
this.TW = teeWorlds;
|
|
25
25
|
} else {
|
|
26
26
|
this.TW = teeworlds;
|
|
@@ -92,7 +92,8 @@ class BotManager extends EventEmitter {
|
|
|
92
92
|
let TW = this.TW; // teeworlds
|
|
93
93
|
// то самое место откуда создаеться клинт бота
|
|
94
94
|
const client = new TW.Client(serverIp, serverPort, botName, { // изпользуем имя без уникального суффикса чтобы было одно имя.
|
|
95
|
-
identity: identity // то самое индентити для скина и тд
|
|
95
|
+
identity: identity, // то самое индентити для скина и тд
|
|
96
|
+
...parameter.parameter
|
|
96
97
|
});
|
|
97
98
|
|
|
98
99
|
// Настраиваем события для бота
|
|
@@ -304,10 +305,12 @@ class BotManager extends EventEmitter {
|
|
|
304
305
|
let chatinterval = null; // интервал для чата
|
|
305
306
|
|
|
306
307
|
this.on(`${botName}:disconnected`, (reason) => {
|
|
308
|
+
logDebug('internal "disconnected" event received for botName:', botName);
|
|
307
309
|
clearInterval(chatinterval);
|
|
308
310
|
});
|
|
309
311
|
|
|
310
312
|
this.on(`${botName}:disconnect`, (reason) => {
|
|
313
|
+
logDebug('internal "disconnect" event received for botName:', botName);
|
|
311
314
|
clearInterval(chatinterval);
|
|
312
315
|
});
|
|
313
316
|
|
|
@@ -316,6 +319,7 @@ class BotManager extends EventEmitter {
|
|
|
316
319
|
if (!botInfo) {
|
|
317
320
|
return; // бот не найден фак
|
|
318
321
|
} else {
|
|
322
|
+
client.movement.FlagScoreboard(true); // для пинга
|
|
319
323
|
botInfo.isConnected = true; // обновляем статус
|
|
320
324
|
}
|
|
321
325
|
this.emit(`${botName}:connect`); // емитим событие коннекта1
|
|
@@ -391,9 +395,7 @@ class BotManager extends EventEmitter {
|
|
|
391
395
|
for (let client_id = 0; client_id < 64; client_id++) {
|
|
392
396
|
const clientInfo = client.SnapshotUnpacker.getObjClientInfo(client_id);
|
|
393
397
|
const playerInfo = client.SnapshotUnpacker.getObjPlayerInfo(client_id);
|
|
394
|
-
const
|
|
395
|
-
? client.SnapshotUnpacker.getObjExDDNetCharacter(client_id)
|
|
396
|
-
: null;
|
|
398
|
+
const character = client.SnapshotUnpacker.getObjCharacter(client_id);
|
|
397
399
|
|
|
398
400
|
if (clientInfo && clientInfo.name && playerInfo && playerInfo.m_Team !== -1) {
|
|
399
401
|
playerMap.set(client_id, {
|
|
@@ -401,10 +403,10 @@ class BotManager extends EventEmitter {
|
|
|
401
403
|
name: clientInfo.name,
|
|
402
404
|
clan: clientInfo.clan || '',
|
|
403
405
|
country: clientInfo.country || -1,
|
|
404
|
-
team: playerInfo.
|
|
406
|
+
team: playerInfo.team,
|
|
405
407
|
skin: clientInfo.skin || 'default',
|
|
406
|
-
x:
|
|
407
|
-
y:
|
|
408
|
+
x: character ? character.character_core.x : null,
|
|
409
|
+
y: character ? character.character_core.y : null
|
|
408
410
|
});
|
|
409
411
|
}
|
|
410
412
|
}
|
|
@@ -426,7 +428,7 @@ class BotManager extends EventEmitter {
|
|
|
426
428
|
const msgraw = msg; // ориг для чата на всякий
|
|
427
429
|
const text = msg.message; // само сообщение
|
|
428
430
|
const client_id = msg.client_id; // айди отправителя
|
|
429
|
-
const autormsg = msg.client_id === -1 ? "system" : this.getPlayerName(botName, client_id) || (msg.
|
|
431
|
+
const autormsg = msg.client_id === -1 ? "system" : this.getPlayerName(botName, client_id) || (msg.author?.ClientInfo?.name || null) // имя отправителя
|
|
430
432
|
const team = msg.team; // команда отправителя
|
|
431
433
|
|
|
432
434
|
// фильтрация дубликатов сообщений
|