🩹 Fix stupid

This should fix all the dumb mistakes and allow for easy access to development things.
This commit is contained in:
Brendan Lane 2020-12-24 03:03:28 -05:00
parent 3e3250491b
commit 195603e353
14 changed files with 100 additions and 22 deletions

View File

@ -1,3 +1,5 @@
/* eslint-disable import/first */
// SpookVooper API - src/main.ts
// Written by Brendan Lane - https://brndnln.dev/
@ -11,6 +13,13 @@ import TransactionHub from './modules/TransactionHub'
import * as DepersonalizedUser from './modules/depersonalized/user'
import * as DepersonalizedGroup from './modules/depersonalized/group'
import * as SvidTool from './modules/tools/SvidTool'
const Tools = { SvidTool }
import * as Interfaces from './modules/interfaces/Interfaces'
import * as Types from './modules/types/Types'
const Dev = { Interfaces, Types }
export {
User,
Group,
@ -19,5 +28,7 @@ export {
Stock,
TransactionHub,
DepersonalizedUser,
DepersonalizedGroup
DepersonalizedGroup,
Tools,
Dev
}

View File

@ -5,7 +5,8 @@
import { Observable } from 'rxjs'
import { HubConnectionBuilder, LogLevel } from '@microsoft/signalr'
import { AuthEntity, QueueType } from './types/Types'
import { QueueType } from './types/Types'
import { EntityUser } from './interfaces/Interfaces'
const URI = 'https://spookvooper.com/ExchangeHub'
const retryTime = 5
@ -76,7 +77,7 @@ class ExchangeHub {
await this.start()
}
public async sendChatMessage (message: string, accountid: string, auth: AuthEntity, ticker: string, tradeState: QueueType): Promise<any> {
public async sendChatMessage (message: string, accountid: string, auth: EntityUser, ticker: string, tradeState: QueueType): Promise<any> {
return await new Promise((resolve, reject) => {
if (message === undefined || accountid === undefined || auth === undefined || ticker === undefined || tradeState === undefined) {
throw new Error('All parameters need to be set')

View File

@ -3,7 +3,7 @@
import axios from 'axios'
import { EntityUser } from './interfaces/Interfaces'
import { AuthEntity, CreditAmount, GroupMember, PaymentEntity } from './types/Types'
import { CreditAmount, GroupMember, PaymentEntity } from './types/Types'
const groupURL = 'https://api.spookvooper.com/group'
const ecoURL = 'https://api.spookvooper.com/eco'
@ -176,7 +176,7 @@ class Group {
})
}
public async buyStock (ticker: string, amount: number, price: CreditAmount, auth: AuthEntity): Promise<any> {
public async buyStock (ticker: string, amount: number, price: CreditAmount, auth: EntityUser): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/submitStockBuy`, {
params: {
@ -196,7 +196,7 @@ class Group {
})
}
public async sellStock (ticker: string, amount: number, price: CreditAmount, auth: AuthEntity): Promise<any> {
public async sellStock (ticker: string, amount: number, price: CreditAmount, auth: EntityUser): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/submitStockSell`, {
params: {
@ -216,7 +216,7 @@ class Group {
})
}
public async cancelOffer (orderid: number, auth: AuthEntity): Promise<any> {
public async cancelOffer (orderid: number, auth: EntityUser): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${ecoURL}/cancelOrder`, {
params: {

View File

@ -32,6 +32,21 @@ class TransactionHub {
this.fromAccount = this.val.FromAccount
this.toAccount = this.val.ToAccount
if (this.fromAccount.startsWith('u-')) {
this.fromType = 'user'
} else if (this.fromAccount.startsWith('g-')) {
this.fromType = 'group'
} else {
this.fromType = 'Error'
}
if (this.toAccount.startsWith('u-')) {
this.toType = 'user'
} else if (this.toAccount.startsWith('g-')) {
this.toType = 'group'
} else {
this.toType = 'Error'
}
observer.next(this.val)
})
})

View File

@ -110,6 +110,22 @@ class User {
})
}
public async getDaysSinceLastMove (): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${userURL}/getDaysSinceLastMove`, {
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) => {

View File

@ -0,0 +1,18 @@
// SpookVooper API - modules/tools/SvidTool.ts
// Written by Brendan Lane - https://brndnln.dev/
function svidType (svid: string): string {
if (svid.startsWith('u-')) {
return 'user'
} else if (svid.startsWith('g-')) {
return 'group'
} else if (svid.startsWith('i-')) {
return 'item'
} else {
throw new Error('This is either a legacy svid or it is not an svid! If it is a legacy SVID, it is no longer supported.')
}
}
export {
svidType
}

View File

@ -5,7 +5,7 @@ import { EntityUser, ConfigAuth } from './../interfaces/Interfaces'
type CreditAmount = string | number
type PaymentEntity = string | EntityUser
type AuthEntity = EntityUser
type SvidType = 'user' | 'group' | 'item'
type GroupMember = string | EntityUser
type AuthConfig = ConfigAuth
type District = 'Voopmont' | 'New Yam' | 'San Vooperisco' | 'Medievala' | 'Landing Cove' | 'New Spudland' | 'Vooperia City' | 'Corgi' | 'Old Yam' | 'New Vooperis' | 'The Netherlands' | 'Queensland' | 'Servers Past' | 'Los Vooperis' | 'Old King Peninsula'
@ -16,7 +16,7 @@ type QueueType = 'BUY' | 'SELL'
export {
CreditAmount,
PaymentEntity,
AuthEntity,
SvidType,
GroupMember,
AuthConfig,
District,

9
typings/main.d.ts vendored
View File

@ -6,4 +6,11 @@ import Stock from './modules/Stock'
import TransactionHub from './modules/TransactionHub'
import * as DepersonalizedUser from './modules/depersonalized/user'
import * as DepersonalizedGroup from './modules/depersonalized/group'
export { User, Group, Auth, District, Stock, TransactionHub, DepersonalizedUser, DepersonalizedGroup }
declare const Tools: {
SvidTool: any
}
declare const Dev: {
Interfaces: any
Types: any
}
export { User, Group, Auth, District, Stock, TransactionHub, DepersonalizedUser, DepersonalizedGroup, Tools, Dev }

View File

@ -1,16 +1,16 @@
import { Observable } from 'rxjs'
import { AuthEntity, QueueType } from './types/Types'
import { QueueType } from './types/Types'
import { EntityUser } from './interfaces/Interfaces'
declare class ExchangeHub {
private readonly connection
onOffer: Observable<unknown>
onOfferCancel: Observable<unknown>
onTradeEvent: Observable<unknown>
onMessage: Observable<unknown>
onMessageHistory: Observable<unknown>
onOffer: any
onOfferCancel: any
onTradeEvent: any
onMessage: any
onMessageHistory: any
constructor ();
private readonly start
private readonly onClosed
sendChatMessage (message: string, accountid: string, auth: AuthEntity, ticker: string, tradeState: QueueType): Promise<any>;
sendChatMessage (message: string, accountid: string, auth: EntityUser, ticker: string, tradeState: QueueType): Promise<any>;
getMessageHistory (): Promise<any>;
}
export default ExchangeHub

View File

@ -1,13 +1,18 @@
import { AuthEntity, CreditAmount, GroupMember, PaymentEntity } from './types/Types'
import { EntityUser } from './interfaces/Interfaces'
import { CreditAmount, GroupMember, PaymentEntity } from './types/Types'
declare class Group {
private readonly accountid
constructor (svid: string);
getGroup (): Promise<any>;
sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: AuthEntity): Promise<any>;
sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: EntityUser): Promise<any>;
doesGroupExist (): Promise<any>;
getGroupMembers (): Promise<any>;
hasGroupPermission (user: GroupMember, permission: string): Promise<any>;
get svid (): string;
set svid (svid: string);
getStockOffers (ticker: string): Promise<any>;
buyStock (ticker: string, amount: number, price: CreditAmount, auth: EntityUser): Promise<any>;
sellStock (ticker: string, amount: number, price: CreditAmount, auth: EntityUser): Promise<any>;
cancelOffer (orderid: number, auth: EntityUser): Promise<any>;
}
export default Group

View File

@ -4,6 +4,8 @@ declare class TransactionHub {
private readonly val
fromAccount: string
toAccount: string
fromType: string
toType: string
event: Observable<unknown>
constructor ();
start (): Promise<void>;

View File

@ -9,6 +9,7 @@ declare class User {
getBalance (): Promise<any>;
hasDiscordRole (role: string): Promise<any>;
getDiscordRoles (): Promise<any>;
getDaysSinceLastMove (): Promise<any>;
sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string): Promise<any>;
getStockOffers (ticker: string): Promise<any>;
buyStock (ticker: string, amount: number, price: CreditAmount): Promise<any>;

2
typings/modules/tools/SvidTool.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
declare function svidType (svid: string): string
export { svidType }

View File

@ -1,11 +1,11 @@
import { EntityUser, ConfigAuth } from './../interfaces/Interfaces'
declare type CreditAmount = string | number
declare type PaymentEntity = string | EntityUser
declare type AuthEntity = EntityUser
declare type SvidType = 'user' | 'group' | 'item'
declare type GroupMember = string | EntityUser
declare type AuthConfig = ConfigAuth
declare type District = 'Voopmont' | 'New Yam' | 'San Vooperisco' | 'Medievala' | 'Landing Cove' | 'New Spudland' | 'Vooperia City' | 'Corgi' | 'Old Yam' | 'New Vooperis' | 'The Netherlands' | 'Queensland' | 'Servers Past' | 'Los Vooperis' | 'Old King Peninsula'
declare type DistrictWealthType = 'ALL' | 'USER' | 'GROUP'
declare type SenatorDistrict = District | 'ALL'
declare type QueueType = 'BUY' | 'SELL'
export { CreditAmount, PaymentEntity, AuthEntity, GroupMember, AuthConfig, District, DistrictWealthType, SenatorDistrict, QueueType }
export { CreditAmount, PaymentEntity, SvidType, GroupMember, AuthConfig, District, DistrictWealthType, SenatorDistrict, QueueType }