🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@castery/caster-vk

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@castery/caster-vk - npm Package Compare versions

Comparing version

to
0.0.5

12

lib/contexts/message.js

@@ -27,3 +27,3 @@ 'use strict';

*/
constructor(caster, message, id) {
constructor(caster, { id, message, $text = null }) {
super(caster);

@@ -37,2 +37,3 @@

this.text = message.text;
this.$text = $text;

@@ -92,3 +93,6 @@ this.from = {

const message = new VKMessageContext(this.caster, this.raw, this.platform.id);
const message = new VKMessageContext(this.caster, {
id: this.platform.id,
message: this.raw
});

@@ -101,5 +105,5 @@ message.to = this.from;

options.attachments = [options.attachments];
} else {
message.attachments = options.attachments;
}
message.attachments = options.attachments;
}

@@ -106,0 +110,0 @@

@@ -58,2 +58,3 @@ 'use strict';

this._setReplacePrefix();
this._addDefaultEvents();

@@ -84,2 +85,6 @@ }

if ('prefix' in options) {
this._setReplacePrefix();
}
return this;

@@ -341,3 +346,3 @@ }

_addDefaultEvents() {
const longpoll = this.vk.longpoll;
const { longpoll } = this.vk;

@@ -358,4 +363,18 @@ longpoll.on('chat.kick', action => {

let $text = message.text;
if (message.from !== 'group' && $text !== null) {
if (message.from === 'chat' && !this._hasPrefix.test($text)) {
return;
}
$text = $text.replace(this._replacePrefix, '');
}
for (const caster of this._casters) {
caster.dispatchIncoming(new _message.VKMessageContext(caster, message, this.options.id));
caster.dispatchIncoming(new _message.VKMessageContext(caster, {
id: this.options.id,
message,
$text
}));
}

@@ -407,3 +426,15 @@ });

}
/**
* Sets replace prefix
*/
_setReplacePrefix() {
let { prefix } = this.options;
prefix = String.raw`^(?:${prefix.join('|')})`;
this._hasPrefix = new RegExp(String.raw`${prefix}.+`, 'i');
this._replacePrefix = new RegExp(String.raw`${prefix}?[, ]*`, 'i');
}
}
exports.VKPlatform = VKPlatform;

@@ -62,3 +62,7 @@ 'use strict';

* @type {Object}
* @property {boolean} [isGroup]
*
* @property {mixed} [id] Unique ID platform
* @property {Object} [adapter] Options for adapter
* @property {array} [prefix] Message prefix not for group
* @property {boolean} [isGroup] Requests optimization for group
* @property {number} [sendingInterval] Interval send message

@@ -71,2 +75,4 @@ */

prefix: ['Bot'],
isGroup: false,

@@ -88,4 +94,6 @@ sendingInterval: 1800

prefix: _joi2.default.array(),
isGroup: _joi2.default.boolean(),
sendingInterval: _joi2.default.number().min(100)
});
{
"name": "@castery/caster-vk",
"version": "0.0.4",
"version": "0.0.5",
"description": "🤖⛓️ The VK platform for caster",

@@ -36,4 +36,4 @@ "main": "index.js",

"babel-preset-env": "^1.6.0",
"chai": "^4.1.0",
"mocha": "^3.4.2"
"chai": "^4.1.1",
"mocha": "^3.5.0"
},

@@ -43,3 +43,3 @@ "dependencies": {

"bluebird": "^3.5.0",
"debug": "^2.6.8",
"debug": "^3.0.0",
"joi": "^10.6.0",

@@ -46,0 +46,0 @@ "vk-io": "^3.1.7"

@@ -26,3 +26,3 @@ 'use strict';

*/
constructor (caster, message, id) {
constructor (caster, { id, message, $text = null }) {
super(caster);

@@ -36,2 +36,3 @@

this.text = message.text;
this.$text = $text;

@@ -91,3 +92,6 @@ this.from = {

const message = new VKMessageContext(this.caster, this.raw, this.platform.id);
const message = new VKMessageContext(this.caster, {
id: this.platform.id,
message: this.raw
});

@@ -100,5 +104,5 @@ message.to = this.from;

options.attachments = [options.attachments];
} else {
message.attachments = options.attachments;
}
message.attachments = options.attachments;
}

@@ -105,0 +109,0 @@

@@ -52,2 +52,3 @@ 'use strict';

this._setReplacePrefix();
this._addDefaultEvents();

@@ -80,2 +81,6 @@ }

if ('prefix' in options) {
this._setReplacePrefix();
}
return this;

@@ -344,3 +349,3 @@ }

_addDefaultEvents () {
const longpoll = this.vk.longpoll;
const { longpoll } = this.vk;

@@ -361,5 +366,19 @@ longpoll.on('chat.kick', (action) => {

let $text = message.text;
if (message.from !== 'group' && $text !== null) {
if (message.from === 'chat' && !this._hasPrefix.test($text)) {
return;
}
$text = $text.replace(this._replacePrefix, '');
}
for (const caster of this._casters) {
caster.dispatchIncoming(
new VKMessageContext(caster, message, this.options.id)
new VKMessageContext(caster, {
id: this.options.id,
message,
$text
})
);

@@ -412,2 +431,20 @@ }

}
/**
* Sets replace prefix
*/
_setReplacePrefix () {
let { prefix } = this.options;
prefix = String.raw`^(?:${prefix.join('|')})`;
this._hasPrefix = new RegExp(
String.raw`${prefix}.+`,
'i'
);
this._replacePrefix = new RegExp(
String.raw`${prefix}?[, ]*`,
'i'
);
}
}

@@ -53,3 +53,7 @@ 'use strict';

* @type {Object}
* @property {boolean} [isGroup]
*
* @property {mixed} [id] Unique ID platform
* @property {Object} [adapter] Options for adapter
* @property {array} [prefix] Message prefix not for group
* @property {boolean} [isGroup] Requests optimization for group
* @property {number} [sendingInterval] Interval send message

@@ -62,2 +66,4 @@ */

prefix: ['Bot'],
isGroup: false,

@@ -79,4 +85,6 @@ sendingInterval: 1800

prefix: Joi.array(),
isGroup: Joi.boolean(),
sendingInterval: Joi.number().min(100)
});

Sorry, the diff of this file is not supported yet