diff --git a/src/main.ts b/src/main.ts index 129c3b1..4194c4e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 } diff --git a/src/modules/ExchangeHub.ts b/src/modules/ExchangeHub.ts index c49f516..2003cc3 100644 --- a/src/modules/ExchangeHub.ts +++ b/src/modules/ExchangeHub.ts @@ -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 { + public async sendChatMessage (message: string, accountid: string, auth: EntityUser, ticker: string, tradeState: QueueType): Promise { 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') diff --git a/src/modules/Group.ts b/src/modules/Group.ts index 517dfd1..b80d057 100644 --- a/src/modules/Group.ts +++ b/src/modules/Group.ts @@ -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 { + public async buyStock (ticker: string, amount: number, price: CreditAmount, auth: EntityUser): Promise { 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 { + public async sellStock (ticker: string, amount: number, price: CreditAmount, auth: EntityUser): Promise { 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 { + public async cancelOffer (orderid: number, auth: EntityUser): Promise { return await new Promise((resolve, reject) => { axios.get(`${ecoURL}/cancelOrder`, { params: { diff --git a/src/modules/TransactionHub.ts b/src/modules/TransactionHub.ts index 1a96ed5..a960bbc 100644 --- a/src/modules/TransactionHub.ts +++ b/src/modules/TransactionHub.ts @@ -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) }) }) diff --git a/src/modules/User.ts b/src/modules/User.ts index 15656af..1ca6663 100644 --- a/src/modules/User.ts +++ b/src/modules/User.ts @@ -110,6 +110,22 @@ class User { }) } + public async getDaysSinceLastMove (): Promise { + 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 { if (typeof to === 'string') { return await new Promise((resolve, reject) => { diff --git a/src/modules/tools/SvidTool.ts b/src/modules/tools/SvidTool.ts new file mode 100644 index 0000000..366adf4 --- /dev/null +++ b/src/modules/tools/SvidTool.ts @@ -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 +} diff --git a/src/modules/types/Types.ts b/src/modules/types/Types.ts index bc866a0..90dde89 100644 --- a/src/modules/types/Types.ts +++ b/src/modules/types/Types.ts @@ -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, diff --git a/typings/main.d.ts b/typings/main.d.ts index 823c831..b6285b8 100644 --- a/typings/main.d.ts +++ b/typings/main.d.ts @@ -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 } diff --git a/typings/modules/ExchangeHub.d.ts b/typings/modules/ExchangeHub.d.ts index 376a028..cf8ef14 100644 --- a/typings/modules/ExchangeHub.d.ts +++ b/typings/modules/ExchangeHub.d.ts @@ -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 - onOfferCancel: Observable - onTradeEvent: Observable - onMessage: Observable - onMessageHistory: Observable + 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; + sendChatMessage (message: string, accountid: string, auth: EntityUser, ticker: string, tradeState: QueueType): Promise; getMessageHistory (): Promise; } export default ExchangeHub diff --git a/typings/modules/Group.d.ts b/typings/modules/Group.d.ts index 0e7d580..1c9235c 100644 --- a/typings/modules/Group.d.ts +++ b/typings/modules/Group.d.ts @@ -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; - sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: AuthEntity): Promise; + sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: EntityUser): Promise; doesGroupExist (): Promise; getGroupMembers (): Promise; hasGroupPermission (user: GroupMember, permission: string): Promise; get svid (): string; set svid (svid: string); + getStockOffers (ticker: string): Promise; + buyStock (ticker: string, amount: number, price: CreditAmount, auth: EntityUser): Promise; + sellStock (ticker: string, amount: number, price: CreditAmount, auth: EntityUser): Promise; + cancelOffer (orderid: number, auth: EntityUser): Promise; } export default Group diff --git a/typings/modules/TransactionHub.d.ts b/typings/modules/TransactionHub.d.ts index b6edb2d..fa18af5 100644 --- a/typings/modules/TransactionHub.d.ts +++ b/typings/modules/TransactionHub.d.ts @@ -4,6 +4,8 @@ declare class TransactionHub { private readonly val fromAccount: string toAccount: string + fromType: string + toType: string event: Observable constructor (); start (): Promise; diff --git a/typings/modules/User.d.ts b/typings/modules/User.d.ts index 5c1c48d..645bea2 100644 --- a/typings/modules/User.d.ts +++ b/typings/modules/User.d.ts @@ -9,6 +9,7 @@ declare class User { getBalance (): Promise; hasDiscordRole (role: string): Promise; getDiscordRoles (): Promise; + getDaysSinceLastMove (): Promise; sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string): Promise; getStockOffers (ticker: string): Promise; buyStock (ticker: string, amount: number, price: CreditAmount): Promise; diff --git a/typings/modules/tools/SvidTool.d.ts b/typings/modules/tools/SvidTool.d.ts new file mode 100644 index 0000000..49c7988 --- /dev/null +++ b/typings/modules/tools/SvidTool.d.ts @@ -0,0 +1,2 @@ +declare function svidType (svid: string): string +export { svidType } diff --git a/typings/modules/types/Types.d.ts b/typings/modules/types/Types.d.ts index 4225af9..7a9090a 100644 --- a/typings/modules/types/Types.d.ts +++ b/typings/modules/types/Types.d.ts @@ -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 }