vantiv.io 1.0.0
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/LICENSE +21 -0
- package/README.md +864 -0
- package/index.js +13 -0
- package/package.json +28 -0
- package/src/classes/Actions/Awaiter.js +202 -0
- package/src/classes/Actions/Channel.js +73 -0
- package/src/classes/Actions/Direct.js +263 -0
- package/src/classes/Actions/Inventory.js +156 -0
- package/src/classes/Actions/Music.js +278 -0
- package/src/classes/Actions/Player.js +377 -0
- package/src/classes/Actions/Public.js +66 -0
- package/src/classes/Actions/Room.js +333 -0
- package/src/classes/Actions/Utils.js +29 -0
- package/src/classes/Actions/lib/AudioStreaming.js +447 -0
- package/src/classes/Caches/MovementCache.js +357 -0
- package/src/classes/Handlers/AxiosErrorHandler.js +68 -0
- package/src/classes/Handlers/ErrorHandler.js +65 -0
- package/src/classes/Handlers/EventHandlers.js +259 -0
- package/src/classes/Handlers/WebSocketHandlers.js +54 -0
- package/src/classes/Managers/ChannelManager.js +303 -0
- package/src/classes/Managers/DanceFloorManagers.js +509 -0
- package/src/classes/Managers/Helpers/CleanupManager.js +130 -0
- package/src/classes/Managers/Helpers/LoggerManager.js +171 -0
- package/src/classes/Managers/Helpers/MetricsManager.js +83 -0
- package/src/classes/Managers/Networking/ConnectionManager.js +259 -0
- package/src/classes/Managers/Networking/CooldownManager.js +516 -0
- package/src/classes/Managers/Networking/EventsManager.js +64 -0
- package/src/classes/Managers/Networking/KeepAliveManager.js +109 -0
- package/src/classes/Managers/Networking/MessageHandler.js +110 -0
- package/src/classes/Managers/Networking/Request.js +329 -0
- package/src/classes/Managers/PermissionManager.js +288 -0
- package/src/classes/WebApi/Category/Grab.js +98 -0
- package/src/classes/WebApi/Category/Item.js +347 -0
- package/src/classes/WebApi/Category/Post.js +154 -0
- package/src/classes/WebApi/Category/Room.js +137 -0
- package/src/classes/WebApi/Category/User.js +88 -0
- package/src/classes/WebApi/webapi.js +52 -0
- package/src/constants/TypesConstants.js +89 -0
- package/src/constants/WebSocketConstants.js +80 -0
- package/src/core/Highrise.js +123 -0
- package/src/core/HighriseWebsocket.js +228 -0
- package/src/utils/ConvertSvgToPng.js +51 -0
- package/src/utils/ModelPool.js +160 -0
- package/src/utils/Models.js +128 -0
- package/src/utils/versionCheck.js +27 -0
- package/src/validators/ConfigValidator.js +205 -0
- package/src/validators/ConnectionValidator.js +65 -0
- package/typings/index.d.ts +3820 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
const { reactions, gold_bars } = require("../../constants/TypesConstants");
|
|
2
|
+
|
|
3
|
+
class PlayerClass {
|
|
4
|
+
constructor(bot) {
|
|
5
|
+
this.bot = bot;
|
|
6
|
+
this.logger = this.bot.logger
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async walk(x, y, z, facing = 'FrontRight') {
|
|
10
|
+
const method = 'bot.player.walk';
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
if (x === undefined || x === null || y === undefined || y === null || z === undefined || z === null) {
|
|
14
|
+
throw new TypeError('x, y, z, facing must be all be provided');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (typeof x !== 'number') throw new TypeError('x must be a number');
|
|
18
|
+
if (typeof y !== 'number') throw new TypeError('y must be a number');
|
|
19
|
+
if (typeof z !== 'number') throw new TypeError('z must be a number');
|
|
20
|
+
if (typeof facing !== 'string') throw new TypeError('facing must be a string');
|
|
21
|
+
|
|
22
|
+
const destination = { x, y, z, facing };
|
|
23
|
+
const payload = {
|
|
24
|
+
_type: 'FloorHitRequest',
|
|
25
|
+
destination: destination
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
29
|
+
return response.success;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof TypeError) {
|
|
32
|
+
this.logger.error(method, `TypeError: ${error.message}`, { x, y, z, facing }, error);
|
|
33
|
+
} else {
|
|
34
|
+
this.logger.error(method, `Failed to walk bot: ${error.message}`, { x, y, z, facing }, error);
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async sit(entity_id, anchor_ix = 0) {
|
|
41
|
+
const method = 'bot.player.sit';
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
if (!entity_id || typeof entity_id !== 'string') throw new TypeError('entity_id must be a string and non-empty string')
|
|
45
|
+
if (anchor_ix < 0 || typeof anchor_ix !== 'number') throw new TypeError('anchor_ix must be a positive number')
|
|
46
|
+
|
|
47
|
+
const anchor = { entity_id, anchor_ix };
|
|
48
|
+
const payload = {
|
|
49
|
+
_type: 'AnchorHitRequest',
|
|
50
|
+
anchor: anchor
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
54
|
+
return response.success;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error instanceof TypeError) {
|
|
57
|
+
this.logger.error(method, `TypeError: ${error.message}`, { entity_id, anchor_ix }, error);
|
|
58
|
+
} else {
|
|
59
|
+
this.logger.error(method, `Failed to sit bot: ${error.message}`, { entity_id, anchor_ix }, error);
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async teleport(user_id, x, y, z, facing = 'FrontRight') {
|
|
66
|
+
const method = 'bot.player.teleport';
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
if (!user_id) throw new TypeError('user_id must be a string and non-empty string');
|
|
70
|
+
if (x === undefined || x === null || y === undefined || y === null || z === undefined || z === null) {
|
|
71
|
+
throw new TypeError('x, y, z, facing must be all be provided');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof x !== 'number') throw new TypeError('x must be a number');
|
|
75
|
+
if (typeof y !== 'number') throw new TypeError('y must be a number');
|
|
76
|
+
if (typeof z !== 'number') throw new TypeError('z must be a number');
|
|
77
|
+
if (typeof facing !== 'string') throw new TypeError('facing must be a string');
|
|
78
|
+
|
|
79
|
+
const payload = {
|
|
80
|
+
_type: 'TeleportRequest',
|
|
81
|
+
user_id: user_id,
|
|
82
|
+
destination: { x, y, z, facing }
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
86
|
+
return response.success;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error instanceof TypeError) {
|
|
89
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id, x, y, z, facing }, error);
|
|
90
|
+
} else {
|
|
91
|
+
this.logger.error(method, `Failed to teleport: ${error.message}`, { user_id, x, y, z, facing }, error);
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async transport(user_id, room_id) {
|
|
98
|
+
const method = 'bot.player.transport';
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
102
|
+
if (!room_id || typeof room_id !== 'string') throw new TypeError('room_id must be a string and a non-empty string');
|
|
103
|
+
if (user_id === this.bot.info.user.id) throw new Error(`You can't transport bot to another room`);
|
|
104
|
+
|
|
105
|
+
const payload = {
|
|
106
|
+
_type: 'MoveUserToRoomRequest',
|
|
107
|
+
user_id: user_id,
|
|
108
|
+
room_id: room_id
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
112
|
+
return response.success;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (error instanceof TypeError) {
|
|
115
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id, room_id }, error);
|
|
116
|
+
} else {
|
|
117
|
+
this.logger.error(method, `Failed to transport user: ${error.message}`, { user_id, room_id }, error);
|
|
118
|
+
return false
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async emote(emote_id, user_id) {
|
|
124
|
+
const method = 'bot.player.emote';
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
if (user_id !== undefined && typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
128
|
+
if (!emote_id || typeof emote_id !== 'string') throw new TypeError('emote_id must be a string and a non-empty string');
|
|
129
|
+
|
|
130
|
+
const payload = {
|
|
131
|
+
_type: 'EmoteRequest',
|
|
132
|
+
emote_id: emote_id,
|
|
133
|
+
target_user_id: user_id
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
137
|
+
return response.success;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (error instanceof TypeError) {
|
|
140
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id, emote_id }, error);
|
|
141
|
+
} else {
|
|
142
|
+
this.logger.error(method, `Failed to play emote: ${error.message}`, { user_id, emote_id }, error);
|
|
143
|
+
return false
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async react(user_id, reaction) {
|
|
149
|
+
const method = 'bot.player.react';
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
153
|
+
if (!reaction || typeof reaction !== 'string') throw new TypeError('reaction must be a string and a non-empty string');
|
|
154
|
+
|
|
155
|
+
if (!reactions.includes(reaction)) {
|
|
156
|
+
throw new Error(`Invalid reaction "${reaction}", Valid reactions: ${reactions.join(', ')}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const payload = {
|
|
160
|
+
_type: 'ReactionRequest',
|
|
161
|
+
reaction: reaction,
|
|
162
|
+
target_user_id: user_id
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
166
|
+
return response.success;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error instanceof TypeError) {
|
|
169
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id, reaction }, error);
|
|
170
|
+
} else {
|
|
171
|
+
this.logger.error(method, `Failed to send reaction: ${error.message}`, { user_id, reaction }, error);
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async tip(user_id, gold_bar = 1) {
|
|
178
|
+
const method = 'bot.player.tip';
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
182
|
+
if (!gold_bar || typeof gold_bar !== 'number' || gold_bar <= 0 || gold_bar > 10_000 || !gold_bars.includes(gold_bar)) throw new TypeError(`gold_bar must be a number, bigger than 0 less than 10,000, supported amount: ${gold_bars.join(', ')}`);
|
|
183
|
+
|
|
184
|
+
const PayladGoldBars = {
|
|
185
|
+
1: "gold_bar_1",
|
|
186
|
+
5: "gold_bar_5",
|
|
187
|
+
10: "gold_bar_10",
|
|
188
|
+
50: "gold_bar_50",
|
|
189
|
+
100: "gold_bar_100",
|
|
190
|
+
500: "gold_bar_500",
|
|
191
|
+
1000: "gold_bar_1k",
|
|
192
|
+
5000: "gold_bar_5000",
|
|
193
|
+
10000: "gold_bar_10k"
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const payload = {
|
|
197
|
+
_type: 'TipUserRequest',
|
|
198
|
+
user_id: user_id,
|
|
199
|
+
gold_bar: PayladGoldBars[gold_bar]
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
203
|
+
return response.success;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (error instanceof TypeError) {
|
|
206
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id, gold_bar }, error);
|
|
207
|
+
} else {
|
|
208
|
+
this.logger.error(method, `Failed to tip user: ${error.message}`, { user_id, gold_bar }, error);
|
|
209
|
+
return false
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
outfit = {
|
|
215
|
+
get: async (user_id) => {
|
|
216
|
+
const method = 'bot.outfit.get'
|
|
217
|
+
try {
|
|
218
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
const payload = {
|
|
222
|
+
_type: 'GetUserOutfitRequest',
|
|
223
|
+
user_id: user_id
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const response = await this.bot._requestResponse.send(payload)
|
|
227
|
+
return response.outfit
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (error instanceof TypeError) {
|
|
230
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id }, error);
|
|
231
|
+
} else {
|
|
232
|
+
this.logger.error(method, `Failed to get user outfit: ${error.message}`, { user_id }, error);
|
|
233
|
+
return []
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
moderation = {
|
|
240
|
+
kick: async (user_id) => {
|
|
241
|
+
const method = 'bot.moderation.kick';
|
|
242
|
+
|
|
243
|
+
try {
|
|
244
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
245
|
+
|
|
246
|
+
const payload = {
|
|
247
|
+
_type: 'ModerateRoomRequest',
|
|
248
|
+
user_id: user_id,
|
|
249
|
+
moderation_action: 'kick',
|
|
250
|
+
action_length: null
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
254
|
+
return response.success;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
if (error instanceof TypeError) {
|
|
257
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id }, error);
|
|
258
|
+
} else {
|
|
259
|
+
this.logger.error(method, `Failed to kick user: ${error.message}`, { user_id }, error);
|
|
260
|
+
return false
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
ban: async (user_id, duration = 1 * 60 * 60 * 1000) => {
|
|
266
|
+
const method = 'bot.moderation.ban';
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
270
|
+
if (!duration ||
|
|
271
|
+
typeof duration !== 'number' ||
|
|
272
|
+
duration < 0 ||
|
|
273
|
+
duration > 69 * 365.2425 * 24 * 60 * 60 * 1000
|
|
274
|
+
) throw new TypeError('duration must be a number and a positive number and less than 69 years');
|
|
275
|
+
|
|
276
|
+
const payload = {
|
|
277
|
+
_type: 'ModerateRoomRequest',
|
|
278
|
+
user_id: user_id,
|
|
279
|
+
moderation_action: 'ban',
|
|
280
|
+
action_length: duration
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
284
|
+
return response.success;
|
|
285
|
+
} catch (error) {
|
|
286
|
+
if (error instanceof TypeError) {
|
|
287
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id, duration }, error);
|
|
288
|
+
} else {
|
|
289
|
+
this.logger.error(method, `Failed to ban user: ${error.message}`, { user_id, duration }, error);
|
|
290
|
+
return false
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
mute: async (user_id, duration = 5 * 60 * 1000) => {
|
|
296
|
+
const method = 'bot.moderation.mute';
|
|
297
|
+
|
|
298
|
+
try {
|
|
299
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
300
|
+
if (!duration ||
|
|
301
|
+
typeof duration !== 'number' ||
|
|
302
|
+
duration < 0 ||
|
|
303
|
+
duration > 69 * 365.2425 * 24 * 60 * 60 * 1000
|
|
304
|
+
) throw new TypeError('duration must be a number and a positive number and less than 69 years');
|
|
305
|
+
|
|
306
|
+
const payload = {
|
|
307
|
+
_type: 'ModerateRoomRequest',
|
|
308
|
+
user_id: user_id,
|
|
309
|
+
moderation_action: 'mute',
|
|
310
|
+
action_length: duration
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
314
|
+
return response.success;
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if (error instanceof TypeError) {
|
|
317
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id, duration }, error);
|
|
318
|
+
} else {
|
|
319
|
+
this.logger.error(method, `Failed to mute user: ${error.message}`, { user_id, duration }, error);
|
|
320
|
+
return false
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
|
|
325
|
+
unmute: async (user_id) => {
|
|
326
|
+
const method = 'bot.moderation.unmute';
|
|
327
|
+
|
|
328
|
+
try {
|
|
329
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
330
|
+
|
|
331
|
+
const payload = {
|
|
332
|
+
_type: 'ModerateRoomRequest',
|
|
333
|
+
user_id: user_id,
|
|
334
|
+
moderation_action: 'mute',
|
|
335
|
+
action_length: 1
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
339
|
+
return response.success;
|
|
340
|
+
} catch (error) {
|
|
341
|
+
if (error instanceof TypeError) {
|
|
342
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id }, error);
|
|
343
|
+
} else {
|
|
344
|
+
this.logger.error(method, `Failed to unmute user: ${error.message}`, { user_id }, error);
|
|
345
|
+
return false
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
unban: async (user_id) => {
|
|
351
|
+
const method = 'bot.moderation.unban';
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
if (!user_id || typeof user_id !== 'string') throw new TypeError('user_id must be a string and a non-empty string');
|
|
355
|
+
|
|
356
|
+
const payload = {
|
|
357
|
+
_type: 'ModerateRoomRequest',
|
|
358
|
+
user_id: user_id,
|
|
359
|
+
moderation_action: 'unban',
|
|
360
|
+
action_length: null
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
364
|
+
return response.success;
|
|
365
|
+
} catch (error) {
|
|
366
|
+
if (error instanceof TypeError) {
|
|
367
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id }, error);
|
|
368
|
+
} else {
|
|
369
|
+
this.logger.error(method, `Failed to unban user: ${error.message}`, { user_id }, error);
|
|
370
|
+
return false
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
module.exports = { PlayerClass }
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
class MessageClass {
|
|
2
|
+
constructor(bot) {
|
|
3
|
+
this.bot = bot
|
|
4
|
+
this.logger = this.bot.logger
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async send(message) {
|
|
8
|
+
const method = 'bot.message.send';
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
if (typeof message !== 'string' || !message) throw new TypeError('message must be a string and non-empty string')
|
|
12
|
+
|
|
13
|
+
const payload = {
|
|
14
|
+
_type: 'ChatRequest',
|
|
15
|
+
message: message
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
19
|
+
return response.success
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (error instanceof TypeError) {
|
|
22
|
+
this.logger.error(method, error, { message }, error);
|
|
23
|
+
} else if (error) {
|
|
24
|
+
this.logger.error(method, `Failed to send message: ${error.message}`, { message }, error);
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class WhisperClass {
|
|
32
|
+
constructor(bot) {
|
|
33
|
+
this.bot = bot
|
|
34
|
+
this.logger = this.bot._logger
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async send(user_id, message) {
|
|
38
|
+
const method = 'bot.whisper.send';
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
if (typeof message !== 'string' || !message) throw new TypeError('message must be a string and non-empty string')
|
|
42
|
+
if (typeof user_id !== 'string' || !user_id) throw new TypeError('user_id must be a string and non-empty string')
|
|
43
|
+
|
|
44
|
+
const payload = {
|
|
45
|
+
_type: 'ChatRequest',
|
|
46
|
+
message: message,
|
|
47
|
+
whisper_target_id: user_id
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const response = await this.bot._fireAndForget.send(payload)
|
|
51
|
+
return response.success
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error instanceof TypeError) {
|
|
54
|
+
this.logger.error(method, `TypeError: ${error.message}`, { user_id, message }, error);
|
|
55
|
+
} else {
|
|
56
|
+
this.logger.error(method, `Failed to send whisper: ${error.message}`, { user_id, message }, error);
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = {
|
|
64
|
+
MessageClass,
|
|
65
|
+
WhisperClass
|
|
66
|
+
}
|