Initial Commit 3

This commit is contained in:
brendan-lane 2020-09-16 15:34:39 -04:00 committed by GitHub
parent 73acab575c
commit 77193150ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 777 additions and 0 deletions

354
modules/eco.js Normal file
View File

@ -0,0 +1,354 @@
// SpookVooper API - modules/eco.js
// Written by Brendan Lane
/** @module modules/eco */
import axios from "axios";
let baseURL = "https://api.spookvooper.com/eco";
/**
* Gets the balance of a user, given their svid.
* @function getBalance
* @param {string} svid The svid of the user in question.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
* @author Brendan Lane <me@imbl.me>
*/
function getBalance(svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getBalance?svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Makes a payment to and from accounts
* @function sendTransactionByIDs
* @param {string} to The svid of the user/group you want to send the payment to
* @param {string} from The svid of the user/group you want to send the payment from
* @param {string} amount The amount of money to be sent
* @param {string} auth An api key which has permission to use funds from the sender
* @param {string} detail A short detail of why the payment happened. Must include "sale" if it was a sale.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
* @author Brendan Lane <me@imbl.me>
*/
function sendTransactionByIDs(to, from, amount, auth, detail, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/sendTransactionByIDs?to=${to}&from=${from}&amount=${amount}&auth=${auth}&detail=${detail}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the value of a stock ticker.
* @function getStockValue
* @param {string} ticker The ticker id
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
* @author Brendan Lane <me@imbl.me>
*/
function getStockValue(ticker, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getStockValue?ticker=${ticker}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the history of a stock ticker.
* @function getStockHistory
* @param {string} ticker The ticker id
* @param {string} type Can be "MINUTE", "HOUR", or "DAY"
* @param {string} count How far back to go. Don't use a count over 60!
* @param {string} interval Set the time interval beteen data points
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be an array).
* @author Brendan Lane <me@imbl.me>
*/
function getStockHistory(ticker, type, count, interval, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getStockHistory?ticker=${ticker}&type=${type}&count=${count}&interval=${interval}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Purchases Stocks
* @function submitStockBuy
* @param {string} ticker The ticker id
* @param {string} count How many stocks you want to purchase
* @param {string} price How much you want to pay for each stock
* @param {string} accountid The SVID of the account (user or group) you'd like to purchase from.
* @param {string} auth API Key that has authentication to use the account specified in accountid.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a tesult).
* @author Brendan Lane <me@imbl.me>
*/
function submitStockBuy(ticker, count, price, accountid, auth, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/submitStockBuy?ticker=${ticker}&count=${count}&price=${price}&accountid=${accountid}&auth=${auth}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Sells Stocks
* @function submitStockSell
* @param {string} ticker The ticker id
* @param {string} count How many stocks you want to sell
* @param {string} price How much you want to sell each stock for
* @param {string} accountid The SVID of the account (user or group) you'd like to sell from.
* @param {string} auth API Key that has authentication to use the account specified in accountid.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a result).
* @author Brendan Lane <me@imbl.me>
*/
function submitStockSell(ticker, count, price, accountid, auth, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/submitStockSell?ticker=${ticker}&count=${count}&price=${price}&accountid=${accountid}&auth=${auth}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Cancels an ongoing order.
* @function cancelOrder
* @param {string} orderid The ID of the order you'd like to cancel.
* @param {string} accountid The SVID of the account (user or group) you'd like to purchase from.
* @param {string} auth API Key that has authentication to use the account specified in accountid.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a result).
* @author Brendan Lane <me@imbl.me>
*/
function cancelOrder(orderid, accountid, auth, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/submitStockBuy?orderid=${orderid}&accountid=${accountid}&auth=${auth}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the current buy price of the ticker
* @function getStockBuyPrice
* @param {string} ticker The ticker id
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
* @author Brendan Lane <me@imbl.me>
*/
function getStockBuyPrice(ticker, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getStockBuyPrice?ticker=${ticker}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the current buy price of the ticker
* @function getStockBuyPrice
* @param {string} ticker The ticker id
* @param {string} type The type of queue. Can either be "BUY" or "SELL"
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
* @author Brendan Lane <me@imbl.me>
*/
function getQueueInfo(ticker, type, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getQueueInfo?ticker=${ticker}&type=${type}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets stock offer data for a user.
* @function getUserStockOffers
* @param {string} ticker The ticker id
* @param {string} svid The SVID of the user you want to look up
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be an array).
* @author Brendan Lane <me@imbl.me>
*/
function getUserStockOffers(ticker, svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUserStockOffers?ticker=${ticker}&svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets total wealth of a district
* @function getDistrictWealth
* @param {string} id The name of the district
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
* @author Brendan Lane <me@imbl.me>
*/
function getDistrictWealth(id, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getDistrictWealth?id=${id}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets total wealth of users in a district
* @function getDistrictUserWealth
* @param {string} id The name of the district
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
* @author Brendan Lane <me@imbl.me>
*/
function getDistrictUserWealth(id, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getDistrictUserWealth?id=${id}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets total wealth of groups in a district
* @function getDistrictGroupWealth
* @param {string} id The name of the district
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a decimal).
* @author Brendan Lane <me@imbl.me>
*/
function getDistrictGroupWealth(id, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getDistrictGroupWealth?id=${id}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
export default {
getBalance,
sendTransactionByIDs,
getStockValue,
getStockHistory,
submitStockBuy,
submitStockSell,
cancelOrder,
getStockBuyPrice,
getQueueInfo,
getUserStockOffers,
getDistrictWealth,
getDistrictUserWealth,
getDistrictGroupWealth
};

137
modules/group.js Normal file
View File

@ -0,0 +1,137 @@
// SpookVooper API - modules/group.js
// Written by Brendan Lane
/** @module modules/group */
import axios from "axios";
let baseURL = "https://api.spookvooper.com/group";
/**
* Checks if a group exists.
* @function doesGroupExist
* @param {string} svid The svid of the group in question.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a boolean).
* @author Brendan Lane <me@imbl.me>
*/
function doesGroupExist(svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/doesGroupExist?svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets all members of a group.
* @function getGroupMembers
* @param {string} svid The svid of the group in question.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
* @author Brendan Lane <me@imbl.me>
*/
function getGroupMembers(svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getGroupMembers?svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets all members of a group.
* @function hasGroupPermission
* @param {string} svid The svid of the group in question.
* @param {string} usersvid The svid of the user you want to check
* @param {string} permission The permission you want to search for
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
* @author Brendan Lane <me@imbl.me>
*/
function hasGroupPermission(svid, usersvid, permission, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/hasGroupPermission?svid=${svid}&usersvid=${usersvid}&permission=${permission}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the SVID from a name
* @function getSvidFromName
* @param {string} name The name of the group
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
* @author Brendan Lane <me@imbl.me>
*/
function getSvidFromName(name, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getSvidFromName?name=${name}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the name of the group
* @function getGroupMembers
* @param {string} svid The svid of the group in question.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
* @author Brendan Lane <me@imbl.me>
*/
function getName(svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getName?svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
export default {
doesGroupExist,
getGroupMembers,
hasGroupPermission,
getSvidFromName,
getName
};

25
modules/premade.js Normal file
View File

@ -0,0 +1,25 @@
// SpookVooper API - modules/premade.js
// Written by Brendan Lane
/** @module modules/premade */
import user from "./user.js";
let UserResponse;
/**
* Gets the total XP of a user
* @function getTotalXP
* @param {string} svid The svid of the user you want to lookup.
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be an integer).
*/
function getTotalXP(svid) {
return new Promise((resolve) => {
user.getUser(svid, true).then(value => {
resolve(value.post_likes + value.comment_likes + (value.twitch_message_xp * 4) + (value.discord_commends * 5) + (value.discord_message_xp * 2) + (value.discord_game_xp / 100));
});
});
}
export default {
getTotalXP
};

261
modules/user.js Normal file
View File

@ -0,0 +1,261 @@
// SpookVooper API - modules/user.js
// Written by Brendan Lane
/** @module modules/user */
import axios from "axios";
let baseURL = "https://api.spookvooper.com/user";
/**
* Gets information on the user
* @function getUser
* @param {string} svid The svid for the user.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON object).
* @author Brendan Lane <me@imbl.me>
*/
function getUser(svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUser?svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the username of a user
* @function getUsername
* @param {string} svid The svid for the user lookup.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
* @author Brendan Lane <me@imbl.me>
*/
function getUsername(svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUsername?svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the svid of a user from their username
* @function getSvidFromUsername
* @param {string} username The username of the user
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
* @author Brendan Lane <me@imbl.me>
*/
function getSvidFromUsername(username, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getSvidFromUsername?username=${username}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the username from their linked discord account
* @function getUsernameFromDiscord
* @param {string} discordid The discord User ID for the user account.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
* @author Brendan Lane <me@imbl.me>
*/
function getUsernameFromDiscord(discordid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUsernameFromDiscord?discordid=${discordid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the SVID of a user who has their discord account linked.
* @function getSvidFromDiscord
* @param {string} discordid The discord user ID
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
* @author Brendan Lane <me@imbl.me>
*/
function getSvidFromDiscord(discordid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getSvidFromDiscord?discordid=${discordid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the username from the minecraft UUID.
* @function getUsernameFromMinecraft
* @param {string} minecraftid The UUID of the minecraft user.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
* @author Brendan Lane <me@imbl.me>
*/
function getUsernameFromMinecraft(minecraftid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUsernameFromMinecraft?minecraftid=${minecraftid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the SVID from the minecraft UUID.
* @function getSvidFromMinecraft
* @param {string} minecraftid The UUID of the minecraft user.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a string).
* @author Brendan Lane <me@imbl.me>
*/
function getSvidFromMinecraft(minecraftid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getSvidFromMinecraft?minecraftid=${minecraftid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Checks if the user has a discord role
* @function hasDiscordRole
* @param {string} userid The SVID of the user you want to lookup
* @param {string} role The name of the role you want to lookup.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a boolean).
* @author Brendan Lane <me@imbl.me>
*/
function hasDiscordRole(userid, role, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/hasDiscordRole?userid=${userid}&role=${role}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the discord roles of a user
* @function getDiscordRoles
* @param {string} svid The svid of the user you want to lookup
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a JSON Object).
* @author Brendan Lane <me@imbl.me>
*/
function getDiscordRoles(svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getDiscordRoles?svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
/**
* Gets the days since the last move of a user
* @function getDiscordRoles
* @param {string} svid The svid of the user you want to lookup
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false
* @returns {string} The data from the HTTP GET request, but because of the way it's handled, will always be a string (should be a integer).
* @author Brendan Lane <me@imbl.me>
*/
function getDaysSinceLastMove(svid, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getDaysSinceLastMove?svid=${svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
if (errToConsole) {
console.warn(error);
} else {
reject(error);
}
});
});
}
export default {
getUser,
getUsername,
getSvidFromUsername,
getUsernameFromDiscord,
getSvidFromDiscord,
getUsernameFromMinecraft,
getSvidFromMinecraft,
hasDiscordRole,
getDiscordRoles,
getDaysSinceLastMove
};