hackchat-engine 1.1.2 → 1.1.4

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/README.md CHANGED
@@ -1,48 +1,60 @@
1
- # hackchat-engine
2
-
3
- A NodeJS and browser friendly JavaScript library used to interact with a hackchat server.
4
-
5
- # Installation
6
-
7
- ## Prerequisites
8
-
9
- - [node.js 14.15](https://nodejs.org/en/download/package-manager/) or higher
10
- - [npm 6](https://nodejs.org/en/download/package-manager/) or higher
11
-
12
- ## Install
13
-
14
- `npm i hackchat-engine`
15
-
16
- # Usage
17
-
18
- ## Minimum Usage
19
-
20
- ```javascript
21
- const { Client } = require('hackchat-engine');
22
- const hcClient = new Client();
23
-
24
- const testName = 'testBot';
25
- const testPass = 'testBot';
26
- const testChannel = 'programming';
27
-
28
- hcClient.on('connected', () => console.log('Connected!'));
29
-
30
- hcClient.on('session', (payload) => {
31
- console.log(payload);
32
- hcClient.join(testName, testPass, testChannel);
33
- });
34
-
35
- hcClient.on('channelJoined', (payload) => {
36
- console.log(payload);
37
- hcClient.say(testChannel, 'Bep boop i r bot');
38
- });
39
-
40
- hcClient.on('message', (payload) => {
41
- console.log(payload);
42
- hcClient.say(testChannel, 'No u');
43
- });
44
- ```
45
-
46
- ## Advanced Usage
47
-
48
- ** Need to update this **
1
+ # hackchat-engine
2
+
3
+ A NodeJS and browser friendly JavaScript library used to interact with a hackchat server.
4
+
5
+ # Installation
6
+
7
+ ## Prerequisites
8
+
9
+ - [node.js 14.15](https://nodejs.org/en/download/package-manager/) or higher
10
+ - [npm 6](https://nodejs.org/en/download/package-manager/) or higher
11
+
12
+ ## Install
13
+
14
+ `npm i hackchat-engine`
15
+
16
+ # Usage
17
+
18
+ ## Minimum Usage
19
+
20
+ ```javascript
21
+ const { Client } = require('hackchat-engine');
22
+ const hcClient = new Client();
23
+
24
+ const testName = 'testBot';
25
+ const testPass = 'testBot';
26
+ const testChannel = 'programming';
27
+
28
+ hcClient.on('connected', () => console.log('Connected!'));
29
+
30
+ hcClient.on('session', (payload) => {
31
+ console.log(payload);
32
+ hcClient.join(testName, testPass, testChannel);
33
+ });
34
+
35
+ hcClient.on('channelJoined', (payload) => {
36
+ console.log(payload);
37
+ hcClient.say(testChannel, 'Bep boop i r bot');
38
+ });
39
+
40
+ hcClient.on('message', (payload) => {
41
+ console.log(payload);
42
+ hcClient.say(testChannel, 'No u');
43
+ });
44
+ ```
45
+
46
+ ## Advanced Usage
47
+
48
+ ** Need to update this, still **
49
+
50
+ ### Changing the connection
51
+
52
+ By default, this engine will connect to 'wss://hack.chat/chat-ws'. To change this, add a `ws.gateway` property to the `options` object, for example:
53
+
54
+ ```javascript
55
+ const hcClient = new Client({
56
+ ws: {
57
+ gateway: 'ws://1.1.1.1:6060/',
58
+ }
59
+ });
60
+ ```
package/package.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "_from": "hackchat-engine@^1.0.9",
3
- "_id": "hackchat-engine@1.0.9",
4
3
  "_inBundle": false,
5
4
  "_integrity": "sha512-uxyU4HBAs8L4hQktdtvTP/3drbJHQvjkeQDdonglAffHIPtZ1pgU9W/ScNXNCFEyqDAo/QSVikfXp0wMmLtzeQ==",
6
5
  "_location": "/hackchat-engine",
@@ -60,5 +59,5 @@
60
59
  "lintfix": "eslint --fix --ignore-path .gitignore .",
61
60
  "test": "echo \"Error: no test specified\" && exit 1"
62
61
  },
63
- "version": "1.1.2"
62
+ "version": "1.1.4"
64
63
  }
@@ -49,6 +49,14 @@ class SessionStruct {
49
49
  * @type {boolean}
50
50
  */
51
51
  this.restored = data.restored;
52
+
53
+ // add non-standard properties
54
+ const dataKeys = Object.keys(data);
55
+ for (let i = 0, j = dataKeys.length; i < j; i++) {
56
+ if (dataKeys[i] !== 'cmd' && dataKeys[i] !== 'time') {
57
+ this[dataKeys[i]] = data[dataKeys[i]];
58
+ }
59
+ }
52
60
  }
53
61
  }
54
62
 
package/util/Constants.js CHANGED
@@ -29,6 +29,7 @@ export const DefaultOptions = {
29
29
  },
30
30
 
31
31
  isBot: true,
32
+ session: false,
32
33
  };
33
34
 
34
35
  /**
@@ -66,7 +66,7 @@ class SocketController extends EventEmitter {
66
66
  */
67
67
  connect(gateway) {
68
68
  if (!this.connection) {
69
- this.connection = new SocketHandler(this, gateway);
69
+ this.connection = new SocketHandler(this, gateway, this.client.session);
70
70
  return true;
71
71
  }
72
72
 
@@ -16,7 +16,7 @@ class SocketHandler extends EventEmitter {
16
16
  * @param {SocketController} controller Controller of this handler
17
17
  * @param {string} gateway Target gateway address to connect to
18
18
  */
19
- constructor(controller, gateway) {
19
+ constructor(controller, gateway, session) {
20
20
  super();
21
21
 
22
22
  /**
@@ -80,7 +80,7 @@ class SocketHandler extends EventEmitter {
80
80
  * Current session id
81
81
  * @type {string}
82
82
  */
83
- this.sessionID = '';
83
+ this.sessionID = session;
84
84
 
85
85
  /**
86
86
  * Store new client session id when assigned
@@ -389,7 +389,7 @@ class SocketHandler extends EventEmitter {
389
389
  const payload = {
390
390
  cmd: OPCodes.SESSION,
391
391
  isBot: this.client.options.isBot,
392
- id: this.sessionID,
392
+ token: this.sessionID,
393
393
  };
394
394
 
395
395
  return this.send(payload);