Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wickrio-bot-api

Package Overview
Dependencies
Maintainers
2
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wickrio-bot-api - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

9

package.json
{
"name": "wickrio-bot-api",
"version": "1.0.0",
"description": "WickrIO Bot API Framework",
"version": "1.0.1",
"description": "The official Wickr IO Bot API Framework",
"main": "WickrIOBot.js",
"dependencies": {
"wickrio_addon": "^5.8.2",
"fs": "0.0.1-security"
"fs": "0.0.2",
"simple-encryptor": "^2.0.0",
"wickrio_addon": "^5.12.4"
},

@@ -10,0 +11,0 @@ "scripts": {

# WickrIO Bot API
The Wickr IO Node.js Bot API Framework provides tools for an easier and more efficient Development of WickrIO integration bots. It utilizes the Node.js Addon API(wickrio_addon) functions to make it easier to develop integrations. For full documentation and usage guide go here: <https://wickrinc.github.io/wickrio-docs/#writing-integrations-node-js-bot-api-development-toolkit>
The Wickr IO Node.js Bot API Framework provides tools for an easier and more efficient Development of WickrIO integration bots. It utilizes the Wickr IO Node.js Addon API(wickrio_addon) functions to make it easier to develop integrations. For full documentation and usage guide go here: <https://wickrinc.github.io/wickrio-docs/#writing-integrations-node-js-bot-api-development-toolkit>

@@ -5,0 +5,0 @@ ## Install

const WickrIOAPI = require('wickrio_addon');
const WickrUser = require('./WickrUser');
var fs = require('fs');
var encryptor;

@@ -9,4 +10,6 @@ class WickrIOBot {

this.wickrUsers = [];
this.listenFlag = false;
}
//WickrIO API functions used: clientInit() and isConnected()
async start(client_username) {

@@ -26,5 +29,10 @@ try {

}).then(async function(connected) {
var settings = JSON.parse(fs.readFileSync('package.json'));
//Check if bot supports a user database
if (!settings.database) {
return true;
}
if (connected) {
var encrypted = await ref.encryptEnv();
var loaded = await ref.loadData(ref.wickrUsers);
var loaded = await ref.loadData();
return true;

@@ -45,4 +53,6 @@ } else {

//WickrIO API functions used: cmdStartAsyncRecvMessages
async startListening(callback) {
try {
var ref = this;
return new Promise(function(resolve, reject) {

@@ -55,2 +65,3 @@ var start = WickrIOAPI.cmdStartAsyncRecvMessages(callback);

}).then(function(start) {
ref.listenFlag = true;
console.log('Bot message listener set successfully!');

@@ -67,7 +78,15 @@ return true;

//WickrIO API functions used: closeClient() and cmdStopAsyncRecvMessages()
async close() {
try {
var saved = this.saveData(this.wickrUsers);
var ref = this;
var settings = JSON.parse(fs.readFileSync('package.json'));
//Check if bot supports a user database
if (settings.database) {
var saved = this.saveData();
}
return new Promise(function(resolve, reject) {
var stopMessaging = WickrIOAPI.cmdStopAsyncRecvMessages();
var stopMessaging = 'not needed';
if (ref.listenFlag === true)
stopMessaging = WickrIOAPI.cmdStopAsyncRecvMessages();
resolve(stopMessaging);

@@ -93,17 +112,26 @@ }).then(function(stopMessaging) {

} catch (err) {
console.log(err);
return false;
console.log(err);
}
}
//WickrIO API functions used: cmdEncryptString()
async encryptEnv() {
var processes = JSON.parse(fs.readFileSync('processes.json'));
var tokens = processes.apps[0].env.tokens;
for (var i in processes.apps[0].env.tokens) {
var tokens = JSON.parse(process.env.tokens);
//Create an encryptor:
var key;
if (tokens.DATABASE_ENCRYPTION_KEY.encrypted) {
key = WickrIOAPI.cmdDecryptString(tokens.DATABASE_ENCRYPTION_KEY.value);
} else {
key = tokens.DATABASE_ENCRYPTION_KEY.value;
}
encryptor = require('simple-encryptor')(key);
for (var i in tokens) {
if (i === "BOT_USERNAME")
continue;
if (!processes.apps[0].env.tokens[i].encrypted) {
if (!tokens[i].encrypted) {
try {
processes.apps[0].env.tokens[i].value = WickrIOAPI.cmdEncryptString(processes.apps[0].env.tokens[i].value);
processes.apps[0].env.tokens[i].encrypted = true;
tokens[i].value = WickrIOAPI.cmdEncryptString(tokens[i].value);
tokens[i].encrypted = true;
} catch (err) {

@@ -115,2 +143,3 @@ console.log("Unable to encrypt Bot Tokens:", err);

}
processes.apps[0].env.tokens = tokens;
var ps = fs.writeFileSync('./processes.json', JSON.stringify(processes, null, 2));

@@ -121,24 +150,15 @@ console.log("Bot tokens encrypted successfully!");

async loadData(wickrUsers) {
//Loads and decrypts the bot's user database
//WickrIO API functions used: cmdDecryptString()
async loadData() {
try {
var users = JSON.parse(fs.readFileSync('users.json'));
if (users.value.length === 0) {
var users = fs.readFileSync('users.txt', 'utf-8');
if (users.length === 0 || !users || users === "") {
return;
}
if (users.encrypted) {
console.log("Decrypting user database...");
for (var i in users.value) {
wickrUsers[i] = Object.create(users.value[i]);
for (var property in users.value[i]) {
if (users.value[i].hasOwnProperty(property) && users.value[i][property]) {
if (property === 'index')
wickrUsers[i][property] = Number(WickrIOAPI.cmdDecryptString(users.value[i][property]));
else
wickrUsers[i][property] = WickrIOAPI.cmdDecryptString(users.value[i][property]);
} else {
wickrUsers[i][property] = users.value[i][property];
}
}
}
}
console.log("Decrypting user database...");
var ciphertext = WickrIOAPI.cmdDecryptString(users.toString());
// Decrypt
var decryptedData = encryptor.decrypt(ciphertext);
this.wickrUsers = decryptedData;
} catch (err) {

@@ -149,25 +169,14 @@ console.log(err);

saveData(wickrUsers) {
//Decrypts and saves the bot's user database
//WickrIO API functions used: cmdEncryptString()
async saveData() {
try {
if (wickrUsers.length > 0) {
console.log("Encrypting user database...");
var data = [];
for (var i in wickrUsers) {
var wickrUser = Object.assign({}, wickrUsers[i]);
data.push(wickrUser);
for (var property in data[i]) {
if (data[i].hasOwnProperty(property) && data[i][property]) {
if (typeof data[i][property] === 'string')
data[i][property] = WickrIOAPI.cmdEncryptString(data[i][property]);
else
data[i][property] = WickrIOAPI.cmdEncryptString(JSON.stringify(data[i][property]));
}
}
}
var obj = {
"value": data,
"encrypted": true
};
var users = fs.writeFileSync('users.json', JSON.stringify(obj));
console.log("Encrypting user database...");
if (this.wickrUsers.length === 0) {
return;
}
// Encrypt
var ciphertext = encryptor.encrypt(this.wickrUsers);
var encrypted = WickrIOAPI.cmdEncryptString(ciphertext);
var saved = fs.writeFileSync('users.txt', encrypted, 'utf-8');
console.log("User database saved to file!");

@@ -187,52 +196,34 @@ return true;

var msgtype = message.msgtype;
if (message.message) {
var sender = message.sender;
var vGroupID = message.vgroupid;
var request = message.message.toLowerCase();
var command = '',
argument = '',
convoType = '';
var sender = message.sender;
var vGroupID = message.vgroupid;
var request = message.message;
var command = '',
argument = '',
convoType = '';
if (message.control)
return;
else
var parsedData = request.match(/(\/[a-zA-Z]+)(@[a-zA-Z0-9_-]+)?(\s+)?(.*)$/);
if (parsedData !== null) {
command = parsedData[1].toLowerCase();
if (parsedData[4] !== '') {
argument = parsedData[4].toLowerCase();
}
if (parsedData !== null) {
command = parsedData[1].toLowerCase();
if (parsedData[4] !== '') {
argument = parsedData[4].toLowerCase();
}
if (vGroupID.charAt(0) === 'a' || vGroupID.charAt(0) === 'c' || vGroupID.charAt(0) === 'd')
convoType = 'personal';
else if (vGroupID.charAt(0) === 'G')
convoType = 'groupconvo';
else
convoType = 'room';
}
if (vGroupID.charAt(0) === 'a' || vGroupID.charAt(0) === 'c' || vGroupID.charAt(0) === 'd')
convoType = 'personal';
else if (vGroupID.charAt(0) === 'G')
convoType = 'groupconvo';
else
convoType = 'room';
var parsedObj = {
'message': request,
'command': command,
'argument': argument,
'vgroupid': vGroupID,
'userEmail': sender,
'convotype': convoType
};
return parsedObj;
} else {
try {
if (message.call)
WickrIOAPI.cmdSendRoomMessage(message.vgroupid, "Sorry I cannot take calls, I wasn't given that feature yet (:");
else if (message.control) {
if (msgtype === 4002) {
WickrIOAPI.cmdSendRoomMessage(message.vgroupid, "Hey, thanks for adding me to the room!\nEnter '/help@" +
bot_username + "' to see the list of available commands.\n" +
"FYI, any commands and info you request, will be visible to all room members. To prevent that, just start a 1-to-1 convo with me and send the commands in there.");
} else if (msgtype === 4001) {
WickrIOAPI.cmdSendRoomMessage(message.vgroupid, "Hey, thanks for adding me to the group conversation!\nEnter '/help@" +
bot_username + "' to see the list of available commands.\n" +
"FYI, any commands and info you request, will be visible to all of the group conversation members. To prevent that, just start a 1-to-1 convo with me and send the commands in there.");
}
}
} catch (err) {
console.log(err);
}
return false;
}
var parsedObj = {
'message': request,
'command': command,
'argument': argument,
'vgroupid': vGroupID,
'userEmail': sender,
'convotype': convoType
};
return parsedObj;
}

@@ -242,4 +233,4 @@

this.wickrUsers.push(wickrUser);
var saved = this.saveData(this.wickrUsers);
return "New Wickr user added to database.";
var saved = this.saveData();
return console.log("New Wickr user added to database.");
}

@@ -268,3 +259,2 @@

module.exports = {

@@ -271,0 +261,0 @@ WickrIOBot,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc