💻 New sync

This commit is contained in:
Brendan Lane 2020-12-08 15:50:31 -05:00
parent 7677ea0194
commit 02c8df4f53
30 changed files with 7228 additions and 5700 deletions

View File

@ -1,15 +1,21 @@
{ {
"env": { "env": {
"browser": true,
"commonjs": true, "commonjs": true,
"es2021": true, "es2021": true,
"node": true "node": true
}, },
"extends": "eslint:recommended", "extends": [
"parser": "babel-eslint", "standard-with-typescript"
],
"parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"ecmaVersion": 12 "ecmaVersion": 12,
"project": "./tsconfig.json"
}, },
"plugins": [
"@typescript-eslint"
],
"rules": { "rules": {
"strict": 0
} }
} }

154
.gitignore vendored
View File

@ -1,6 +1,6 @@
# Created by https://www.toptal.com/developers/gitignore/api/node,python # Created by https://www.toptal.com/developers/gitignore/api/node,yarn
# Edit at https://www.toptal.com/developers/gitignore?templates=node,python # Edit at https://www.toptal.com/developers/gitignore?templates=node,yarn
### Node ### ### Node ###
# Logs # Logs
@ -46,9 +46,6 @@ build/Release
node_modules/ node_modules/
jspm_packages/ jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache # TypeScript cache
*.tsbuildinfo *.tsbuildinfo
@ -76,9 +73,11 @@ typings/
# dotenv environment variables file # dotenv environment variables file
.env .env
.env.test .env.test
.env*.local
# parcel-bundler cache (https://parceljs.org/) # parcel-bundler cache (https://parceljs.org/)
.cache .cache
.parcel-cache
# Next.js build output # Next.js build output
.next .next
@ -111,138 +110,21 @@ dist
# Stores VSCode versions used for testing VSCode extensions # Stores VSCode versions used for testing VSCode extensions
.vscode-test .vscode-test
### Python ### ### yarn ###
# Byte-compiled / optimized / DLL files # https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored
__pycache__/
*.py[cod]
*$py.class
# C extensions .yarn/*
*.so !.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
# Distribution / packaging # if you are NOT using Zero-installs, then:
.Python # comment the following lines
build/ !.yarn/cache
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller # and uncomment the following lines
# Usually these files are written by a python script from a template # .pnp.*
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs # End of https://www.toptal.com/developers/gitignore/api/node,yarn
pip-log.txt src/test.ts
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
pytestdebug.log
# Translations
*.mo
*.pot
# Django stuff:
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
doc/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# End of https://www.toptal.com/developers/gitignore/api/node,python
test.js

21
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\dist\\main.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
]
}

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"editor.tabSize": 2,
"editor.insertSpaces": true
}

2010
LICENSE

File diff suppressed because it is too large Load Diff

20
main.js
View File

@ -1,20 +0,0 @@
// SpookVooper API - main.js
// Written by Brendan Lane - https://brndnln.dev/
const User = require('./modules/User.js')
const Stock = require('./modules/Stock.js')
const District = require('./modules/District.js')
const Group = require('./modules/Group.js')
const Auth = require('./modules/Auth.js')
const TransactionHub = require('./modules/TransactionHub.js')
const ExchangeHub = require('./modules/ExchangeHub.js')
module.exports = {
User,
Stock,
District,
Group,
Auth,
TransactionHub,
ExchangeHub
}

View File

@ -1,53 +0,0 @@
// SpookVooper API - modules/District.js
// Written by Brendan Lane - https://brndnln.dev/
const axios = require('axios')
const ecoURL = 'https://api.spookvooper.com/eco'
class District {
constructor(name) {
this.name = name;
}
getWealth(type) {
switch (type) {
case "ALL":
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getDistrictWealth?id=${this.name}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
case "USER":
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getDistrictUserWealth?id=${this.name}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
case "GROUP":
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getDistrictGroupWealth?id=${this.name}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
default:
throw "Parameter 'type' must be 'ALL', 'USER', or 'GROUP'";
}
}
}
module.exports = District

