🟢 Completed Version w/ README done (v1.0-Stable - Axios)

This commit is contained in:
Brendan Lane 2020-09-17 22:23:17 -04:00
parent 77193150ba
commit 70f311458d
11 changed files with 1632 additions and 1888 deletions

View File

@ -1,15 +1,13 @@
{ {
"env": { "env": {
"es2020": true, "es2021": true,
"node": true "node": true
}, },
"extends": "eslint:recommended", "extends": "eslint:recommended",
"parserOptions": { "parserOptions": {
"ecmaVersion": 11, "ecmaVersion": 12,
"sourceType": "module" "sourceType": "module"
}, },
"rules": { "rules": {
"semi": ["error", "always"],
"quotes": ["error", "double"]
} }
} }

230
.gitignore vendored
View File

@ -1,115 +1,115 @@
# Created by https://www.toptal.com/developers/gitignore/api/node # Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node # Edit at https://www.toptal.com/developers/gitignore?templates=node
### Node ### ### Node ###
# Logs # Logs
logs logs
*.log *.log
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
lerna-debug.log* lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html) # Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data # Runtime data
pids pids
*.pid *.pid
*.seed *.seed
*.pid.lock *.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover # Directory for instrumented libs generated by jscoverage/JSCover
lib-cov lib-cov
# Coverage directory used by tools like istanbul # Coverage directory used by tools like istanbul
coverage coverage
*.lcov *.lcov
# nyc test coverage # nyc test coverage
.nyc_output .nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt .grunt
# Bower dependency directory (https://bower.io/) # Bower dependency directory (https://bower.io/)
bower_components bower_components
# node-waf configuration # node-waf configuration
.lock-wscript .lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html) # Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release build/Release
# Dependency directories # Dependency directories
node_modules/ node_modules/
jspm_packages/ jspm_packages/
# TypeScript v1 declaration files # TypeScript v1 declaration files
typings/ typings/
# TypeScript cache # TypeScript cache
*.tsbuildinfo *.tsbuildinfo
# Optional npm cache directory # Optional npm cache directory
.npm .npm
# Optional eslint cache # Optional eslint cache
.eslintcache .eslintcache
# Microbundle cache # Microbundle cache
.rpt2_cache/ .rpt2_cache/
.rts2_cache_cjs/ .rts2_cache_cjs/
.rts2_cache_es/ .rts2_cache_es/
.rts2_cache_umd/ .rts2_cache_umd/
# Optional REPL history # Optional REPL history
.node_repl_history .node_repl_history
# Output of 'npm pack' # Output of 'npm pack'
*.tgz *.tgz
# Yarn Integrity file # Yarn Integrity file
.yarn-integrity .yarn-integrity
# dotenv environment variables file # dotenv environment variables file
.env .env
.env.test .env.test
# parcel-bundler cache (https://parceljs.org/) # parcel-bundler cache (https://parceljs.org/)
.cache .cache
# Next.js build output # Next.js build output
.next .next
# Nuxt.js build / generate output # Nuxt.js build / generate output
.nuxt .nuxt
dist dist
# Gatsby files # Gatsby files
.cache/ .cache/
# Comment in the public line in if your project uses Gatsby and not Next.js # Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support # https://nextjs.org/blog/next-9-1#public-directory-support
# public # public
# vuepress build output # vuepress build output
.vuepress/dist .vuepress/dist
# Serverless directories # Serverless directories
.serverless/ .serverless/
# FuseBox cache # FuseBox cache
.fusebox/ .fusebox/
# DynamoDB Local files # DynamoDB Local files
.dynamodb/ .dynamodb/
# TernJS port file # TernJS port file
.tern-port .tern-port
# Stores VSCode versions used for testing VSCode extensions # Stores VSCode versions used for testing VSCode extensions
.vscode-test .vscode-test
# End of https://www.toptal.com/developers/gitignore/api/node # End of https://www.toptal.com/developers/gitignore/api/node
node_modules/.bin/prettier node_modules/.bin/prettier

