ddbot.js-0374 4.1.0 → 4.2.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/lib/core/core.d.ts +9 -0
- package/lib/core/core.js +12 -3
- package/lib/core/ddutils.d.ts +3 -0
- package/lib/core/ddutils.js +3 -0
- package/lib/core/module.d.ts +3 -3
- package/lib/modules/chat.d.ts +1 -2
- package/lib/modules/chat.js +14 -22
- package/lib/modules/playerlist.d.ts +1 -1
- package/lib/modules/reconnect.d.ts +1 -1
- package/lib/modules/snap.js +2 -4
- package/package.json +1 -1
package/lib/core/core.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Client } from 'teeworlds';
|
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import * as Types from '../types.js';
|
|
4
4
|
interface BotEvents {
|
|
5
|
+
error: (...args: any[]) => void;
|
|
5
6
|
connect: (info: Types.ConnectionInfo) => void;
|
|
6
7
|
disconnect: (reason: string | null, info: Types.ConnectionInfo) => void;
|
|
7
8
|
broadcast: (message: string) => void;
|
|
@@ -16,6 +17,13 @@ interface BotEvents {
|
|
|
16
17
|
kill: (kill: Types.SnapshotItemTypes.iKillMsg) => void;
|
|
17
18
|
snapshot: (items: Types.DeltaItem[]) => void;
|
|
18
19
|
map_change: (message: Types.SnapshotItemTypes.iMapChange) => void;
|
|
20
|
+
map_details: (message: {
|
|
21
|
+
map_name: string;
|
|
22
|
+
map_sha256: Buffer;
|
|
23
|
+
map_crc: number;
|
|
24
|
+
map_size: number;
|
|
25
|
+
map_url: string;
|
|
26
|
+
}) => void;
|
|
19
27
|
motd: (message: string) => void;
|
|
20
28
|
message: (message: Types.SnapshotItemTypes.iMessage) => void;
|
|
21
29
|
teams: (teams: Array<number>) => void;
|
|
@@ -51,6 +59,7 @@ export declare class Bot extends EventEmitter {
|
|
|
51
59
|
* @param CustomTeeworlds Custom teeworlds
|
|
52
60
|
*/
|
|
53
61
|
constructor(identity?: Types.SnapshotItemTypes.Identity, options?: Types.SnapshotItemTypes.iOptions, CustomTeeworlds?: typeof import('teeworlds'));
|
|
62
|
+
private error;
|
|
54
63
|
/**
|
|
55
64
|
* Get bot identity
|
|
56
65
|
*/
|
package/lib/core/core.js
CHANGED
|
@@ -32,6 +32,10 @@ export class Bot extends EventEmitter {
|
|
|
32
32
|
? identity
|
|
33
33
|
: DDUtils.DefaultIdentity('nameless tee');
|
|
34
34
|
}
|
|
35
|
+
error(...err) {
|
|
36
|
+
//console.error(err);
|
|
37
|
+
this.emit('error', ...err);
|
|
38
|
+
}
|
|
35
39
|
/**
|
|
36
40
|
* Get bot identity
|
|
37
41
|
*/
|
|
@@ -66,7 +70,7 @@ export class Bot extends EventEmitter {
|
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
catch (e) {
|
|
69
|
-
|
|
73
|
+
this.error('Error during clean:', e);
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
/**
|
|
@@ -125,6 +129,10 @@ export class Bot extends EventEmitter {
|
|
|
125
129
|
}, timeout);
|
|
126
130
|
this.once('connect', onConnect);
|
|
127
131
|
this.once('disconnect', onDisconnect);
|
|
132
|
+
if (!this.client) {
|
|
133
|
+
reject(new Error('Client not created'));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
128
136
|
this.client.connect();
|
|
129
137
|
});
|
|
130
138
|
}
|
|
@@ -140,7 +148,7 @@ export class Bot extends EventEmitter {
|
|
|
140
148
|
await this.client.Disconnect();
|
|
141
149
|
}
|
|
142
150
|
catch (e) {
|
|
143
|
-
|
|
151
|
+
this.error('Error during disconnect:', e);
|
|
144
152
|
}
|
|
145
153
|
this.status.connect.connected = false;
|
|
146
154
|
info = { addr: this.status.addr, port: this.status.port };
|
|
@@ -198,6 +206,7 @@ export class Bot extends EventEmitter {
|
|
|
198
206
|
this.client.on('kill', (msg) => this.emit('kill', msg));
|
|
199
207
|
this.client.on('snapshot', (msg) => this.emit('snapshot', msg));
|
|
200
208
|
this.client.on('map_change', (msg) => this.emit('map_change', msg));
|
|
209
|
+
this.client.on('map_details', (msg) => this.emit('map_details', msg));
|
|
201
210
|
this.client.on('motd', (msg) => this.emit('motd', msg));
|
|
202
211
|
this.client.on('message', (msg) => this.emit('message', msg));
|
|
203
212
|
this.client.on('teams', (msg) => this.emit('teams', msg));
|
|
@@ -208,7 +217,7 @@ export class Bot extends EventEmitter {
|
|
|
208
217
|
*/
|
|
209
218
|
setup_snapshot_events() {
|
|
210
219
|
if (!this.client?.SnapshotUnpacker) {
|
|
211
|
-
|
|
220
|
+
this.error('SnapshotUnpacker not available yet');
|
|
212
221
|
return;
|
|
213
222
|
}
|
|
214
223
|
this.client.SnapshotUnpacker.removeAllListeners();
|
package/lib/core/ddutils.d.ts
CHANGED
|
@@ -30,4 +30,7 @@ export declare function IsValidInput(input: unknown): input is Input;
|
|
|
30
30
|
export declare function random(min: number, max: number): number;
|
|
31
31
|
export declare function connectionInfo(): ConnectionInfo;
|
|
32
32
|
import type { SnapshotItemTypes } from '../types.js';
|
|
33
|
+
/**
|
|
34
|
+
* NOT FULL. baze.
|
|
35
|
+
*/
|
|
33
36
|
export declare function reconstructPlayerInput(char: SnapshotItemTypes.Character, ddnetChar?: SnapshotItemTypes.DDNetCharacter | null, tick?: number | null): SnapshotItemTypes.PlayerInput;
|
package/lib/core/ddutils.js
CHANGED
package/lib/core/module.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ interface BaseModuleOptions {
|
|
|
4
4
|
moduleName?: string;
|
|
5
5
|
offonDisconnect?: boolean;
|
|
6
6
|
}
|
|
7
|
-
declare class BaseModule extends EventEmitter {
|
|
7
|
+
declare class BaseModule<TStartArgs extends unknown[] = []> extends EventEmitter {
|
|
8
8
|
protected readonly bot: Bot;
|
|
9
9
|
readonly moduleName: string;
|
|
10
10
|
isRunning: boolean;
|
|
@@ -14,7 +14,7 @@ declare class BaseModule extends EventEmitter {
|
|
|
14
14
|
* Запускает модуль, если он ещё не запущен
|
|
15
15
|
* @param args — аргументы, которые будут переданы в _start
|
|
16
16
|
*/
|
|
17
|
-
start(...args:
|
|
17
|
+
start(...args: TStartArgs): void;
|
|
18
18
|
/**
|
|
19
19
|
* Останавливает модуль, если он запущен
|
|
20
20
|
*/
|
|
@@ -23,7 +23,7 @@ declare class BaseModule extends EventEmitter {
|
|
|
23
23
|
* Метод, который нужно переопределить в наследниках
|
|
24
24
|
* Здесь происходит основная логика запуска
|
|
25
25
|
*/
|
|
26
|
-
protected _start(...args:
|
|
26
|
+
protected _start(...args: TStartArgs): void;
|
|
27
27
|
/**
|
|
28
28
|
* Метод, который нужно переопределить в наследниках
|
|
29
29
|
* Здесь происходит очистка при остановке
|
package/lib/modules/chat.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ interface ChatEvents {
|
|
|
16
16
|
queueSize: number;
|
|
17
17
|
}) => void;
|
|
18
18
|
}
|
|
19
|
-
declare class Chat extends BaseModule {
|
|
19
|
+
declare class Chat extends BaseModule<[interval?: number, cooldown?: number]> {
|
|
20
20
|
private chatinterval;
|
|
21
21
|
private sendinterval;
|
|
22
22
|
private readonly chatset;
|
|
@@ -37,7 +37,6 @@ declare class Chat extends BaseModule {
|
|
|
37
37
|
private _processQueue;
|
|
38
38
|
protected _start(interval?: number, cooldown?: number): void;
|
|
39
39
|
protected _stop(): void;
|
|
40
|
-
destroy(): void;
|
|
41
40
|
on<K extends keyof ChatEvents>(event: K, listener: ChatEvents[K]): this;
|
|
42
41
|
once<K extends keyof ChatEvents>(event: K, listener: ChatEvents[K]): this;
|
|
43
42
|
emit<K extends keyof ChatEvents>(event: K, ...args: Parameters<ChatEvents[K]>): boolean;
|
package/lib/modules/chat.js
CHANGED
|
@@ -8,26 +8,21 @@ class Chat extends BaseModule {
|
|
|
8
8
|
lastSentTime = 0;
|
|
9
9
|
cooldown = 1000;
|
|
10
10
|
chatlistener = (msg) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.emit('chat', msgraw, autormsg, text, team, client_id);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
this.emit('systemchat', msgraw, text);
|
|
27
|
-
}
|
|
11
|
+
const msgraw = msg;
|
|
12
|
+
const text = String(msgraw?.message ?? '');
|
|
13
|
+
const client_id = msgraw.client_id ?? -1;
|
|
14
|
+
const team = msgraw.team ?? 0;
|
|
15
|
+
const autormsg = msgraw?.author?.ClientInfo?.name ?? null;
|
|
16
|
+
const key = `${client_id}:${text}:${team}`;
|
|
17
|
+
if (this.chatset.has(key))
|
|
18
|
+
return;
|
|
19
|
+
this.chatset.add(key);
|
|
20
|
+
this.emit('anychat', msgraw, autormsg, text, team, client_id);
|
|
21
|
+
if (autormsg) {
|
|
22
|
+
this.emit('chat', msgraw, autormsg, text, team, client_id);
|
|
28
23
|
}
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
else {
|
|
25
|
+
this.emit('systemchat', msgraw, text);
|
|
31
26
|
}
|
|
32
27
|
};
|
|
33
28
|
constructor(bot) {
|
|
@@ -102,9 +97,6 @@ class Chat extends BaseModule {
|
|
|
102
97
|
this.sendinterval = null;
|
|
103
98
|
}
|
|
104
99
|
}
|
|
105
|
-
destroy() {
|
|
106
|
-
super.destroy();
|
|
107
|
-
}
|
|
108
100
|
on(event, listener) {
|
|
109
101
|
return super.on(event, listener);
|
|
110
102
|
}
|
|
@@ -8,7 +8,7 @@ interface PlayerData {
|
|
|
8
8
|
character: Types.SnapshotItemTypes.Character | null;
|
|
9
9
|
DDNetCharacter: Types.SnapshotItemTypes.DDNetCharacter | null;
|
|
10
10
|
}
|
|
11
|
-
declare class PlayerList extends BaseModule {
|
|
11
|
+
declare class PlayerList extends BaseModule<[maxclients?: number]> {
|
|
12
12
|
constructor(bot: Bot);
|
|
13
13
|
private client;
|
|
14
14
|
private maxclients;
|
|
@@ -7,7 +7,7 @@ export interface ReconnectingInfo {
|
|
|
7
7
|
reason: string | null;
|
|
8
8
|
ConnectionInfo: Types.ConnectionInfo;
|
|
9
9
|
}
|
|
10
|
-
declare class Reconnect extends BaseModule {
|
|
10
|
+
declare class Reconnect extends BaseModule<[maxAttempts?: number, randomDelay?: boolean]> {
|
|
11
11
|
private maxAttempts;
|
|
12
12
|
private randomDelay;
|
|
13
13
|
private currentAttempts;
|
package/lib/modules/snap.js
CHANGED
|
@@ -31,7 +31,7 @@ class Snap extends BaseModule {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
ffs();
|
|
34
|
+
ffs(); // in future snapshot can be biger, so we just make new functions. блять идите нахуй со своим англиским, я не знаю но я стараюсь идите нахуй
|
|
35
35
|
};
|
|
36
36
|
constructor(bot) {
|
|
37
37
|
super(bot, { moduleName: 'Snap', offonDisconnect: false });
|
|
@@ -42,7 +42,7 @@ class Snap extends BaseModule {
|
|
|
42
42
|
const distanceY = Math.abs(y1 - y2);
|
|
43
43
|
return distanceX <= TILE && distanceY <= TILE;
|
|
44
44
|
}
|
|
45
|
-
static whoareWithinTile(x, y, list, ignoreClients = []) {
|
|
45
|
+
static whoareWithinTile(x, y, list = [], ignoreClients = []) {
|
|
46
46
|
for (const character of list) {
|
|
47
47
|
const character_core = character?.character_core;
|
|
48
48
|
if (!character_core)
|
|
@@ -69,8 +69,6 @@ class Snap extends BaseModule {
|
|
|
69
69
|
return this._isFrozen;
|
|
70
70
|
}
|
|
71
71
|
_start() {
|
|
72
|
-
if (!this.bot.status.connect.connected)
|
|
73
|
-
return;
|
|
74
72
|
this.bot.on('snapshot', this.snapslistener);
|
|
75
73
|
this.bot.on('hammerhit', this.hammerHitlistener);
|
|
76
74
|
this.bot.on('sound_world', this.firelistener);
|