View File

@ -1,104 +0,0 @@
// SpookVooper API - modules/ExchangeHub.js
// Written by Brendan Lane - https://brndnln.dev/
const signalR = require('@microsoft/signalr')
const EventEmitter = require('events')
class ExchangeEmitter extends EventEmitter {}
class ExchangeHub {
#connection = new signalR.HubConnectionBuilder()
.withUrl('https://spookvooper.com/ExchangeHub')
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Information)
.build()
exchangeEvent = new ExchangeEmitter()
constructor() {
// Event Handlers
this.#connection.on('StockOffer', (offer) => {
this.exchangeEvent.emit('NewOffer', offer)
})
this.#connection.on('StockOfferCancel', (offer) => {
this.exchangeEvent.emit('OfferCancelled', offer)
})
this.#connection.on('StockTrade', (trade) => {
this.exchangeEvent.emit('StockTrade', trade)
})
this.#connection.on('RecieveMessage', (message, mode) => {
this.exchangeEvent.emit('RecieveMessage', message, mode)
})
this.#connection.on('RecieveMessageHistory', (messages, modes) => {
this.exchangeEvent.emit('RevieveMessageHistory', messages, modes)
})
// Start of connection logic
this.#connection.onclose(async (e) => {
await this.onClosed(e)
})
this.#connection.on()
this.start()
}
async start() {
console.log("Starting ExchangeHub Connection...")
try {
await this.#connection.start()
console.log("Connected to ExchangeHub")
} catch (e) {
console.error("ExchangeHub Error: Connection failed while trying to establish a connnection\n", e)
console.log("Retrying in 5 seconds")
setTimeout(() => {
this.start()
}, 5000)
}
}
async onClosed(e) {
console.error("ExchangeHub Error: Connection closed unexpectedly\n", e)
await this.start()
}
sendChatMessage(message, accountid, apikey, ticker, tradeState) {
return new Promise((resolve, reject) => {
if (message === undefined || accountid === undefined || apikey === undefined || ticker === undefined || tradeState === undefined) {
throw "All variables are needed for this to work."
}
tradeState = tradeState.toUpperCase()
if (tradeState !== "BUY" && tradeState !== "SELL") {
throw "The tradeState argument must either be 'BUY' or 'SELL'";
}
this.#connection.invoke("SendMessage", accountid, apikey, message, ticker, tradeState)
.then(function () {
resolve(true)
})
.catch(function (err) {
reject(err)
})
})
}
getMessageHistory() {
return new Promise((resolve, reject) => {
this.#connection.invoke('RequestHistory')
.then(function (val) {
resolve(val)
})
.catch(function (err) {
reject(err)
})
})
}
}
module.exports = ExchangeHub

View File

