hackchat-engine 1.1.6 → 1.1.7
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/events/EventsManager.js +4 -0
- package/events/HackAttempt.js +24 -0
- package/events/PublicChannels.js +24 -0
- package/package.json +1 -1
- package/structures/HackAttemptStruct.js +76 -0
- package/structures/PubChannelsStruct.js +47 -0
- package/structures/UserStruct.js +7 -0
- package/util/Constants.js +4 -0
- package/websocket/packets/PacketRouter.js +5 -0
- package/websocket/packets/handlers/EmoteHandler.js +1 -1
- package/websocket/packets/handlers/HackAttemptHandler.js +30 -0
- package/websocket/packets/handlers/InfoHandler.js +1 -1
- package/websocket/packets/handlers/InviteHandler.js +1 -1
- package/websocket/packets/handlers/PubChannelsHandler.js +30 -0
- package/websocket/packets/handlers/WhisperHandler.js +1 -1
package/events/EventsManager.js
CHANGED
|
@@ -10,6 +10,8 @@ import UserLeave from './UserLeave.js';
|
|
|
10
10
|
import UpdateUser from './UpdateUser.js';
|
|
11
11
|
import Warning from './Warning.js';
|
|
12
12
|
import Whisper from './Whisper.js';
|
|
13
|
+
import PublicChannels from './PublicChannels.js';
|
|
14
|
+
import HackAttempt from './HackAttempt.js';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* This class routes incoming event data to it's proper handler
|
|
@@ -34,6 +36,8 @@ class EventsManager {
|
|
|
34
36
|
this.UpdateUser = new UpdateUser(this.client);
|
|
35
37
|
this.Warning = new Warning(this.client);
|
|
36
38
|
this.Whisper = new Whisper(this.client);
|
|
39
|
+
this.PublicChannels = new PublicChannels(this.client);
|
|
40
|
+
this.HackAttempt = new HackAttempt(this.client);
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import AbstractEvent from './AbstractEvent.js';
|
|
2
|
+
import HackAttemptStruct from '../structures/HackAttemptStruct.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This class handles an incoming `hackattempt` event from the server
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
class PublicChannels extends AbstractEvent {
|
|
9
|
+
/**
|
|
10
|
+
* Event handler function
|
|
11
|
+
* @param {object} data Incoming event data
|
|
12
|
+
* @returns {object}
|
|
13
|
+
*/
|
|
14
|
+
handle(data) {
|
|
15
|
+
const { client } = this;
|
|
16
|
+
const message = new HackAttemptStruct(client, data);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
message,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default PublicChannels;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import AbstractEvent from './AbstractEvent.js';
|
|
2
|
+
import PubChannelsStruct from '../structures/PubChannelsStruct.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This class handles an incoming `publicchannels` event from the server
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
class PublicChannels extends AbstractEvent {
|
|
9
|
+
/**
|
|
10
|
+
* Event handler function
|
|
11
|
+
* @param {object} data Incoming event data
|
|
12
|
+
* @returns {object}
|
|
13
|
+
*/
|
|
14
|
+
handle(data) {
|
|
15
|
+
const { client } = this;
|
|
16
|
+
const message = new PubChannelsStruct(client, data);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
message,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default PublicChannels;
|
package/package.json
CHANGED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This class handles parsing of the data of a `hackAttempt` event
|
|
3
|
+
*/
|
|
4
|
+
class HackAttemptStruct {
|
|
5
|
+
/**
|
|
6
|
+
* @param {Channel} channel Channel that the hackAttempt was sent through
|
|
7
|
+
* @param {Number} fromId User id of requester
|
|
8
|
+
* @param {User} from User whomst'd sent the hackAttempt
|
|
9
|
+
* @param {String} fromNick User name of whomst'd sent the hackAttempt
|
|
10
|
+
* @param {String} lib Target library
|
|
11
|
+
* @param {Client} client Main client reference
|
|
12
|
+
*/
|
|
13
|
+
constructor(client, data) {
|
|
14
|
+
/**
|
|
15
|
+
* Add client reference
|
|
16
|
+
* @type {Client}
|
|
17
|
+
* @readonly
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(this, 'client', { value: client });
|
|
20
|
+
|
|
21
|
+
if (data) this.setup(data);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Fill in this structure with provided data
|
|
26
|
+
* @param {object} data Incoming event data
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*/
|
|
29
|
+
setup(data) {
|
|
30
|
+
/**
|
|
31
|
+
* Origin channel of the request
|
|
32
|
+
* @type {string}
|
|
33
|
+
*/
|
|
34
|
+
this.channel = data.channel;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Userid of request sender
|
|
38
|
+
* @type {number}
|
|
39
|
+
*/
|
|
40
|
+
this.fromId = data.from;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The user who sent the whisper
|
|
44
|
+
* @type {User}
|
|
45
|
+
*/
|
|
46
|
+
this.from = this.client.users.find((val) => val.userid === data.from);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Name of request sender
|
|
50
|
+
* @type {string}
|
|
51
|
+
*/
|
|
52
|
+
this.fromNick = data.fromNick;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* URL to requested library
|
|
56
|
+
* @type {string}
|
|
57
|
+
*/
|
|
58
|
+
this.lib = data.lib;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The timestamp the publicchannels was sent at
|
|
62
|
+
* @type {number}
|
|
63
|
+
*/
|
|
64
|
+
this.timestamp = new Date();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* When referenced as a string, output the content instead of an object type
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
toString() {
|
|
72
|
+
return `${this.fromNick} suggested ${this.lib}`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default HackAttemptStruct;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This class handles parsing of the data of a `publicchannels` event
|
|
3
|
+
*/
|
|
4
|
+
class PubChannelsStruct {
|
|
5
|
+
/**
|
|
6
|
+
* @param {Array} list Array of objects containing channel name and population
|
|
7
|
+
*/
|
|
8
|
+
constructor(client, data) {
|
|
9
|
+
/**
|
|
10
|
+
* Add client reference
|
|
11
|
+
* @type {Client}
|
|
12
|
+
* @readonly
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(this, 'client', { value: client });
|
|
15
|
+
|
|
16
|
+
if (data) this.setup(data);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Fill in this structure with provided data
|
|
21
|
+
* @param {object} data Incoming event data
|
|
22
|
+
* @returns {void}
|
|
23
|
+
*/
|
|
24
|
+
setup(data) {
|
|
25
|
+
/**
|
|
26
|
+
* Array of objects containing channel name and population
|
|
27
|
+
* @type {array}
|
|
28
|
+
*/
|
|
29
|
+
this.list = data.list;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The timestamp the publicchannels was sent at
|
|
33
|
+
* @type {number}
|
|
34
|
+
*/
|
|
35
|
+
this.timestamp = new Date();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* When referenced as a string, output the content instead of an object type
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
toString() {
|
|
43
|
+
return this.list.join(', ');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default PubChannelsStruct;
|
package/structures/UserStruct.js
CHANGED
|
@@ -106,6 +106,12 @@ class User {
|
|
|
106
106
|
*/
|
|
107
107
|
this.nickColor = data.color || false;
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* User's color
|
|
111
|
+
* @type {string}
|
|
112
|
+
*/
|
|
113
|
+
this.flair = data.flair || '';
|
|
114
|
+
|
|
109
115
|
/**
|
|
110
116
|
* Numeric permission level
|
|
111
117
|
* @type {number}
|
|
@@ -260,6 +266,7 @@ class User {
|
|
|
260
266
|
this.userlevel = data.uType;
|
|
261
267
|
this.bot = data.isBot;
|
|
262
268
|
this.nickColor = data.color;
|
|
269
|
+
this.flair = data.flair;
|
|
263
270
|
this.permissionLevel = data.level;
|
|
264
271
|
}
|
|
265
272
|
|
package/util/Constants.js
CHANGED
|
@@ -100,6 +100,8 @@ export const Events = {
|
|
|
100
100
|
ERROR: 'error',
|
|
101
101
|
WARN: 'warn',
|
|
102
102
|
DEBUG: 'debug',
|
|
103
|
+
PUB_CHANS: 'publicchannels',
|
|
104
|
+
HACK_ATTEMPT: 'hackAttempt',
|
|
103
105
|
};
|
|
104
106
|
|
|
105
107
|
/**
|
|
@@ -108,6 +110,7 @@ export const Events = {
|
|
|
108
110
|
*/
|
|
109
111
|
export const WSEvents = {
|
|
110
112
|
SESSION: 'session',
|
|
113
|
+
PUB_CHANS: 'publicchannels',
|
|
111
114
|
NEW_MESSAGE: 'chat',
|
|
112
115
|
CHANNEL_INFO: 'info',
|
|
113
116
|
CHANNEL_EMOTE: 'emote',
|
|
@@ -119,4 +122,5 @@ export const WSEvents = {
|
|
|
119
122
|
CHANNEL_CAPTCHA: 'captcha',
|
|
120
123
|
CHANNEL_INVITE: 'invite',
|
|
121
124
|
CHANNEL_WHISPER: 'whisper',
|
|
125
|
+
HACK_ATTEMPT: 'hackAttempt',
|
|
122
126
|
};
|
|
@@ -13,9 +13,12 @@ import UserLeaveHandler from './handlers/UserLeaveHandler.js';
|
|
|
13
13
|
import UpdateUserHandler from './handlers/UpdateUserHandler.js';
|
|
14
14
|
import CaptchaHandler from './handlers/CaptchaHandler.js';
|
|
15
15
|
import WhisperHandler from './handlers/WhisperHandler.js';
|
|
16
|
+
import PubChannelsHandler from './handlers/PubChannelsHandler.js';
|
|
17
|
+
import HackAttemptHandler from './handlers/HackAttemptHandler.js';
|
|
16
18
|
|
|
17
19
|
const BeforeReadyWhitelist = [
|
|
18
20
|
WSEvents.SESSION,
|
|
21
|
+
WSEvents.PUB_CHANS,
|
|
19
22
|
];
|
|
20
23
|
|
|
21
24
|
/**
|
|
@@ -58,6 +61,8 @@ class PacketRouter {
|
|
|
58
61
|
this.registerEvent(WSEvents.USER_UPDATE, UpdateUserHandler);
|
|
59
62
|
this.registerEvent(WSEvents.CHANNEL_CAPTCHA, CaptchaHandler);
|
|
60
63
|
this.registerEvent(WSEvents.CHANNEL_WHISPER, WhisperHandler);
|
|
64
|
+
this.registerEvent(WSEvents.PUB_CHANS, PubChannelsHandler);
|
|
65
|
+
this.registerEvent(WSEvents.HACK_ATTEMPT, HackAttemptHandler);
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
/**
|
|
@@ -16,7 +16,7 @@ class EmoteHandler extends AbstractHandler {
|
|
|
16
16
|
const response = client.events.Emote.handle(packet);
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Emitted when the client
|
|
19
|
+
* Emitted when the client receives an emote packet
|
|
20
20
|
* @event Client#emote
|
|
21
21
|
* @param {Emote} message The created message
|
|
22
22
|
*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import AbstractHandler from './AbstractHandler.js';
|
|
2
|
+
import { Events } from '../../../util/Constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles an incoming hackAttempt
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
class HackAttemptHandler extends AbstractHandler {
|
|
9
|
+
/**
|
|
10
|
+
* Parses incoming packet data and emits related events
|
|
11
|
+
* @param {object} packet Incoming packet data
|
|
12
|
+
* @returns {void}
|
|
13
|
+
*/
|
|
14
|
+
handle(packet) {
|
|
15
|
+
const { client } = this.packetRouter;
|
|
16
|
+
const response = client.events.HackAttempt.handle(packet);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Emitted when the client receives a hackAttempt packet
|
|
20
|
+
* @event Client#hackAttempt
|
|
21
|
+
* @param {HackAttemptStruct} message The hack attempt event
|
|
22
|
+
*/
|
|
23
|
+
client.emit(Events.HACK_ATTEMPT, response.message);
|
|
24
|
+
|
|
25
|
+
// Emit debug info
|
|
26
|
+
client.emit(Events.DEBUG, `[${Events.HACK_ATTEMPT}]: ${packet}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default HackAttemptHandler;
|
|
@@ -16,7 +16,7 @@ class InfoHandler extends AbstractHandler {
|
|
|
16
16
|
const response = client.events.Info.handle(packet);
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Emitted when the client
|
|
19
|
+
* Emitted when the client receives an info packet
|
|
20
20
|
* @event Client#information
|
|
21
21
|
* @param {Information} message The created message
|
|
22
22
|
*/
|
|
@@ -16,7 +16,7 @@ class InviteHandler extends AbstractHandler {
|
|
|
16
16
|
const response = client.events.Invite.handle(packet);
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Emitted when the client
|
|
19
|
+
* Emitted when the client receives an invite packet
|
|
20
20
|
* @event Client#invite
|
|
21
21
|
* @param {Invite} message The created message
|
|
22
22
|
*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import AbstractHandler from './AbstractHandler.js';
|
|
2
|
+
import { Events } from '../../../util/Constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles an incoming public channels event
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
class PubChannelsHandler extends AbstractHandler {
|
|
9
|
+
/**
|
|
10
|
+
* Parses incoming packet data and emits related events
|
|
11
|
+
* @param {object} packet Incoming packet data
|
|
12
|
+
* @returns {void}
|
|
13
|
+
*/
|
|
14
|
+
handle(packet) {
|
|
15
|
+
const { client } = this.packetRouter;
|
|
16
|
+
const response = client.events.PublicChannels.handle(packet);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Emitted when the client receives a publicchannels packet
|
|
20
|
+
* @event Client#publicchannels
|
|
21
|
+
* @param {PubChannelsStruct} message The publicchannels event
|
|
22
|
+
*/
|
|
23
|
+
client.emit(Events.PUB_CHANS, response.message);
|
|
24
|
+
|
|
25
|
+
// Emit debug info
|
|
26
|
+
client.emit(Events.DEBUG, `[${Events.PUB_CHANS}]: ${packet}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default PubChannelsHandler;
|
|
@@ -16,7 +16,7 @@ class WhisperHandler extends AbstractHandler {
|
|
|
16
16
|
const response = client.events.Whisper.handle(packet);
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Emitted when the client
|
|
19
|
+
* Emitted when the client receives a whisper packet
|
|
20
20
|
* @event Client#whisper
|
|
21
21
|
* @param {WhisperStruct} message The whisper event
|
|
22
22
|
*/
|