resolve(response[i][0]);
const { response, execute_errors } = await request(code);
for (let i = 0, len = response.length; i < len; i++) {
const { resolve, reject } = queuePart[i];
if (response[i] === false) {
reject(execute_errors.shift());
} else {
resolve(response[i]);
}
};
const commands = [{
name: 'transfer',
value: /#перевести/i,
separator: / /,
params: ['name', 'count']
}, /* ... */];
const parse = (msg) => {
const command = commands.find((item) => (msg.match(item.value) || {}).index === 0);
if (!command) {
return null;
}
const args = msg.split(command.separator).slice(1);
return {
name: command.name,
params: command.params.reduce((acc, curr, i) => ({...acc, [curr]: args[i] || null}), {})
};
};
parse('#перевести Лёша 100');
/*
{
name: 'transfer',
params: {
name: 'Лёша',
count: '100'
}
}
*/
data.reduce((acc, curr, i) => [...acc, ...data.slice(i + 1).map((item) => `${curr} - ${item}`)], []);
const smiles = {
1: 'smile for mobile version',
2: 'smile for iPhone',
// ...
};
function getSmile(user) {
return smiles[user.last_seen.platform];
}
users.splice(users.indexOf(socket.login), 1);
async function setStat(data) {
const {status} = data.body;
// ...
return status;
}
module.exports = {setStat};
let foo = require('../controllers/foo');
async function main() {
let out = await foo.setStat(data);
console.log(out);
}