easy-api.ts
Version:
A powerful library to create your own API with ease.
1 lines • 1.37 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});let tslib_1=require("tslib"),APIFunction_1=require("../../classes/structures/APIFunction"),Error_1=require("../../classes/structures/Error"),Util_1=require("../../classes/internal/Util"),ms_1=tslib_1.__importDefault(require("ms"));class SetTimeout extends APIFunction_1.APIFunction{name="$setTimeout";description="Set a NodeJS timeout.";parameters=[{name:"Name",description:"The name for this timeout.",type:APIFunction_1.ParamType.String,required:!0,rest:!1,defaultValue:null},{name:"Time",description:"Time to execute the code.",type:APIFunction_1.ParamType.Time,required:!0,rest:!1,defaultValue:null},{name:"Code",description:"Code to be executed when the time ends.",type:APIFunction_1.ParamType.String,required:!0,rest:!1,defaultValue:null}];usage="$setTimeout[name;time;code]";returns=APIFunction_1.ParamType.Unknown;aliases=[];compile=!1;async run(e,[t,r,i]){if(e.internalVarExists("NodeJS.Timeout:"+t))throw new Error_1.EATS_Error("There is already a timeout with that name at: "+e.function.name);if(t=await Util_1.Util.resolveCode(e,t),r=await Util_1.Util.resolveCode(e,r),r=(0,ms_1.default)(r),isNaN(r))throw new Error_1.EATS_Error("Invalid time provided at: "+e.function.name);r=setTimeout(async()=>{await Util_1.Util.resolveCode(e,i)},r),e.setInternalVar("NodeJS.Timeout:"+t,r)}}exports.default=SetTimeout;