View File

@ -19,4 +19,15 @@ svAPI.eco.getBalance("2a0057e6-356a-4a49-b825-c37796cb7bd9", true).then(value =>
}); });
``` ```
The value variable is what the The value variable is what the function returns as a result.
It gets passed to the callback function where you can use it.
## Supported Routes
We support all the routes. We even made some.
* Auth
* User
* Group
* Eco
* Premade

View File

@ -1,65 +1,65 @@
// SpookVooper API - modules/auth.js // SpookVooper API - modules/auth.js
// Written by Brendan Lane // Written by Brendan Lane
/** @module modules/auth */ /** @module modules/auth */
import axios from "axios"; import axios from "axios";
let baseURL = "https://spookvooper.com/oauth2"; let baseURL = "https://spookvooper.com/oauth2";
let urlReturn; let urlReturn;
/** /**
* Generates a Oauth2 URL for you. This just builds a string and DOES NOT need a promise. For any updates on how this works, check #sv-developer in the discord server. https://discord.gg/spookvooper * Generates a Oauth2 URL for you. This just builds a string and DOES NOT need a promise. For any updates on how this works, check #sv-developer in the discord server. https://discord.gg/spookvooper
* @function authorize * @function authorize
* @param {string} response_type The type of response you get back. Currently the only one that is supported is "code". This argument is requried. * @param {string} response_type The type of response you get back. Currently the only one that is supported is "code". This argument is requried.
* @param {string} client_id The client ID of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2. This argument is requried. * @param {string} client_id The client ID of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2. This argument is requried.
* @param {string} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" perameter if successful. This argument is requried. * @param {string} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" perameter if successful. This argument is requried.
* @param {string} scope The scope of what you want to be able to recieve. Currently the only supported scope is "view". This argument is requried. * @param {string} scope The scope of what you want to be able to recieve. Currently the only supported scope is "view". This argument is requried.
* @param {string} state The state parameter can have anything here. Will be returned to the server upon completion. This argument is optional. * @param {string} state The state parameter can have anything here. Will be returned to the server upon completion. This argument is optional.
* @returns {string} Will return a string containing a link to the Oauth2 authorization page. If there is an error, it will return "ERROR: Oauth2 URL Builder - A required variable is undefined or is missing." * @returns {string} Will return a string containing a link to the Oauth2 authorization page. If there is an error, it will return "ERROR: Oauth2 URL Builder - A required variable is undefined or is missing."
*/ */
function authorize(response_type, client_id, redirect_uri, scope, state) { function authorize(response_type, client_id, redirect_uri, scope, state) {
if (response_type === undefined || client_id === undefined || redirect_uri === undefined || scope === undefined) { if (response_type === undefined || client_id === undefined || redirect_uri === undefined || scope === undefined) {
return "ERROR: Oauth2 URL Builder - A required variable is undefined or is missing."; return "ERROR: Oauth2 URL Builder - A required variable is undefined or is missing.";
} else if (state === undefined) { } else if (state === undefined) {
state = ""; state = "";
urlReturn = `${baseURL}/authorize?response_type=${response_type}&client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}`; urlReturn = `${baseURL}/authorize?response_type=${response_type}&client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}`;
urlReturn = urlReturn.split(" ").join("%20"); urlReturn = urlReturn.split(" ").join("%20");
return urlReturn; return urlReturn;
} else { } else {
urlReturn = `${baseURL}/authorize?response_type=${response_type}&client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}`; urlReturn = `${baseURL}/authorize?response_type=${response_type}&client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}`;
urlReturn = urlReturn.split(" ").join("%20"); urlReturn = urlReturn.split(" ").join("%20");
return urlReturn; return urlReturn;
} }
} }
/** /**
* Gets a token that you can use for Oauth2. For any updates on how this works, check #sv-developer in the discord server. https://discord.gg/spookvooper * Gets a token that you can use for Oauth2. For any updates on how this works, check #sv-developer in the discord server. https://discord.gg/spookvooper
* @function requestToken * @function requestToken
* @param {string} grant_type The type of response you get back. Currently the one that is supported is "authorization_code" * @param {string} grant_type The type of response you get back. Currently the one that is supported is "authorization_code"
* @param {string} code The code that was returned from the authorization. * @param {string} code The code that was returned from the authorization.
* @param {string} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" perameter if successful. * @param {string} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" perameter if successful.
* @param {string} client_id The client ID of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2. * @param {string} client_id The client ID of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2.
* @param {string} client_secret The client secret of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2. This WILL NOT get shared with anything other than the function it is in, and will not get sent anywhere other than https://spookvooper.com/. We take privacy very seriously. You must keep this safe. * @param {string} client_secret The client secret of your Oauth2 app. To get your client ID, go to https://spookvooper.com/oauth2. This WILL NOT get shared with anything other than the function it is in, and will not get sent anywhere other than https://spookvooper.com/. We take privacy very seriously. You must keep this safe.
* @param {boolean} errToConsole If there is an error, send it to console, instead of returning. Defaults to false * @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 containing the token, expire time in seconds, and the svid of the authorized user). * @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 containing the token, expire time in seconds, and the svid of the authorized user).
*/ */
function requestToken(grant_type, code, redirect_uri, client_id, client_secret, errToConsole) { function requestToken(grant_type, code, redirect_uri, client_id, client_secret, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/requestToken?grant_type=${grant_type}&code=${code}&redirect_uri=${redirect_uri}&client_id=${client_id}&client_secret=${client_secret}`) axios.get(`${baseURL}/requestToken?grant_type=${grant_type}&code=${code}&redirect_uri=${redirect_uri}&client_id=${client_id}&client_secret=${client_secret}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
export default { export default {
authorize, authorize,
requestToken requestToken
}; };

View File

@ -1,137 +1,137 @@
// SpookVooper API - modules/group.js // SpookVooper API - modules/group.js
// Written by Brendan Lane // Written by Brendan Lane
/** @module modules/group */ /** @module modules/group */
import axios from "axios"; import axios from "axios";
let baseURL = "https://api.spookvooper.com/group"; let baseURL = "https://api.spookvooper.com/group";
/** /**
* Checks if a group exists. * Checks if a group exists.
* @function doesGroupExist * @function doesGroupExist
* @param {string} svid The svid of the group in question. * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function doesGroupExist(svid, errToConsole) { function doesGroupExist(svid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/doesGroupExist?svid=${svid}`) axios.get(`${baseURL}/doesGroupExist?svid=${svid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets all members of a group. * Gets all members of a group.
* @function getGroupMembers * @function getGroupMembers
* @param {string} svid The svid of the group in question. * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getGroupMembers(svid, errToConsole) { function getGroupMembers(svid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getGroupMembers?svid=${svid}`) axios.get(`${baseURL}/getGroupMembers?svid=${svid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets all members of a group. * Gets all members of a group.
* @function hasGroupPermission * @function hasGroupPermission
* @param {string} svid The svid of the group in question. * @param {string} svid The svid of the group in question.
* @param {string} usersvid The svid of the user you want to check * @param {string} usersvid The svid of the user you want to check
* @param {string} permission The permission you want to search for * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function hasGroupPermission(svid, usersvid, permission, errToConsole) { function hasGroupPermission(svid, usersvid, permission, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/hasGroupPermission?svid=${svid}&usersvid=${usersvid}&permission=${permission}`) axios.get(`${baseURL}/hasGroupPermission?svid=${svid}&usersvid=${usersvid}&permission=${permission}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the SVID from a name * Gets the SVID from a name
* @function getSvidFromName * @function getSvidFromName
* @param {string} name The name of the group * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getSvidFromName(name, errToConsole) { function getSvidFromName(name, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getSvidFromName?name=${name}`) axios.get(`${baseURL}/getSvidFromName?name=${name}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the name of the group * Gets the name of the group
* @function getGroupMembers * @function getGroupMembers
* @param {string} svid The svid of the group in question. * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getName(svid, errToConsole) { function getName(svid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getName?svid=${svid}`) axios.get(`${baseURL}/getName?svid=${svid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
export default { export default {
doesGroupExist, doesGroupExist,
getGroupMembers, getGroupMembers,
hasGroupPermission, hasGroupPermission,
getSvidFromName, getSvidFromName,
getName getName
}; };

View File

@ -1,25 +1,25 @@
// SpookVooper API - modules/premade.js // SpookVooper API - modules/premade.js
// Written by Brendan Lane // Written by Brendan Lane
/** @module modules/premade */ /** @module modules/premade */
import user from "./user.js"; import user from "./user.js";
let UserResponse; let UserResponse;
/** /**
* Gets the total XP of a user * Gets the total XP of a user
* @function getTotalXP * @function getTotalXP
* @param {string} svid The svid of the user you want to lookup. * @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). * @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) { function getTotalXP(svid) {
return new Promise((resolve) => { return new Promise((resolve) => {
user.getUser(svid, true).then(value => { 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)); 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 { export default {
getTotalXP getTotalXP
}; };

View File

@ -1,261 +1,261 @@
// SpookVooper API - modules/user.js // SpookVooper API - modules/user.js
// Written by Brendan Lane // Written by Brendan Lane
/** @module modules/user */ /** @module modules/user */
import axios from "axios"; import axios from "axios";
let baseURL = "https://api.spookvooper.com/user"; let baseURL = "https://api.spookvooper.com/user";
/** /**
* Gets information on the user * Gets information on the user
* @function getUser * @function getUser
* @param {string} svid The svid for the user. * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getUser(svid, errToConsole) { function getUser(svid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUser?svid=${svid}`) axios.get(`${baseURL}/getUser?svid=${svid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the username of a user * Gets the username of a user
* @function getUsername * @function getUsername
* @param {string} svid The svid for the user lookup. * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getUsername(svid, errToConsole) { function getUsername(svid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUsername?svid=${svid}`) axios.get(`${baseURL}/getUsername?svid=${svid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the svid of a user from their username * Gets the svid of a user from their username
* @function getSvidFromUsername * @function getSvidFromUsername
* @param {string} username The username of the user * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getSvidFromUsername(username, errToConsole) { function getSvidFromUsername(username, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getSvidFromUsername?username=${username}`) axios.get(`${baseURL}/getSvidFromUsername?username=${username}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the username from their linked discord account * Gets the username from their linked discord account
* @function getUsernameFromDiscord * @function getUsernameFromDiscord
* @param {string} discordid The discord User ID for the user account. * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getUsernameFromDiscord(discordid, errToConsole) { function getUsernameFromDiscord(discordid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUsernameFromDiscord?discordid=${discordid}`) axios.get(`${baseURL}/getUsernameFromDiscord?discordid=${discordid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the SVID of a user who has their discord account linked. * Gets the SVID of a user who has their discord account linked.
* @function getSvidFromDiscord * @function getSvidFromDiscord
* @param {string} discordid The discord user ID * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getSvidFromDiscord(discordid, errToConsole) { function getSvidFromDiscord(discordid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getSvidFromDiscord?discordid=${discordid}`) axios.get(`${baseURL}/getSvidFromDiscord?discordid=${discordid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the username from the minecraft UUID. * Gets the username from the minecraft UUID.
* @function getUsernameFromMinecraft * @function getUsernameFromMinecraft
* @param {string} minecraftid The UUID of the minecraft user. * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getUsernameFromMinecraft(minecraftid, errToConsole) { function getUsernameFromMinecraft(minecraftid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getUsernameFromMinecraft?minecraftid=${minecraftid}`) axios.get(`${baseURL}/getUsernameFromMinecraft?minecraftid=${minecraftid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the SVID from the minecraft UUID. * Gets the SVID from the minecraft UUID.
* @function getSvidFromMinecraft * @function getSvidFromMinecraft
* @param {string} minecraftid The UUID of the minecraft user. * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getSvidFromMinecraft(minecraftid, errToConsole) { function getSvidFromMinecraft(minecraftid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getSvidFromMinecraft?minecraftid=${minecraftid}`) axios.get(`${baseURL}/getSvidFromMinecraft?minecraftid=${minecraftid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Checks if the user has a discord role * Checks if the user has a discord role
* @function hasDiscordRole * @function hasDiscordRole
* @param {string} userid The SVID of the user you want to lookup * @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 {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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function hasDiscordRole(userid, role, errToConsole) { function hasDiscordRole(userid, role, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/hasDiscordRole?userid=${userid}&role=${role}`) axios.get(`${baseURL}/hasDiscordRole?userid=${userid}&role=${role}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the discord roles of a user * Gets the discord roles of a user
* @function getDiscordRoles * @function getDiscordRoles
* @param {string} svid The svid of the user you want to lookup * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getDiscordRoles(svid, errToConsole) { function getDiscordRoles(svid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getDiscordRoles?svid=${svid}`) axios.get(`${baseURL}/getDiscordRoles?svid=${svid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
/** /**
* Gets the days since the last move of a user * Gets the days since the last move of a user
* @function getDiscordRoles * @function getDiscordRoles
* @param {string} svid The svid of the user you want to lookup * @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 * @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). * @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> * @author Brendan Lane <me@imbl.me>
*/ */
function getDaysSinceLastMove(svid, errToConsole) { function getDaysSinceLastMove(svid, errToConsole) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getDaysSinceLastMove?svid=${svid}`) axios.get(`${baseURL}/getDaysSinceLastMove?svid=${svid}`)
.then(function (response) { .then(function (response) {
resolve(response.data); resolve(response.data);
}) })
.catch(function (error) { .catch(function (error) {
if (errToConsole) { if (errToConsole) {
console.warn(error); console.warn(error);
} else { } else {
reject(error); reject(error);
} }
}); });
}); });
} }
export default { export default {
getUser, getUser,
getUsername, getUsername,
getSvidFromUsername, getSvidFromUsername,
getUsernameFromDiscord, getUsernameFromDiscord,
getSvidFromDiscord, getSvidFromDiscord,
getUsernameFromMinecraft, getUsernameFromMinecraft,
getSvidFromMinecraft, getSvidFromMinecraft,
hasDiscordRole, hasDiscordRole,
getDiscordRoles, getDiscordRoles,
getDaysSinceLastMove getDaysSinceLastMove
}; };

2113
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,17 +12,17 @@
"url": "https://git.imbl.me/btech/spookvooper-api-libraries.git" "url": "https://git.imbl.me/btech/spookvooper-api-libraries.git"
}, },
"keywords": [ "keywords": [
"spookvooper" "spookvooper",
"api",
"library"
], ],
"author": "bTech", "author": "bTech",
"license": "SEE LICENSE IN LICENSE", "license": "SEE LICENSE IN LICENSE",
"devDependencies": { "devDependencies": {
"eslint": "^7.7.0", "eslint": "^7.9.0",
"prettier": "2.1.1" "prettier": "^2.1.1"
}, },
"dependencies": { "dependencies": {
"axios": "^0.20.0", "axios": "^0.20.0"
"node-fetch": "^2.6.0",
"puppeteer": "^5.2.1"
} }
} }

122
routes.md
View File

@ -1,61 +1,61 @@
# API Routes # API Routes
Allowed routes from the spookvooper api. Allowed routes from the spookvooper api.
**Note:** All API routes are api.spookvooper.com OR spookvooper.com/api/ **Note:** All API routes are api.spookvooper.com OR spookvooper.com/api/
## /User Routes ## /User Routes
- /GetUser [svid]: Returns all user data - /GetUser [svid]: Returns all user data
- /GetUsername [svid]: Returns username - /GetUsername [svid]: Returns username
- /GetSVIDFromUsername [username]: Returns SVID - /GetSVIDFromUsername [username]: Returns SVID
- /GetUsernameFromDiscord [discordid]: Returns username - /GetUsernameFromDiscord [discordid]: Returns username
- /GetSVIDFromDiscord [discordid]: Returns SVID - /GetSVIDFromDiscord [discordid]: Returns SVID
- /GetUsernameFromMinecraft [minecraftid]: Returns username - /GetUsernameFromMinecraft [minecraftid]: Returns username
- /GetSVIDFromMinecraft [minecraftid]: Returns SVID - /GetSVIDFromMinecraft [minecraftid]: Returns SVID
- /HasDiscordRole [userid, role]: Returns true or false - /HasDiscordRole [userid, role]: Returns true or false
- /GetDiscordRoles [svid]: Returns list of roles - /GetDiscordRoles [svid]: Returns list of roles
- /GetDaysSinceLastMove [svid]: Returns an integer - /GetDaysSinceLastMove [svid]: Returns an integer
## Group Routes ## Group Routes
- /DoesGroupExist [svid]: Returns true or false - /DoesGroupExist [svid]: Returns true or false
- /GetGroupMembers [svid]: Returns all member SVIDs, in a json list object - /GetGroupMembers [svid]: Returns all member SVIDs, in a json list object
- /HasGroupPermission [svid, usersvid, permission]: Returns true or false - /HasGroupPermission [svid, usersvid, permission]: Returns true or false
- /GetSVIDFromName [name]: Returns SVID - /GetSVIDFromName [name]: Returns SVID
- /GetName [svid]: Returns name - /GetName [svid]: Returns name
## /Eco Routes ## /Eco Routes
- /GetBalance [svid]: Returns decimal - /GetBalance [svid]: Returns decimal
- /SendTransactionByIDs [from, to, amount, auth, detail]: Returns a result. 'from' and 'to' are svids. Detail should include 'sale' if it is a sale. - /SendTransactionByIDs [from, to, amount, auth, detail]: Returns a result. 'from' and 'to' are svids. Detail should include 'sale' if it is a sale.
- /GetStockValue [ticker]: Returns decimal - /GetStockValue [ticker]: Returns decimal
- /GetStockHistory [ticker, type, count, interval]: Returns list of stock history. Please do not use a count of over 60. Type can be "MINUTE", "HOUR", or "DAY". - /GetStockHistory [ticker, type, count, interval]: Returns list of stock history. Please do not use a count of over 60. Type can be "MINUTE", "HOUR", or "DAY".
- /SubmitStockBuy [ticker, count, price, accountid, auth]: Returns a result. Auth key must belong to accountid or have permission to it. - /SubmitStockBuy [ticker, count, price, accountid, auth]: Returns a result. Auth key must belong to accountid or have permission to it.
- /SubmitStockSell [ticker, count, price, accountid, auth]: Returns a result. Auth key must belong to accountid or have permission to it. - /SubmitStockSell [ticker, count, price, accountid, auth]: Returns a result. Auth key must belong to accountid or have permission to it.
- /CancelOrder [orderid, accountid, auth]: Returns a result. - /CancelOrder [orderid, accountid, auth]: Returns a result.
- /GetStockBuyPrice [ticker]: Returns decimal. Cheapest stock available for ticker. - /GetStockBuyPrice [ticker]: Returns decimal. Cheapest stock available for ticker.
- /GetQueueInfo [ticker, type]: Returns list of queue data. Type can be "BUY" or "SELL". - /GetQueueInfo [ticker, type]: Returns list of queue data. Type can be "BUY" or "SELL".
- /GetUserStockOffers [ticker, svid]: Returns list of stock offer data. - /GetUserStockOffers [ticker, svid]: Returns list of stock offer data.
- /GetDistrictWealth [id]: Returns total wealth of a district - /GetDistrictWealth [id]: Returns total wealth of a district
- /GetDistrictUserWealth [id]: Returns total user wealth of a district - /GetDistrictUserWealth [id]: Returns total user wealth of a district
- /GetDistrictGroupWealth [id]: Returns total group wealth of a district - /GetDistrictGroupWealth [id]: Returns total group wealth of a district
## Oauth2 ## Oauth2
What is Oauth2? What is Oauth2?
- Oauth2 allows applications to verify and control accounts from another platform without ever sharing sensitive information. - Oauth2 allows applications to verify and control accounts from another platform without ever sharing sensitive information.
How can I use Oauth2? How can I use Oauth2?
- SpookVooper is currently matching the standard Oauth configuration, although it is limited to only "code" response type and "authorization_code" grant type currently. - SpookVooper is currently matching the standard Oauth configuration, although it is limited to only "code" response type and "authorization_code" grant type currently.
You can register apps at: <https://spookvooper.com/oauth2> You can register apps at: <https://spookvooper.com/oauth2>
### Oauth2 Routes ### Oauth2 Routes
- /Authorize [response_type, client_id, redirect_uri, scope, state]: Redirects back to 'redirect_uri' with a "code" and "state" parameter if successful - /Authorize [response_type, client_id, redirect_uri, scope, state]: Redirects back to 'redirect_uri' with a "code" and "state" parameter if successful
- /RequestToken [grant_type, code, redirect_uri, client_id, client_secret]: Returns a json object containing the token, expire time in seconds, and svid of the authorized user - /RequestToken [grant_type, code, redirect_uri, client_id, client_secret]: Returns a json object containing the token, expire time in seconds, and svid of the authorized user
### What are the scopes ### What are the scopes
Currently, the only scope is View. This will be extended to eco/plot/etc in the future. Currently, the only scope is View. This will be extended to eco/plot/etc in the future.
This is currently new and may have bugs. Try not to bug me without specific issues. This is currently new and may have bugs. Try not to bug me without specific issues.

50
test.js
View File

@ -1,25 +1,25 @@
import svAPI from "./main.js"; import svAPI from "./main.js";
/* /*
svAPI.eco.getBalance("02c977bb-0a6c-4eb2-bfca-5e9101025aaf", true).then(value => { svAPI.eco.getBalance("02c977bb-0a6c-4eb2-bfca-5e9101025aaf", true).then(value => {
console.log(`[test.js] ${value}`); console.log(`[test.js] ${value}`);
}); });
*/ */
svAPI.eco.getStockBuyPrice("VNB", true).then(value => { svAPI.eco.getStockBuyPrice("VNB", true).then(value => {
console.log(value); console.log(value);
}); });
svAPI.group.getSvidFromName("Bowling Ball Industries").then(value => { svAPI.group.getSvidFromName("Bowling Ball Industries").then(value => {
console.log(value); console.log(value);
}); });
svAPI.user.getUser("02c977bb-0a6c-4eb2-bfca-5e9101025aaf", true).then(value => { svAPI.user.getUser("02c977bb-0a6c-4eb2-bfca-5e9101025aaf", true).then(value => {
console.log(value.userName); console.log(value.userName);
}); });
svAPI.premade.getTotalXP("02c977bb-0a6c-4eb2-bfca-5e9101025aaf").then(value => { svAPI.premade.getTotalXP("02c977bb-0a6c-4eb2-bfca-5e9101025aaf").then(value => {
console.log(value); console.log(value);
}); });
// Intended result should be whats on this page: https://api.spookvooper.com/eco/getbalance?svid=02c977bb-0a6c-4eb2-bfca-5e9101025aaf // Intended result should be whats on this page: https://api.spookvooper.com/eco/getbalance?svid=02c977bb-0a6c-4eb2-bfca-5e9101025aaf