@ -1,72 +0,0 @@
// SpookVooper API - modules/Stock.js
// Written by Brendan Lane - https://brndnln.dev/
const axios = require('axios');
const ecoURL = 'https://api.spookvooper.com/eco'
class Stock {
constructor(ticker) {
this.ticker = ticker.toUpperCase();
}
getValue() {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getStockValue?ticker=${this.ticker}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
getStockBuyPrice() {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getStockBuyPrice?ticker=${this.ticker}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
getQueueInfo(type) {
switch (type) {
case "BUY":
break;
case "SELL":
break;
default:
throw "Parameter 'type' must be 'BUY' or 'SELL'"
}
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getQueueInfo?ticker=${this.ticker}&type=${type}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
getOwner() {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getOwnerData?ticker=${this.ticker}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
}
module.exports = Stock

View File

@ -1,65 +0,0 @@
// SpookVooper API - modules/TransactionHub.js
// Written by Brendan Lane - https://brndnln.dev/
const signalR = require('@microsoft/signalr')
const EventEmitter = require('events')
class TransactionEmitter extends EventEmitter {}
class TransactionHub {
#connection = new signalR.HubConnectionBuilder()
.withUrl('https://spookvooper.com/TransactionHub')
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Information)
.build();
transactionEvent = new TransactionEmitter()
#val = undefined;
fromAccount = undefined
toAccount = undefined
constructor() {
// Event Handlers
this.#connection.on('NotifyTransaction', (recieved) => {
this.#val = JSON.parse(recieved);
this.fromAccount = this.#val.FromAccount;
this.toAccount = this.#val.ToAccount;
this.transactionEvent.emit('NewTransaction', recieved);
})
// Start connection logic
this.#connection.onclose(async (e) => {
await this.onClosed(e)
});
this.#connection.on();
this.start();
}
async start() {
console.log("Starting TransactionHub Connection...");
try {
await this.#connection.start();
console.log("Connected to TransactionHub");
} catch (e) {
console.error("TransactionHub Error: Connection failed while trying to establish a connection\n", e)
console.log("Retrying in 5 seconds")
setTimeout(() => {
this.start();
}, 5000);
}
}
async onClosed(e) {
console.error("TransactionHub Error: Connection closed unexpectedly\n", e);
await this.start();
}
}
module.exports = TransactionHub

View File

