hackchat-engine 1.1.5 → 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/.eslintrc.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es6": true,
5
- "node": true
6
- },
7
- "extends": [
8
- "airbnb-base"
9
- ],
10
- "globals": {
11
- "Atomics": "readonly",
12
- "SharedArrayBuffer": "readonly"
13
- },
14
- "parserOptions": {
15
- "ecmaVersion": 2018,
16
- "sourceType": "module"
17
- },
18
- "rules": {
19
- "import/extensions": [
20
- "error",
21
- "ignorePackages",
22
- {
23
- "js": "always"
24
- }
25
- ]
26
- }
27
- }
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es6": true,
5
+ "node": true
6
+ },
7
+ "extends": [
8
+ "airbnb-base"
9
+ ],
10
+ "globals": {
11
+ "Atomics": "readonly",
12
+ "SharedArrayBuffer": "readonly"
13
+ },
14
+ "parserOptions": {
15
+ "ecmaVersion": 2018,
16
+ "sourceType": "module"
17
+ },
18
+ "rules": {
19
+ "import/extensions": [
20
+ "error",
21
+ "ignorePackages",
22
+ {
23
+ "js": "always"
24
+ }
25
+ ]
26
+ }
27
+ }
package/Client.js CHANGED
@@ -137,7 +137,7 @@ class Client extends EventEmitter {
137
137
  * Sends a join event to the hackchat server
138
138
  * @param {string} name Name to join with
139
139
  * @param {string} password Optional password to create trip code
140
- * @param {string} channel Cchannel to auto join
140
+ * @param {string} channel Channel to auto join
141
141
  * @returns {void}
142
142
  */
143
143
  join(name = false, password = '', channel = false) {
@@ -266,6 +266,17 @@ class Client extends EventEmitter {
266
266
  this.intervals.delete(interval);
267
267
  }
268
268
 
269
+ /**
270
+ * Send `changecolor` operation to the server
271
+ * @param {string} newColor HTML color code
272
+ */
273
+ changeColor(newColor) {
274
+ this.ws.send({
275
+ cmd: OPCodes.CHANGE_COLOR,
276
+ color: newColor,
277
+ });
278
+ }
279
+
269
280
  /**
270
281
  * Send `chat` operation to the server
271
282
  * @param {string} channel Target channel to send `text`
@@ -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
@@ -1,63 +1,63 @@
1
- {
2
- "_from": "hackchat-engine@^1.0.9",
3
- "_inBundle": false,
4
- "_integrity": "sha512-uxyU4HBAs8L4hQktdtvTP/3drbJHQvjkeQDdonglAffHIPtZ1pgU9W/ScNXNCFEyqDAo/QSVikfXp0wMmLtzeQ==",
5
- "_location": "/hackchat-engine",
6
- "_phantomChildren": {},
7
- "_requested": {
8
- "type": "range",
9
- "registry": true,
10
- "raw": "hackchat-engine@^1.0.9",
11
- "name": "hackchat-engine",
12
- "escapedName": "hackchat-engine",
13
- "rawSpec": "^1.0.9",
14
- "saveSpec": null,
15
- "fetchSpec": "^1.0.9"
16
- },
17
- "_requiredBy": [
18
- "#USER",
19
- "/"
20
- ],
21
- "_resolved": "https://registry.npmjs.org/hackchat-engine/-/hackchat-engine-1.0.9.tgz",
22
- "_shasum": "536ea142dbfca44d3853c5767b7797c303642cdb",
23
- "_spec": "hackchat-engine@^1.0.9",
24
- "_where": "C:\\Users\\Owner\\Documents\\GitHub\\hcClientBeta",
25
- "author": {
26
- "name": "Marzavec"
27
- },
28
- "bugs": {
29
- "url": "https://github.com/hack-chat/hackchat-engine/issues"
30
- },
31
- "bundleDependencies": false,
32
- "dependencies": {
33
- "node-fetch": "^2.6.0",
34
- "ws": "^7.2.0"
35
- },
36
- "deprecated": false,
37
- "description": "hack.chat chat engine",
38
- "devDependencies": {
39
- "eslint": "^7.12.1",
40
- "eslint-config-airbnb-base": "^14.2.0",
41
- "eslint-plugin-import": "^2.22.1"
42
- },
43
- "homepage": "https://github.com/hack-chat/hackchat-engine#readme",
44
- "keywords": [
45
- "hack.chat",
46
- "chat",
47
- "client"
48
- ],
49
- "type": "module",
50
- "license": "WTFPL",
51
- "main": "index.js",
52
- "name": "hackchat-engine",
53
- "repository": {
54
- "type": "git",
55
- "url": "git+https://github.com/hack-chat/hackchat-engine.git"
56
- },
57
- "scripts": {
58
- "lint": "eslint --ignore-path .gitignore .",
59
- "lintfix": "eslint --fix --ignore-path .gitignore .",
60
- "test": "echo \"Error: no test specified\" && exit 1"
61
- },
62
- "version": "1.1.5"
63
- }
1
+ {
2
+ "_from": "hackchat-engine@^1.0.9",
3
+ "_inBundle": false,
4
+ "_integrity": "sha512-uxyU4HBAs8L4hQktdtvTP/3drbJHQvjkeQDdonglAffHIPtZ1pgU9W/ScNXNCFEyqDAo/QSVikfXp0wMmLtzeQ==",
5
+ "_location": "/hackchat-engine",
6
+ "_phantomChildren": {},
7
+ "_requested": {
8
+ "type": "range",
9
+ "registry": true,
10
+ "raw": "hackchat-engine@^1.0.9",
11
+ "name": "hackchat-engine",
12
+ "escapedName": "hackchat-engine",
13
+ "rawSpec": "^1.0.9",
14
+ "saveSpec": null,
15
+ "fetchSpec": "^1.0.9"
16
+ },
17
+ "_requiredBy": [
18
+ "#USER",
19
+ "/"
20
+ ],
21
+ "_resolved": "https://registry.npmjs.org/hackchat-engine/-/hackchat-engine-1.0.9.tgz",
22
+ "_shasum": "536ea142dbfca44d3853c5767b7797c303642cdb",
23
+ "_spec": "hackchat-engine@^1.0.9",
24
+ "_where": "C:\\Users\\Owner\\Documents\\GitHub\\hcClientBeta",
25
+ "author": {
26
+ "name": "Marzavec"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/hack-chat/hackchat-engine/issues"
30
+ },
31
+ "bundleDependencies": [],
32
+ "dependencies": {
33
+ "node-fetch": "^2.6.0",
34
+ "ws": "^7.2.0"
35
+ },
36
+ "deprecated": false,
37
+ "description": "hack.chat chat engine",
38
+ "devDependencies": {
39
+ "eslint": "^7.12.1",
40
+ "eslint-config-airbnb-base": "^14.2.0",
41
+ "eslint-plugin-import": "^2.22.1"
42
+ },
43
+ "homepage": "https://github.com/hack-chat/hackchat-engine#readme",
44
+ "keywords": [
45
+ "hack.chat",
46
+ "chat",
47
+ "client"
48
+ ],
49
+ "type": "module",
50
+ "license": "WTFPL",
51
+ "main": "index.js",
52
+ "name": "hackchat-engine",
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/hack-chat/hackchat-engine.git"
56
+ },
57
+ "scripts": {
58
+ "lint": "eslint --ignore-path .gitignore .",
59
+ "lintfix": "eslint --fix --ignore-path .gitignore .",
60
+ "test": "echo \"Error: no test specified\" && exit 1"
61
+ },
62
+ "version": "1.1.7"
63
+ }
@@ -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;
@@ -52,7 +52,7 @@ class SessionStruct {
52
52
 
53
53
  // add non-standard properties
54
54
  const dataKeys = Object.keys(data);
55
- for (let i = 0, j = dataKeys.length; i < j; i++) {
55
+ for (let i = 0, j = dataKeys.length; i < j; i += 1) {
56
56
  if (dataKeys[i] !== 'cmd' && dataKeys[i] !== 'time') {
57
57
  this[dataKeys[i]] = data[dataKeys[i]];
58
58
  }
@@ -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
@@ -63,6 +63,7 @@ export const OPCodes = {
63
63
  CHAT: 'chat',
64
64
  INVITE: 'invite',
65
65
  CHANGE_NICK: 'changenick',
66
+ CHANGE_COLOR: 'changecolor',
66
67
  KICK: 'kick',
67
68
  BAN: 'ban',
68
69
  MUTE: 'muzzle',
@@ -99,6 +100,8 @@ export const Events = {
99
100
  ERROR: 'error',
100
101
  WARN: 'warn',
101
102
  DEBUG: 'debug',
103
+ PUB_CHANS: 'publicchannels',
104
+ HACK_ATTEMPT: 'hackAttempt',
102
105
  };
103
106
 
104
107
  /**
@@ -107,6 +110,7 @@ export const Events = {
107
110
  */
108
111
  export const WSEvents = {
109
112
  SESSION: 'session',
113
+ PUB_CHANS: 'publicchannels',
110
114
  NEW_MESSAGE: 'chat',
111
115
  CHANNEL_INFO: 'info',
112
116
  CHANNEL_EMOTE: 'emote',
@@ -118,4 +122,5 @@ export const WSEvents = {
118
122
  CHANNEL_CAPTCHA: 'captcha',
119
123
  CHANNEL_INVITE: 'invite',
120
124
  CHANNEL_WHISPER: 'whisper',
125
+ HACK_ATTEMPT: 'hackAttempt',
121
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 recives an emote packet
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 recives an info packet
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 recives an invite packet
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 recives a whisper packet
19
+ * Emitted when the client receives a whisper packet
20
20
  * @event Client#whisper
21
21
  * @param {WhisperStruct} message The whisper event
22
22
  */