UNPKG

shock-client

Version:

A community-made Node bot library for controling PiShock devices

65 lines (59 loc) 2.11 kB
const uri = require('./uri.js') module.exports ={ /** * @description Stops the program for a set amount of time * @param {Number} ms * @returns Promise */ sleep:function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }, getUserId: async function checkVaildApi(Username, Apikey){ let result await fetch(`${uri.Vaild}?apikey=${Apikey}&username=${Username}`) .then((res) => { if (!res.ok) { throw new Error('Network response was not ok'); } return res.text(); // Get the response as text }) .then((text) => { if (text) { return JSON.parse(text); // Parse the text if it's not empty } else { throw new Error('Response body is empty'); } }) .then((data) => { result = data.UserId; }) .catch((error) => { console.error('Error fetching user ID:', error); }); return result; }, getSharedDevices: async function getSharedDevices(UserId, Apikey, IsToken){ let result await fetch(`${uri.SharedDevicesURL}?UserId=${UserId}&Token=${Apikey}&api=${IsToken}`) .then((res) => res.json()) .then((data) => { result = data; }) .catch((error) => { console.error('Error fetching shared devices:', error); }); return result; }, getDevices: async function getDevices(UserId, Apikey, IsToken){ let result await fetch(`${uri.DeviceURL}?UserId=${UserId}&Token=${Apikey}&api=${IsToken}`) .then((res) => res.json()) .then((data) => { result = data; }) .catch((error) => { console.error('Error fetching devices:', error); }); return result; } }