Browse Source

๐Ÿ’ป New sync

pull/15/head
Brendan Lane 10 months ago
parent
commit
02c8df4f53
  1. 14
      .eslintrc.json
  2. 162
      .gitignore
  3. 21
      .vscode/launch.json
  4. 4
      .vscode/settings.json
  5. 2010
      LICENSE
  6. 20
      main.js
  7. 53
      modules/District.js
  8. 104
      modules/ExchangeHub.js
  9. 72
      modules/Stock.js
  10. 65
      modules/TransactionHub.js
  11. 49
      modules/auth.js
  12. 113
      modules/group.js
  13. 65
      modules/old/auth.js
  14. 378
      modules/old/eco.js
  15. 137
      modules/old/group.js
  16. 42
      modules/old/premade.js
  17. 261
      modules/old/user.js
  18. 170
      modules/user.js
  19. 8780
      package-lock.json
  20. 32
      package.json
  21. 8
      src/main.ts
  22. 17
      src/modules/Group.ts
  23. 245
      src/modules/User.ts
  24. 25
      src/modules/interfaces/Interfaces.ts
  25. 8
      src/modules/types/Types.ts
  26. 31
      tsconfig.json
  27. 0
      typings/main.d.ts
  28. 24
      typings/modules/User.d.ts
  29. 22
      typings/modules/interfaces/Interfaces.d.ts
  30. 4
      typings/modules/types/Types.d.ts

14
.eslintrc.json

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

162
.gitignore

@ -1,6 +1,6 @@
# Created by https://www.toptal.com/developers/gitignore/api/node,python
# Edit at https://www.toptal.com/developers/gitignore?templates=node,python
# Created by https://www.toptal.com/developers/gitignore/api/node,yarn
# Edit at https://www.toptal.com/developers/gitignore?templates=node,yarn
### Node ###
# Logs
@ -46,9 +46,6 @@ build/Release
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
@ -76,9 +73,11 @@ typings/
# dotenv environment variables file
.env
.env.test
.env*.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
@ -111,138 +110,21 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
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
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
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
### yarn ###
# https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored
.yarn/*
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
# if you are NOT using Zero-installs, then:
# comment the following lines
!.yarn/cache
# and uncomment the following lines
# .pnp.*
# End of https://www.toptal.com/developers/gitignore/api/node,yarn
src/test.ts

21
.vscode/launch.json

@ -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

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

2010
LICENSE

File diff suppressed because it is too large

20
main.js

@ -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
}

53
modules/District.js

@ -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

104
modules/ExchangeHub.js

@ -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

72
modules/Stock.js

@ -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

65
modules/TransactionHub.js

@ -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

49
modules/auth.js

@ -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

113
modules/group.js

@ -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

65
modules/old/auth.js

@ -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
}

378
modules/old/eco.js

@ -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
}

137
modules/old/group.js

@ -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
}

42
modules/old/premade.js

@ -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
}

261
modules/old/user.js

@ -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 {