@ -1,49 +0,0 @@
// SpookVooper API - modules/Auth.js
// Written by Brendan Lane - https://brndnln.dev/
const axios = require('axios')
const authURL = 'https://spookvooper.com/oauth2'
let urlReturn;
class Auth {
#clientsecret = undefined;
#authcode = undefined;
constructor(clientid, clientsecret) {
this.clientid = clientid;
this.#clientsecret = clientsecret;
}
genLink(redirect, scope, state) {
if (redirect === undefined || scope === undefined) {
throw "Both parameters 'redirect' and 'scope' must be defined!"
} else if (state === undefined) {
state = "";
urlReturn = `${authURL}/authorize?response_type=code&client_id=${this.clientid}&redirect_uri=${redirect}&scope=${scope}&state=${state}`;
urlReturn = urlReturn.split(" ").join("%20");
return urlReturn;
} else {
urlReturn = `${authURL}/authorize?response_type=code&client_id=${this.clientid}&redirect_uri=${redirect}&scope=${scope}&state=${state}`;
urlReturn = urlReturn.split(" ").join("%20");
return urlReturn;
}
}
setAuthCode(authcode) {
this.#authcode = authcode;
}
requestToken(redirect) {
return new Promise((resolve, reject) => {
axios.get(`${authURL}/requestToken?grant_type=authorization_code&code=${this.#authcode}&redirect_uri=${redirect}&client_id=${this.clientid}&client_secret=${this.#clientsecret}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
}
module.exports = Auth

View File

@ -1,113 +0,0 @@
// SpookVooper API - modules/Group.js
// Written by Brendan Lane - https://brndnln.dev/
const axios = require('axios');
const groupURL = 'https://api.spookvooper.com/group'
const ecoURL = 'https://api.spookvooper.com/eco'
class Group {
svid = undefined;
#apikey = undefined;
constructor(svid) {
this.svid = svid;
if (!this.svid.startsWith('g-')) {
throw "Error: A group must have a 'g-' or else it is not a group!"
}
}
getGroup() {
return new Promise((resolve, reject) => {
axios.get(`${groupURL}/getGroup?svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
set setApiKey(key) {
this.#apikey = key;
}
sendCredits(amount, to, reason) {
if (typeof to === "string") {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/sendTransactionByIds?from=${this.svid}&to=${to}&amount=${amount}&auth=${this.#apikey}&detail=${reason}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
} else if (typeof to === "object") {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/sendTransactionByIds?from=${this.svid}&to=${to.svid}&amount=${amount}&auth=${this.#apikey}&detail=${reason}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
} else {
throw "The 'to' parameter must be a string or an object!";
}
}
doesGroupExist() {
return new Promise((resolve, reject) => {
axios.get(`${groupURL}/doesGroupExist?svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
getGroupMembers() {
return new Promise((resolve, reject) => {
axios.get(`${groupURL}/getGroupMembers?svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
hasGroupPermission(user, permission) {
if (typeof to === "string") {
return new Promise((resolve, reject) => {
axios.get(`${groupURL}/hasGroupPermission?svid=${this.svid}&usersvid=${user}&permission=${permission}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
} else if (typeof to === "object") {
return new Promise((resolve, reject) => {
axios.get(`${groupURL}/hasGroupPermission?svid=${this.svid}&usersvid=${user.svid}&permission=${permission}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
} else {
throw "Argument user must either be a string or an object"
}
}
}
module.exports = Group

View File

@ -1,65 +0,0 @@
// SpookVooper API - modules/auth.js
// Written by Brendan Lane
/** @module modules/auth */
import axios from 'axios'
const baseURL = 'https://spookvooper.com/oauth2'
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. Get more information at the wiki. https://github.com/bowlingballindustries/spookvooper-api/wiki/Auth#authorize
* @function authorize
* @param {string} response_type The type of response you get back. Currently the only one that is supported is "code". This parameter 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 parameter is requried.
* @param {string} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" parameter if successful. This parameter is requried.
* @param {string} scope The scope of what you want to be able to receive. All scopes are allowed. This parameter is requried.
* @param {string} state The state parameter can have anything here. Will be returned to the server upon completion. This parameter 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."
*/
function authorize (response_type, client_id, redirect_uri, scope, state) {
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.'
} else if (state === undefined) {
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')
return urlReturn
} else {
urlReturn = `${baseURL}/authorize?response_type=${response_type}&client_id=${client_id}&redirect_uri=${redirect_uri}&scope=${scope}&state=${state}`
urlReturn = urlReturn.split(' ').join('%20')
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
* @function requestToken
* @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} redirect_uri Where to redirect to once authorization has been granted. Will return a "code" and "state" parameter 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_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
* @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) {
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}`)
.then(function (response) {
resolve(response.data)
})
.catch(function (error) {
if (errToConsole) {
console.warn(error)
} else {
reject(error)
}
})
})
}
export default {
authorize,
requestToken
}

View File

@ -1,378 +0,0 @@
// SpookVooper API - modules/eco.js
// Written by Brendan Lane
/** @module modules/eco */
import axios from 'axios'
const 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 or use oauthkey|app_secret formula for Oauth2.
* @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 or use oauthkey|app_secret formula for Oauth2.
* @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 or use oauthkey|app_secret formula for Oauth2.
* @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 or use oauthkey|app_secret formula for Oauth2.
* @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)
}
})
})
}
/**
* @function getOwnerData
* @param {string} ticker The stock ticker you want to query
* @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 getOwnerData (ticker, errToConsole) {
return new Promise((resolve, reject) => {
axios.get(`${baseURL}/getOwnerData?ticker=${ticker}`)
.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,
getOwnerData
}

View File

@ -1,137 +0,0 @@
// SpookVooper API - modules/group.js
// Written by Brendan Lane
/** @module modules/group */
import axios from 'axios'
const 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
}

View File

@ -1,42 +0,0 @@
// SpookVooper API - modules/premade.js
// Written by Brendan Lane
/** @module modules/premade */
import user from './user.js'
import eco from './eco.js'
let StockOwnerAmount
/**
* 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))
})
})
}
/**
* Gets the name of the stock owner and the amount they own.
* @function getStockOwner
* @param {string} ticker The ticker 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 Object).
*/
function getStockOwner (ticker) {
return new Promise((resolve) => {
eco.getOwnerData(ticker, true).then(value => {
StockOwnerAmount = value.length - 1
resolve({ name: `${value[StockOwnerAmount].ownerName}`, amount: value[StockOwnerAmount].amount })
})
})
}
export default {
getTotalXP,
getStockOwner
}

View File

@ -1,261 +0,0 @@
// SpookVooper API - modules/user.js
// Written by Brendan Lane
/** @module modules/user */
import axios from 'axios'
const 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
}

View File

@ -1,170 +0,0 @@
// SpookVooper API - modules/User.js
// Written by Brendan Lane - https://brndnln.dev
const axios = require('axios')
const userURL = "https://api.spookvooper.com/user"
const ecoURL = "https://api.spookvooper.com/eco"
class User {
#apikey = undefined;
constructor(svid) {
this.svid = svid
if (!this.svid.startsWith('u-')) {
throw "Error: A user must have a 'u-' or else it is not a user!"
}
}
getUser() {
return new Promise((resolve, reject) => {
axios.get(`${userURL}/getUser?svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
getUsername() {
return new Promise((resolve, reject) => {
axios.get(`${userURL}/getUsername?svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
getBalance() {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getBalance?svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
hasDiscordRole(role) {
return new Promise((resolve, reject) => {
axios.get(`${userURL}/hasDiscordRole?userid=${this.svid}&role=${role}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
getDiscordRoles() {
return new Promise((resolve, reject) => {
axios.get(`${userURL}/getDiscordRoles?svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
getDaysSinceLastMove() {
return new Promise((resolve, reject) => {
axios.get(`${userURL}/getDaysSinceLastMove?svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
set setApiKey(key) {
this.#apikey = key;
}
sendCredits(amount, to, reason) {
if (typeof to === "string") {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/sendTransactionByIds?from=${this.svid}&to=${to}&amount=${amount}&auth=${this.#apikey}&detail=${reason}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
} else if (typeof to === "object") {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/sendTransactionByIds?from=${this.svid}&to=${to.svid}&amount=${amount}&auth=${this.#apikey}&detail=${reason}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
} else {
throw "The 'to' parameter must be a string or an object!";
}
}
getUserStockOffers(ticker) {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getUserStockOffers?ticker=${ticker}&svid=${this.svid}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
buyStock(ticker, amount, price) {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/submitStockBuy?ticker=${ticker}&count=${amount}&price=${price}&accountid=${this.svid}&auth=${this.#apikey}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
sellStock(ticker, amount, price) {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/submitStockSell?ticker=${ticker}&count=${amount}&price=${price}&accountid=${this.svid}&auth=${this.#apikey}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
cancelStockOrder(orderid) {
return new Promise((resolve, reject) => {
axios.get(`${ecoURL}/cancelOrder?orderid=${orderid}&accountid=${this.svid}&auth=${this.#apikey}`)
.then(function (response) {
resolve(response.data);
})
.catch(function (error) {
reject(error);
});
});
}
}
module.exports = User

8780
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,15 @@
{ {
"name": "@vexico/spookvooperapi", "name": "@vexico/spookvooperapi",
"version": "1.3.0", "version": "1.3.0-alpha-1",
"description": "Easy to use library for the SpookVooper API", "description": "Easy to use library for the SpookVooper API",
"main": "main.js", "main": "dist/main.js",
"type": "commonjs", "type": "commonjs",
"scripts": { "scripts": {
"test": "node main.js" "test": "node dist/test.js",
"setup-dependencies": "npm i",
"full-lint": "npx eslint . && npx ts-standard",
"lint-style": "npx ts-standard",
"build": "npx tsc"
}, },
"publishConfig": { "publishConfig": {
"registry": "https://npm.pkg.github.com/" "registry": "https://npm.pkg.github.com/"
@ -17,18 +21,28 @@
"keywords": [ "keywords": [
"spookvooper", "spookvooper",
"api", "api",
"library" "library",
"SVAPI"
], ],
"author": "Vexi Technologies", "author": "Vexi Technologies",
"license": "SEE LICENSE IN LICENSE", "license": "AGPL-3.0-or-later",
"devDependencies": { "devDependencies": {
"babel-eslint": "^10.1.0", "@types/node": "^14.14.10",
"eslint": "^7.9.0", "@typescript-eslint/eslint-plugin": "^4.9.0",
"prettier": "^2.1.1" "@typescript-eslint/parser": "^4.9.0",
"eslint": "^7.12.1",
"eslint-config-standard": "^16.0.2",
"eslint-config-standard-with-typescript": "^18.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"prettier": "^2.1.1",
"ts-standard": "^9.0.0",
"typescript": "^4.1.2"
}, },
"dependencies": { "dependencies": {
"@microsoft/signalr": "^5.0.0", "@microsoft/signalr": "^5.0.0",
"axios": "^0.20.0" "axios": "^0.21.0"
}, },
"bugs": { "bugs": {
"url": "https://github.com/vexico/spookvooper-api/issues" "url": "https://github.com/vexico/spookvooper-api/issues"

8
src/main.ts Normal file
View File

@ -0,0 +1,8 @@
// SpookVooper API - src/main.ts
// Written by Brendan Lane - https://brndnln.dev/
import User from './modules/User'
export {
User
}

17
src/modules/Group.ts Normal file
View File

@ -0,0 +1,17 @@
// SpookVooper API - modules/Group.ts
// Written by Brendan Lane - https://brndnln.dev/
import axios from 'axios'
const groupURL = 'https://api.spookvooper.com/group'
const ecoURL = 'https://api.spookvooper.com/eco'
class Group {
private accountid: string
constructor (svid: string) {
this.accountid = svid
}
}
export default Group

245
src/modules/User.ts Normal file
View File

@ -0,0 +1,245 @@
// SpookVooper API - modules/User.ts
// Written by Brendan Lane - https://brndnln.dev
import axios from 'axios'
import { CreditAmount, PaymentEntity, SVStockTicker } from './types/Types'
import { ConfigUser } from './interfaces/Interfaces'
const userURL: string = 'https://api.spookvooper.com/user'
const ecoURL: string = 'https://api.spookvooper.com/eco'
class User {
private accountid: string
private authkey: string
public constructor (config: ConfigUser) {
if (!config.svid.startsWith('u-')) {
throw new Error('A user svid must have a \'u-\' in front of it to comply with the latest API changes.')
}
this.accountid = config.svid
if (config.apikey !== undefined) {
this.authkey = config.apikey
}
}
public async getUser (): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${userURL}/getUser`, {
params: {
svid: this.accountid
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public async getUsername (): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${userURL}/getUsername`, {
params: {
svid: this.accountid
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public async getBalance (): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getBalance`, {
params: {
svid: this.accountid
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public async hasDiscordRole (role: string): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${userURL}/hasDiscordRole`, {
params: {
userid: this.accountid,
role: role
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public async getDiscordRoles (): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${userURL}/getDiscordRoles`, {
params: {
svid: this.accountid
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public async sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string): Promise<any> {
if (typeof to === 'string') {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/sendTransactionByIds`, {
params: {
from: this.accountid,
to: to,
amount: amount,
auth: this.authkey,
detail: reason
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
} else if (typeof to === 'object') {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/sendTransactionByIds`, {
params: {
from: this.accountid,
to: to.svid,
amount: amount,
auth: this.authkey,
detail: reason
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
} else {
throw new Error('The \'to\' parameter must be a string or an object!')
}
}
public async getStockOffers (ticker: SVStockTicker): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/getUserStockOffers`, {
params: {
ticker: ticker,
svid: this.accountid
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public async buyStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/submitStockBuy`, {
params: {
ticker: ticker,
count: amount,
price: price,
accountid: this.accountid,
auth: this.authkey
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public async sellStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/submitStockSell`, {
params: {
ticker: ticker,
count: amount,
price: price,
accountid: this.accountid,
auth: this.authkey
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public async cancelOffer (orderid: number): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/cancelOrder`, {
params: {
orderid: orderid,
accountid: this.accountid,
auth: this.authkey
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
public get apikey (): string {
return this.authkey
}
public set apikey (apikey: string) {
this.authkey = apikey
}
public get svid (): string {
return this.accountid
}
public set svid (svid: string) {
if (!svid.startsWith('u-')) {
throw new Error('A user svid must have a \'u-\' in front of it to comply with the latest API changes.')
}
this.accountid = svid
}
}
export default User

View File

@ -0,0 +1,25 @@
// SpookVooper API - modules/interfaces/Interfaces.ts
// Written by Brendan Lane - https://brndnln.dev/
export interface EntityUser {
getUser: () => Promise<any>
getUsername: () => Promise<any>
getBalance: () => Promise<any>
hasDiscordRole: () => Promise<any>
getDiscordRoles: () => Promise<any>
sendCredits: () => Promise<any>
getStockOffers: () => Promise<any>
buyStock: () => Promise<any>
sellStock: () => Promise<any>
readonly svid: string
readonly apikey: string
}
export interface ConfigUser {
svid: string
apikey?: string
}
export interface EntityGroup {
svid: string
}

View File

@ -0,0 +1,8 @@
// SpookVooper API - modules/types/Types.ts
// Written by Brendan Lane - https://brndnln.dev/
import { EntityUser } from './../interfaces/Interfaces'
export type CreditAmount = string | number
export type PaymentEntity = string | EntityUser
export type SVStockTicker = 'B' | 'IDE' | 'NEWS' | 'POT' | 'TECH' | 'TYCO' | 'VC' | 'VNB' | 'VU' | 'X'

31
tsconfig.json Normal file
View File

@ -0,0 +1,31 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ESNext",
"outDir": "dist",
"lib": [
"ESNext",
"ESNext.Array",
"ESNext.AsyncIterable",
"ESNext.Intl",
"ESNext.Symbol",
"DOM"
],
"sourceMap": true,
"inlineSourceMap": false,
"inlineSources": true,
"incremental": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictNullChecks": true
},
"include": [
"src/**/*",
"typings/**/*"
],
"exclude": [
"node_modules",
"dist/**/*"
]
}

0
typings/main.d.ts vendored Normal file
View File

24
typings/modules/User.d.ts vendored Normal file
View File

@ -0,0 +1,24 @@
import { CreditAmount, PaymentEntity, SVStockTicker } from './types/Types'
import { ConfigUser } from './interfaces/Interfaces'
declare class User {
// eslint-disable-next-line @typescript-eslint/prefer-readonly
private accountid
// eslint-disable-next-line @typescript-eslint/prefer-readonly
private authkey
constructor (config: ConfigUser)
getUser (): Promise<any>
getUsername (): Promise<any>
getBalance (): Promise<any>
hasDiscordRole (role: string): Promise<any>
getDiscordRoles (): Promise<any>
sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string): Promise<any>
getStockOffers (ticker: SVStockTicker): Promise<any>
buyStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any>
sellStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any>
cancelOffer (orderid: number): Promise<any>
get apikey (): string;
set apikey (apikey: string);
get svid (): string;
set svid (svid: string);
}
export default User

View File

@ -0,0 +1,22 @@
export interface EntityUser {
svid: string
getUser: () => Promise<any>
getUsername: () => Promise<any>
getBalance: () => Promise<any>
hasDiscordRole: () => Promise<any>
getDiscordRoles: () => Promise<any>
sendCredits: () => Promise<any>
getStockOffers: () => Promise<any>
buyStock: () => Promise<any>
sellStock: () => Promise<any>
setApiKey: () => void
setSvid: () => void
}
export interface ConfigUser {
svid: string
apikey?: string
}
export interface EntityGroup {
svid: string
}

4
typings/modules/types/Types.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
import { EntityUser } from './../interfaces/Interfaces'
export declare type CreditAmount = string | number
export declare type PaymentEntity = string | EntityUser
export declare type SVStockTicker = 'B' | 'IDE' | 'NEWS' | 'POT' | 'TECH' | 'TYCO' | 'VC' | 'VNB' | 'VU' | 'X'