ddbot.js-0374 2.1.0 → 2.1.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/bot/bot.js +11 -13
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "neiky-ddracebot.js": "^2.4.0"
6
6
  },
7
7
  "name": "ddbot.js-0374",
8
- "version": "2.1.0",
8
+ "version": "2.1.2",
9
9
  "description": "ddbot.js — это Node.js проект для автоматизации и управления ботами, а также работы с картами и логами.",
10
10
  "main": "./index.js",
11
11
  "scripts": {
package/src/bot/bot.js CHANGED
@@ -81,11 +81,11 @@ class BotManager extends EventEmitter {
81
81
  };
82
82
  logDebug('creating bot client');
83
83
  // то самое место откуда создаеться клинт бота
84
- const client = new DDRaceBot.Client(serverIp, serverPort, botName, {
84
+ const client = new DDRaceBot.Client(serverIp, serverPort, botName, { // изпользуем имя без уникального суффикса чтобы было одно имя.
85
85
  identity: identity // то самое индентити для скина и тд
86
86
  });
87
87
 
88
- // Настраиваем события для бота или пиздеи будет
88
+ // Настраиваем события для бота
89
89
  this._setupBotEvents(uniqueBotName, client);
90
90
 
91
91
  // Сохраняем информацию о боте
@@ -105,18 +105,18 @@ class BotManager extends EventEmitter {
105
105
 
106
106
  return uniqueBotName;
107
107
  } catch (error) {
108
- return null; // пиздеи
108
+ return null; // не получилось
109
109
  }
110
110
  }
111
111
 
112
112
  /**
113
113
  * Подключение бота к серверу
114
114
  * @param {string} botName
115
- * @returns {boolean} (Да если ошибок не возникло)
115
+ * @returns {boolean} (Да, если ошибок не возникло)
116
116
  */
117
117
  async connectBot(botName) {
118
118
  logDebug('connectBot called with botName:', botName); // логируем вызов функции
119
- const botInfo = this.activeBots.get(botName); // получаем инфу о боте
119
+ const botInfo = this.getBotInfo(botName); // получаем инфу о боте
120
120
  if (!botInfo) {
121
121
  return false; // бот не найден
122
122
  }
@@ -124,7 +124,7 @@ class BotManager extends EventEmitter {
124
124
  botInfo.client.joinDDRaceServer(); // то самое место подключения
125
125
  return true; // да
126
126
  } catch (error) { // фак
127
- logDebug(JSON.stringify(error, null, 2));
127
+ logDebug(error);
128
128
  return false; // нет
129
129
  }
130
130
  }
@@ -136,7 +136,7 @@ class BotManager extends EventEmitter {
136
136
  */
137
137
  disconnectBot(botName) {
138
138
  logDebug('disconnectBot called with botName:', botName); // логируем вызов функции
139
- const botInfo = this.activeBots.get(botName); // получаем инфу о боте
139
+ const botInfo = this.getBotInfo(botName); // получаем инфу о боте
140
140
  if (!botInfo) {
141
141
  return false; // бот не найден
142
142
  }
@@ -184,7 +184,7 @@ class BotManager extends EventEmitter {
184
184
  * @returns {boolean} - true если бот подключен, иначе false
185
185
  */
186
186
  isBotConnected(botName) {
187
- const botInfo = this.activeBots.get(botName); // получаем инфу о боте
187
+ const botInfo = getBotInfo(botName); // получаем инфу о боте
188
188
  return botInfo ? botInfo.isConnected : false; // подключен? да или нет
189
189
  }
190
190
 
@@ -233,10 +233,8 @@ class BotManager extends EventEmitter {
233
233
  logDebug('removeBot called with botName:', botName); // логируем вызов функции
234
234
  const botInfo = this.getBotInfo(botName); // получаем инфу о боте
235
235
  if (botInfo) {
236
- // Отключаем если подключен
237
- if (botInfo.isConnected) {
238
- this.disconnectBot(botName);
239
- }
236
+ botInfo.client.removeAllListeners(); // удаляем все слушатели событий
237
+ this.disconnectBot(botName); // отключаем бота
240
238
  this.activeBots.delete(botName); // удаляем бота
241
239
  this.botFreezeStates.delete(botName); // удаляем состояние заморозки
242
240
  this.playerLists.delete(botName); // удаляем список игроков
@@ -472,7 +470,7 @@ class BotManager extends EventEmitter {
472
470
  /**
473
471
  * Получение ID клиента бота
474
472
  * @param {string} botName - Имя бота
475
- * @returns {number|null} ID клиента бота или null если не найден, или ошибка.
473
+ * @returns {number|null|undefined} ID клиента бота или null если не найден, или ошибка.
476
474
  */
477
475
  getBotClientId(botName) {
478
476
  const client = this.getBotClient(botName);