UNPKG

absenat

Version:

dedicated messaging service core

127 lines 3.76 kB
/** * @author mr-exception * @description updates first name and notifies all bridge nodes * @param {array} arguments * @param {function} finished */ const updateFirstName = (arguments, finished) => { const first_name = arguments[0]; if (!first_name) { console.log(chalk.red('Err: please enter you first name.')); return finished(); } config.first_name = first_name; fs.unlinkSync(`./configs/${config.nickname}.json`); const stream = fs.createWriteStream(`./configs/${config.nickname}.json`); stream.once('open', () => { stream.write(JSON.stringify(config)); stream.end(); db.updateFirstName(first_name); console.log(`first name changed to ${chalk.blue(first_name)}`); return finished(); }); return finished(); } /** * @author mr-exception * @description updates first name and notifies all bridge nodes * @param {array} arguments * @param {function} finished */ const updateLastName = (arguments, finished) => { const last_name = arguments[0]; if (!last_name) { console.log(chalk.red('Err: please enter you last name.')); return finished(); } config.last_name = last_name; fs.unlinkSync(`./configs/${config.nickname}.json`); const stream = fs.createWriteStream(`./configs/${config.nickname}.json`); stream.once('open', () => { stream.write(JSON.stringify(config)); stream.end(); db.updateLastName(last_name); console.log(`last name changed to ${chalk.blue(last_name)}`); return finished(); }); return finished(); } /** * @author mr-exception * @description updates first name and notifies all bridge nodes * @param {array} arguments * @param {function} finished */ const updateBio = (arguments, finished) => { const bio = arguments[0]; if (!bio) { console.log(chalk.red('Err: please enter you bio.')); return finished(); } config.bio = bio; fs.unlinkSync(`./configs/${config.nickname}.json`); const stream = fs.createWriteStream(`./configs/${config.nickname}.json`); stream.once('open', () => { stream.write(JSON.stringify(config)); stream.end(); db.updateBio(bio); console.log(`bio changed to ${chalk.blue(bio)}`); return finished(); }); return finished(); } /** * @author mr-exception * @description updates first name and notifies all bridge nodes * @param {array} arguments * @param {function} finished */ const updateEmail = (arguments, finished) => { const email = arguments[0]; if (!email) { console.log(chalk.red('Err: please enter you email.')); return finished(); } config.email = email; fs.unlinkSync(`./configs/${config.nickname}.json`); const stream = fs.createWriteStream(`./configs/${config.nickname}.json`); stream.once('open', () => { stream.write(JSON.stringify(config)); stream.end(); db.updateEmail(email); console.log(`email changed to ${chalk.blue(email)}`); return finished(); }); return finished(); } /** * @author mr-exception * @description updates first name and notifies all bridge nodes * @param {array} arguments * @param {function} finished */ const updatePhone = (arguments, finished) => { const phone = arguments[0]; if (!phone) { console.log(chalk.red('Err: please enter you phone.')); return finished(); } config.phone = phone; fs.unlinkSync(`./configs/${config.nickname}.json`); const stream = fs.createWriteStream(`./configs/${config.nickname}.json`); stream.once('open', () => { stream.write(JSON.stringify(config)); stream.end(); db.updatePhone(phone); console.log(`phone changed to ${chalk.blue(phone)}`); return finished(); }); return finished(); } module.exports = { updateFirstName, updateLastName, updateEmail, updateBio, updatePhone, }