Files
2026-03-22 03:21:45 +02:00

1 line
2.5 KiB
JavaScript

"use strict";function t(t){var e=new r;e.load(function(o){return o?void t(o):void t(null,e)})}function e(){return!0}var o=function(t){return t&&t.__esModule?t["default"]:t},r=o(require("./config")),n=o(require("lodash")),i={list:function(e){t(function(t,o){if(t)return void e(t);var r=o.get("robots");return Array.isArray(r)?void e(null,r):void e(null,[])})},add:function(o,r,i,u){t(function(t,a){if(t)return void u(t);if(0===o.length)return void u(new Error("Robot's name must be at least one character long"));if(e(r)===!1)return void u(new Error("IP address is not a valid ("+r+")"));if(0===i.length)return void u(new Error("Network name must be at least one character long"));var s=a.get("robots");return("undefined"==typeof s||Array.isArray(s)===!1)&&(s=[]),-1!==n.findIndex(s,function(t){return t.name===o})?void u(new Error("A robot with the name "+o+" already exists. Delete it first if you want to update it's information ")):(s.push({name:o,ip:r,network:i}),s.sort(function(t,e){return t>e}),a.set("robots",s),1===s.length&&a.set("defaultRobot",o),void a.save(function(t){u(t)}))})},remove:function(e,o){console.log(""),t(function(t,r){if(t)return void o(t);if(0===e.length)return void o(new Error("Robot's name must be at least one character long"));var i=r.get("robots");if("undefined"==typeof i||Array.isArray(i)===!1)return void o(new Error("There are no robots to delete"));var u=n.findIndex(i,function(t){return t.name===e});return-1===u?void o(new Error("No robot with the name "+e+" exists.")):(n.pullAt(i,u),r.set("robots",i),r.get("defaultRobot")===e&&r.set("defaultRobot",void 0),void r.save(function(t){o(t)}))})},setDefault:function(e,o){t(function(t,r){if(t)return void o(t);if(0===e.length)return void o(new Error("Robot's name must be at least one character long"));var i=r.get("robots");return Array.isArray(i)===!1||-1===n.findIndex(i,function(t){return t.name===e})?void o(new Error(""+e+" doesn't exist in the list of robots. Run to 'jibo robot-list' to see the list of robots")):(r.set("defaultRobot",e),void r.save(function(t){o(t)}))})},getDefault:function(e){t(function(t,o){if(t)return void e(t);var r=o.get("defaultRobot");return"undefined"==typeof r?void e(null,null):void e(null,r)})},getInfo:function(t,e){return 0===t.length?void e(new Error("Robot's name must be at least one character long")):void this.list(function(o,r){if(o)return void e(o);var i=n.findIndex(r,function(e){return e.name===t});return-1===i?void e(new Error("No robot by the name "+t+" exists in the robot list")):void e(null,r[i])})}};module.exports=i;