From 6600f4ec130946294e45dda142e829c3d040d3a8 Mon Sep 17 00:00:00 2001 From: shadowplay1 Date: Sat, 31 Dec 2022 21:42:00 +0300 Subject: [PATCH] Discord Economy Super v1.7.1 **v1.7.1:** - Major bug fixes! - Major typings fixes! - Major JSDoc fixes! - Improved error handling and debugging. - Update checker fixes. - Fixed broken inventory cache issue on startup in MongoDB version! - **Custom currencies system! :fire:** - Added a new `customCurrencySet`, `customCurrencyAdd` and `customCurrencySubtract` events so the changes in any custom currencies could be tracked! - Added a new optional `currency` argument in **all item buying methods** that takes eaither *currency ID*, *name* or its *symbol* so the currency balance will be subtracted instead of core balance. Requires the `subtractOnBuy` option to be enabled. - Added a `stack()` method for **_inventory items_** that returns the **number of specific item (quantity)** and the **total price** of it in the inventory! - Added a new `clearDaily`, `clearWork` and `clearWeekly` methods in `CooldownItem` and `Cooldowns` classes to clear the specific cooldowns. - Added a `save()` method for `Shop-`, `Inventory-` and `History-` **items** that allows you to edit the item's object properties save the edited objext in database! - Added a `.toString()` method for some classes. - `Shop-`, `Inventory-` and `History-` **items'** `itemObject` property was changed to `rawObject` so it could make sense in the code - Now a warning will be displayed in console if using a dev version in both MongoDB and JSON versions (see the screenshot below). - Added the missing `buy()` method in `ShopItem` class. - Added the missing `clear()` method in `Items` class. - Fixed return values in database operations methods. --- typings/Economy.d.ts | 17 +- typings/classes/Currency.d.ts | 152 ++++++++ typings/classes/EconomyGuild.d.ts | 6 + typings/classes/EconomyUser.d.ts | 6 + typings/classes/EmptyEconomyUser.d.ts | 2 +- typings/classes/HistoryItem.d.ts | 22 +- typings/classes/InventoryItem.d.ts | 30 +- typings/classes/ShopItem.d.ts | 94 ++++- typings/classes/user/Balance.d.ts | 36 +- typings/classes/user/Items.d.ts | 149 ++++++- typings/interfaces/BalanceOperations.d.ts | 3 +- typings/interfaces/CurrencyFactory.d.ts | 42 ++ typings/interfaces/CurrencyObject.d.ts | 31 ++ typings/interfaces/EconomyConstructors.d.ts | 5 +- typings/interfaces/EconomyErrorCodes.d.ts | 5 + typings/interfaces/EconomyEvents.d.ts | 24 +- typings/interfaces/ItemData.d.ts | 2 +- typings/interfaces/ItemProperties.d.ts | 4 +- .../StackedInventoryItemObject.d.ts | 9 + typings/managers/BalanceManager.d.ts | 49 ++- typings/managers/BankManager.d.ts | 22 +- typings/managers/CurrencyManager.d.ts | 299 ++++++++++++++ typings/managers/InventoryManager.d.ts | 76 ++-- typings/managers/ShopManager.d.ts | 368 ++++++++++++------ 24 files changed, 1247 insertions(+), 206 deletions(-) create mode 100644 typings/classes/Currency.d.ts create mode 100644 typings/interfaces/CurrencyFactory.d.ts create mode 100644 typings/interfaces/CurrencyObject.d.ts create mode 100644 typings/interfaces/StackedInventoryItemObject.d.ts create mode 100644 typings/managers/CurrencyManager.d.ts diff --git a/typings/Economy.d.ts b/typings/Economy.d.ts index 35dfafaa..d45826f3 100644 --- a/typings/Economy.d.ts +++ b/typings/Economy.d.ts @@ -21,6 +21,7 @@ import UserManager from './managers/UserManager' import GuildManager from './managers/GuildManager' import SettingsManager from './managers/SettingsManager' +import CurrencyManager from './managers/CurrencyManager' /** @@ -97,6 +98,12 @@ declare class Economy extends Emitter { */ public readonly inventory: If + /** + * Currency manager. + * @type {?CurrencyManager} + */ + public readonly currencies: If + /** * History manager. * @type {?HistoryManager} @@ -104,13 +111,13 @@ declare class Economy extends Emitter { public readonly history: If /** - * Balance. + * Balance manager. * @type {?BalanceManager} */ public readonly balance: If /** - * Bank balance. + * Bank balance manager. * @type {?BankManager} */ public readonly bank: If @@ -128,13 +135,13 @@ declare class Economy extends Emitter { public readonly shop: If /** - * Balance. + * Rewards manager. * @type {?RewardManager} */ public readonly rewards: If /** - * Cooldown. + * Cooldown manager. * @type {?CooldownManager} */ public readonly cooldowns: If @@ -152,7 +159,7 @@ declare class Economy extends Emitter { public readonly guilds: If /** - * Settings. + * Settings manager. * @type {?SettingsManager} */ public readonly settings: If diff --git a/typings/classes/Currency.d.ts b/typings/classes/Currency.d.ts new file mode 100644 index 00000000..9d7927ae --- /dev/null +++ b/typings/classes/Currency.d.ts @@ -0,0 +1,152 @@ +import CurrencyManager from '../managers/CurrencyManager' + +import { CurrencyObject, CurrencyPropertyType } from '../interfaces/CurrencyObject' +import CustomItemData from '../interfaces/CustomItemData' + +import EconomyConfiguration from '../interfaces/EconomyConfiguration' +import DatabaseManager from '../managers/DatabaseManager' + +/** + * Currency class. + */ +declare class Currency { + + /** + * @param {number} currencyID Currency ID. + * @param {string} guildID Guild ID. + * @param {EconomyConfiguration} ecoOptions Economy configuration object. + * @param {CurrencyObject} currencyObject Currency object. + * @param {DatabaseManager} database Database manager. + */ + public constructor( + currencyID: number, + guildID: string, + ecoOptions: EconomyConfiguration, + currencyObject: CurrencyObject, + database: DatabaseManager + ) + + /** + * Guild ID. + * @type {string} + */ + public guildID: string + + /** + * Currency ID. + * @type {number} + */ + public id: number + + /** + * Currency name. + * @type {string} + */ + public name: string + + /** + * Currency symbol. + * @type {string} + */ + public symbol?: string + + /** + * Currency balances object. + * @type {object} + */ + public balances: object + + /** + * Custom currency data object. + * @type {object} + */ + public custom: CustomItemData + + /** + * Currency Manager. + * @type {CurrencyManager} + * @private + */ + private _currencies: CurrencyManager + + /** + * Creates a currency object in guild database. + * @returns {Currency} Currency object. + */ + public create(): Currency + + /** + * Deletes the currency object from guild database. + * @returns {Currency} Currency object. + */ + public delete(): Currency + + /** + * Edits the currency object. + * @param {T} property Currency property to edit. + * @param {K} value Any value to set. + * @returns {Currency} Edited currency object. + */ + public edit< + T extends keyof Omit, + K extends CurrencyPropertyType + >( + property: T, + value: T extends 'custom' ? CustomItemData : K, + ): Currency + + /** + * Edits the currency's custom data object. + * @param {object} customObject Custom data object to set. + * @returns {Currency} Currency object with its updated custom property. + */ + public setCustom(customObject: CurrencyObject): Currency + + /** + * Sets the currency for specified member. + * @param {number} amount Amount of money to set. + * @param {string} memberID Member ID. + * @param {string} [reason] The reason why the balance was set. + * @returns {number} Amount of money that was set. + */ + public setBalance(amount: number, memberID: string, reason: string): number + + /** + * Sets the currency for specified member. + * @param {string} memberID Member ID. + * @returns {number} Member's balance. + */ + public getBalance(memberID: string): number + + /** + * Adds the currency for specified member. + * @param {number} amount Amount of money to add. + * @param {string} memberID Member ID. + * @param {string} [reason] The reason why the balance was added. + * @returns {number} Amount of money that was added. + */ + public addBalance(amount: number, memberID: string, reason: string): number + + /** + * Subtracts the currency for specified member. + * @param {number} amount Amount of money to subtract. + * @param {string} memberID Member ID. + * @param {string} [reason] The reason why the balance was subtracted. + * @returns {number} Amount of money that was subtracted. + */ + public subtractBalance(amount: number, memberID: string, reason: string): number + + /** + * Saves the currency object in database. + * @returns {Currency} Currency instance. + */ + public save(): Currency + + /** + * Converts the currency object to string. + * @returns {string} String representation of currency object. + */ + public toString(): string +} + +export = Currency diff --git a/typings/classes/EconomyGuild.d.ts b/typings/classes/EconomyGuild.d.ts index 004f0fcf..eb017483 100644 --- a/typings/classes/EconomyGuild.d.ts +++ b/typings/classes/EconomyGuild.d.ts @@ -98,6 +98,12 @@ declare class EconomyGuild { * @returns {boolean} If created successfully: true; else: false. */ public create(): boolean + + /** + * Converts the economy guild to string. + * @returns {string} String representation of economy guild. + */ + public toString(): string } export = EconomyGuild diff --git a/typings/classes/EconomyUser.d.ts b/typings/classes/EconomyUser.d.ts index 632804ee..d666c404 100644 --- a/typings/classes/EconomyUser.d.ts +++ b/typings/classes/EconomyUser.d.ts @@ -144,6 +144,12 @@ declare class EconomyUser { * @returns {boolean} If created successfully: true, else: false. */ public create(): boolean + + /** + * Converts the economy user to string. + * @returns {string} String representation of economy user. + */ + public toString(): string } export = EconomyUser diff --git a/typings/classes/EmptyEconomyUser.d.ts b/typings/classes/EmptyEconomyUser.d.ts index 6e91b773..dc3e4904 100644 --- a/typings/classes/EmptyEconomyUser.d.ts +++ b/typings/classes/EmptyEconomyUser.d.ts @@ -16,7 +16,7 @@ declare class EmptyEconomyUser extends EconomyUser { * @param {EconomyConfiguration} options Economy configuration. * @param {DatabaseManager} database Database Manager. */ - constructor( + public constructor( userID: string, guildID: string, options: EconomyConfiguration, diff --git a/typings/classes/HistoryItem.d.ts b/typings/classes/HistoryItem.d.ts index f2bc7309..fbf23b81 100644 --- a/typings/classes/HistoryItem.d.ts +++ b/typings/classes/HistoryItem.d.ts @@ -14,17 +14,17 @@ declare class HistoryItem { /** * History item class. * @param {string} guildID Guild ID. - * @param {string} memberID Member ID. + * @param {string} memberID Member ID. * @param {EconomyConfiguration} ecoOptions Economy configuration. * @param {HistoryData} itemObject User purchases history item object. - * @param {DatabaseManager} database Database Manager. + * @param {DatabaseManager} database Database Manager. */ public constructor( guildID: string, - memberID: string, + memberID: string, ecoOptions: EconomyConfiguration, itemObject: HistoryData, - database: DatabaseManager + database: DatabaseManager ) @@ -81,7 +81,7 @@ declare class HistoryItem { public date: string /** - * ID of Discord Role that will be given to Wuser on item use. + * ID of Discord Role that will be given to the user on item use. * @type {string} */ public role: string @@ -104,6 +104,18 @@ declare class HistoryItem { * @returns {boolean} If removed: true, else: false. */ public remove(): boolean + + /** + * Saves the history item object in database. + * @returns {HistoryItem} History item instance. + */ + public save(): HistoryItem + + /** + * Converts the history item to string. + * @returns {string} String representation of history item. + */ + public toString(): string } export = HistoryItem diff --git a/typings/classes/InventoryItem.d.ts b/typings/classes/InventoryItem.d.ts index 1e03b660..0eb2cfb5 100644 --- a/typings/classes/InventoryItem.d.ts +++ b/typings/classes/InventoryItem.d.ts @@ -6,6 +6,8 @@ import InventoryData from '../interfaces/InventoryData' import CustomItemData from '../interfaces/CustomItemData' import SellingOperationInfo from '../interfaces/SellingOperationInfo' +import StackedInventoryItemObject from '../interfaces/StackedInventoryItemObject' + /** * Inventory item class. @@ -15,17 +17,17 @@ declare class InventoryItem { /** * Inventory item class. * @param {string} guildID Guild ID. - * @param {string} memberID Member ID. + * @param {string} memberID Member ID. * @param {EconomyConfiguration} ecoOptions Economy configuration. * @param {InventoryData} itemObject User inventory object. - * @param {DatabaseManager} database Database Manager. + * @param {DatabaseManager} database Database Manager. */ public constructor( guildID: string, - memberID: string, + memberID: string, ecoOptions: EconomyConfiguration, itemObject: InventoryData, - database: DatabaseManager + database: DatabaseManager ) @@ -66,7 +68,7 @@ declare class InventoryItem { public description: string /** - * ID of Discord Role that will be given to Wuser on item use. + * ID of Discord Role that will be given to the user on item use. * @type {string} */ public role: string @@ -112,6 +114,12 @@ declare class InventoryItem { */ public use(client?: any): string + /** + * Returns the stacked item in user inventory: it shows the quantity and total price of the item. + * @returns {StackedInventoryItemObject} Stacked item object. + */ + public stack(): StackedInventoryItemObject + /** * Removes the item from user's inventory * and adds its price to the user's balance. @@ -121,6 +129,18 @@ declare class InventoryItem { * @returns {SellingOperationInfo} The price the item(s) was/were sold for. */ public sell(quantity?: number): SellingOperationInfo + + /** + * Saves the inventory item object in database. + * @returns {InventoryItem} Inventory item instance. + */ + public save(): InventoryItem + + /** + * Converts the inventory item to string. + * @returns {string} String representation of inventory item. + */ + public toString(): string } export = InventoryItem diff --git a/typings/classes/ShopItem.d.ts b/typings/classes/ShopItem.d.ts index 49efcb51..07d677c8 100644 --- a/typings/classes/ShopItem.d.ts +++ b/typings/classes/ShopItem.d.ts @@ -1,10 +1,11 @@ import ItemData from '../interfaces/ItemData' import CustomItemData from '../interfaces/CustomItemData' +import ShopOperationInfo from '../interfaces/ShopOperationInfo' import { ItemProperties, ItemPropertyType } from '../interfaces/ItemProperties' import DatabaseManager from '../managers/DatabaseManager' -import UserManager from '../managers/UserManager' +import CacheManager from '../managers/CacheManager' /** @@ -17,11 +18,13 @@ declare class ShopItem { * @param {string} guildID Guild ID. * @param {ItemData} itemObject Shop item object. * @param {DatabaseManager} database Database Manager. + * @param {CacheManager} cache Cache manager. */ public constructor( guildID: string, itemObject: ItemData, - database: DatabaseManager + database: DatabaseManager, + cache: CacheManager ) /** @@ -61,7 +64,7 @@ declare class ShopItem { public description: string /** - * ID of Discord Role that will be given to Wuser on item use. + * ID of Discord Role that will be given to the user on item use. * @type {string} */ public role: string @@ -84,7 +87,6 @@ declare class ShopItem { */ public custom: CustomItemData - /** * Checks for is the specified user has enough money to buy the item. * @param {string} userID User ID. @@ -115,6 +117,78 @@ declare class ShopItem { K extends ItemPropertyType >(itemProperty: T, value: T extends 'custom' ? CustomItemData : K): boolean + /** + * Buys the item from the shop. + * @param {string} memberID Member ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string | number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + memberID: string, + quantity?: number, + currency?: string | number, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * @param {string} memberID Member ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + memberID: string, + quantity?: number, + currency?: string, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * @param {string} memberID Member ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + memberID: string, + quantity?: number, + currency?: number, + reason?: string + ): ShopOperationInfo + /** * Sets a custom object for the item. * @param {object} custom Custom item data object. @@ -135,6 +209,18 @@ declare class ShopItem { * @returns {boolean} If removed: true, else: false. */ public remove(): boolean + + /** + * Saves the shop item object in database. + * @returns {ShopItem} Shop item instance. + */ + public save(): ShopItem + + /** + * Converts the shop item to string. + * @returns {string} String representation of shop item. + */ + public toString(): string } export = ShopItem \ No newline at end of file diff --git a/typings/classes/user/Balance.d.ts b/typings/classes/user/Balance.d.ts index 45b96aa3..ca0b697c 100644 --- a/typings/classes/user/Balance.d.ts +++ b/typings/classes/user/Balance.d.ts @@ -1,6 +1,9 @@ import Emitter from '../util/Emitter' + import EconomyConfiguration from '../../interfaces/EconomyConfiguration' +import CurrencyFactory from '../../interfaces/CurrencyFactory' + import TransferingOptions from '../../interfaces/TransferingOptions' import TransferingResult from '../../interfaces/TransferingResult' @@ -15,6 +18,27 @@ declare class Balance extends Emitter { */ public constructor(memberID: string, guildID: string, ecoOptions: EconomyConfiguration) + /** + * Returns a factory with `get`, `set`, `add` and `subtract` methods to work with custom currencies. + * @param {string} currencyID Currency ID, its name or its symbol. + * @returns {CurrencyFactory} Factory object. + */ + public currency(currencyID: string): CurrencyFactory + + /** + * Returns a factory with `get`, `set`, `add` and `subtract` methods to work with custom currencies. + * @param {number} currencyID Currency ID, its name or its symbol. + * @returns {CurrencyFactory} Factory object. + */ + public currency(currencyID: number): CurrencyFactory + + /** + * Returns a factory with `get`, `set`, `add` and `subtract` methods to work with custom currencies. + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @returns {CurrencyFactory} Factory object. + */ + public currency(currencyID: string | number): CurrencyFactory + /** * Sets the money amount on user's balance. * @param {number} amount Money amount @@ -47,12 +71,6 @@ declare class Balance extends Emitter { */ public get(): number - /** - * Fetches the user's balance. - * @returns {number} User's balance. - */ - public fetch(): number - /** * Deposits the specified amount of money. * @param {number} amount Money amount. @@ -61,6 +79,12 @@ declare class Balance extends Emitter { */ public deposit(amount: number, reason?: string): number + /** + * Fetches the user's balance. + * @returns {number} User's balance. + */ + public fetch(): number + /** * Transfers the money to a specified user. * @param {TransferingOptions} options Transfering options. diff --git a/typings/classes/user/Items.d.ts b/typings/classes/user/Items.d.ts index 1fca2d1e..29d75181 100644 --- a/typings/classes/user/Items.d.ts +++ b/typings/classes/user/Items.d.ts @@ -2,7 +2,9 @@ import EconomyConfiguration from '../../interfaces/EconomyConfiguration' import ShopOperationInfo from '../../interfaces/ShopOperationInfo' import SellingOperationInfo from '../../interfaces/SellingOperationInfo' +import StackedInventoryItemObject from '../../interfaces/StackedInventoryItemObject' +import DatabaseManager from '../../managers/DatabaseManager' import InventoryItem from '../InventoryItem' @@ -14,13 +16,90 @@ declare class Items { * @param {string} guildID Guild ID. * @param {EconomyConfiguration} ecoOptions Economy configuratuion. */ - public constructor(memberID: string, guildID: string, ecoOptions: EconomyConfiguration) + public constructor(memberID: string, guildID: string, ecoOptions: EconomyConfiguration, database: DatabaseManager) + + /** + * Buys the item from the shop. + * @param {string | number} itemID Item ID or name. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string | number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + itemID: string | number, + quantity?: number, + currency?: string | number, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * @param {string} itemID Item ID or name. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + itemID: string, + quantity?: number, + currency?: string, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * @param {number} itemID Item ID or name. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + itemID: number, + quantity?: number, + currency?: number, + reason?: string + ): ShopOperationInfo /** * Buys the item from the shop. * @param {string} itemID Item ID or name. * @param {number} [quantity=1] Quantity of items to buy. Default: 1. * + * @param {number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * * @param {string} [reason='received the item from the shop'] * The reason why the money was subtracted. Default: 'received the item from the shop'. * @@ -28,17 +107,44 @@ declare class Items { */ public buy< T extends object = any - >(itemID: string | number, quantity?: number, reason?: string): ShopOperationInfo + >( + itemID: string, + quantity?: number, + currency?: number, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * @param {number} itemID Item ID or name. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + itemID: number, + quantity?: number, + currency?: string, + reason?: string + ): ShopOperationInfo /** * Adds the item from the shop to user's inventory. * @param {string} itemID Item ID or name. * @param {number} [quantity=1] Quantity of items to add. Default: 1. - * @returns {ShopOperationInfo} If added successfully: true, else: false. + * @returns {ShopOperationInfo} Operation information object. */ - public add< - T extends object = any - >(itemID: string | number, quantity?: number): ShopOperationInfo + public add(itemID: string | number, quantity?: number): ShopOperationInfo /** * Gets the specified item from the user's inventory. @@ -49,11 +155,18 @@ declare class Items { /** * Uses the item from user's inventory. - * @param {number | string} itemID Item ID or name. + * @param {string | number} itemID Item ID or name. * @param {Client} [client] Discord Client [Specify if the role will be given in a Discord server]. * @returns {string} Item message. */ - public use(itemID: number | string, client?: any): string + public use(itemID: string | number, client?: any): string + + /** + * Returns the stacked item in user inventory: it shows the quantity and total price of the item. + * @param {string | number} itemID Item ID or name. + * @returns {StackedInventoryItemObject} Stacked item object. + */ + public stack(itemID: string | number): StackedInventoryItemObject /** * Fetches the user's inventory. @@ -61,6 +174,19 @@ declare class Items { */ public all(): InventoryItem[] + /** + * Clears the inventory. + * @returns {boolean} If cleared successfully: true, else: false. + */ + public clear(): boolean + + /** + * Removes the item from user's inventory. + * @param {string} itemID Item ID or name. + * @returns {boolean} If removed successfully: true, else: false. + */ + public remove(itemID: string | number): boolean + /** * Sells the item from the user's inventory. * @param {string} itemID Item ID or name. @@ -75,13 +201,6 @@ declare class Items { T extends object = any >(itemID: string | number, quantity?: number, reason?: string): SellingOperationInfo - /** - * Removes the item from user's inventory. - * @param {string} itemID Item ID or name. - * @returns {boolean} If removed successfully: true, else: false. - */ - public remove(itemID: string | number): boolean - /** * Removes the item from user's inventory. * diff --git a/typings/interfaces/BalanceOperations.d.ts b/typings/interfaces/BalanceOperations.d.ts index f1c57d56..b3f49b3f 100644 --- a/typings/interfaces/BalanceOperations.d.ts +++ b/typings/interfaces/BalanceOperations.d.ts @@ -1,5 +1,6 @@ type BalanceOperations = 'balanceAdd' | 'balanceSubtract' | 'balanceSet' | - 'bankAdd' | 'bankSubtract' | 'bankSet' + 'bankAdd' | 'bankSubtract' | 'bankSet' | + 'customCurrencyAdd' | 'customCurrencySubtract' | 'customCurrencySet' export = BalanceOperations \ No newline at end of file diff --git a/typings/interfaces/CurrencyFactory.d.ts b/typings/interfaces/CurrencyFactory.d.ts new file mode 100644 index 00000000..4c868e03 --- /dev/null +++ b/typings/interfaces/CurrencyFactory.d.ts @@ -0,0 +1,42 @@ +import Currency from '../classes/Currency' + +declare interface CurrencyFactory { + + /** + * Gets the currency balance. + * @returns {number} Currency balance. + */ + get(): number + + /** + * Gets the currency object. + * @returns {Currency} Currency object. + */ + getCurrency(): Currency + + /** + * Sets the currency balance. + * @param {number} amount Amount of money to set. + * @param {string} [reason] The reason why the money was set. + * @returns {number} Updated currency balance. + */ + set(amount: number, reason?: string): number + + /** + * Adds the money on the currency balance. + * @param {number} amount Amount of money to add. + * @param {string} [reason] The reason why the money was added. + * @returns {number} Updated currency balance. + */ + add(amount: number, reason?: string): number + + /** + * Subtracts the money from the currency balance. + * @param {number} amount Amount of money to subtract. + * @param {string} [reason] The reason why the money was subtracted. + * @returns {number} Updated currency balance. + */ + subtract(amount: number, reason?: string): number +} + +export = CurrencyFactory \ No newline at end of file diff --git a/typings/interfaces/CurrencyObject.d.ts b/typings/interfaces/CurrencyObject.d.ts new file mode 100644 index 00000000..8d336481 --- /dev/null +++ b/typings/interfaces/CurrencyObject.d.ts @@ -0,0 +1,31 @@ +import CustomItemData from './CustomItemData' + +export interface CurrencyObject { + + /** + * Currency ID. + */ + id: number + + /** + * Currency name. + */ + name: string + + /** + * Currency symbol. + */ + symbol: string + + /** + * Currency balances object. + */ + balances: object + + /** + * Custom currency data object. + */ + custom: CustomItemData +} + +export type CurrencyPropertyType = T extends 'custom' ? object : CurrencyObject[T] \ No newline at end of file diff --git a/typings/interfaces/EconomyConstructors.d.ts b/typings/interfaces/EconomyConstructors.d.ts index a9c31fb4..ba7c8879 100644 --- a/typings/interfaces/EconomyConstructors.d.ts +++ b/typings/interfaces/EconomyConstructors.d.ts @@ -5,7 +5,10 @@ import ShopItem from '../classes/ShopItem' import InventoryItem from '../classes/InventoryItem' import HistoryItem from '../classes/HistoryItem' +import Currency from '../classes/Currency' + + type EconomyConstructors = - EconomyGuild | EconomyUser | ShopItem | InventoryItem | HistoryItem + EconomyGuild | EconomyUser | ShopItem | Currency | InventoryItem | HistoryItem export = EconomyConstructors \ No newline at end of file diff --git a/typings/interfaces/EconomyErrorCodes.d.ts b/typings/interfaces/EconomyErrorCodes.d.ts index df031854..04aef99f 100644 --- a/typings/interfaces/EconomyErrorCodes.d.ts +++ b/typings/interfaces/EconomyErrorCodes.d.ts @@ -3,10 +3,15 @@ declare type EconomyErrorCodes = 'UNKNOWN_ERROR' | 'PARAMETER_NOT_SPECIFIED' | 'OLD_NODE_VERSION' | + 'ITEM_PROPERTY_INVALID' | + 'INVALID_INPUT' | 'NO_DISCORD_CLIENT' | 'ROLE_NOT_FOUND' | 'PURCHASES_HISTORY_DISABLED' | 'SETTINGS_KEY_INVALID' | + 'READONLY_PROPERTY' | + 'INVALID_PROPERTY' | + 'CURRENCY_NOT_FOUND' | 'INVALID_ERROR_CODE' | 'MODULE_NOT_READY' | 'STORAGE_FILE_ERROR' diff --git a/typings/interfaces/EconomyEvents.d.ts b/typings/interfaces/EconomyEvents.d.ts index 3ac55b43..8f91f84b 100644 --- a/typings/interfaces/EconomyEvents.d.ts +++ b/typings/interfaces/EconomyEvents.d.ts @@ -6,11 +6,12 @@ import EditedItemData from './EditedItemData' import ItemUseData from './ItemUseData' import ItemBuyData from './ItemBuyData' +import Currency from '../classes/Currency' import Economy from '../Economy' /** - * All events list. + * Economy events. */ declare interface EconomyEvents { @@ -44,6 +45,27 @@ declare interface EconomyEvents { */ bankSubtract: BalanceData<'balanceSubtract'> + /** + * Emits when someone's custom currency was set + */ + customCurrencySet: BalanceData<'customCurrencySet'> & { + currency: Currency + } + + /** + * Emits when someone's custom currency was added. + */ + customCurrencyAdd: BalanceData<'customCurrencyAdd'> & { + currency: Currency + } + + /** + * Emits when someone's custom currency was subtracted. + */ + customCurrencySubtract: BalanceData<'customCurrencySubtract'> & { + currency: Currency + } + /** * Emits when someone's added an item in the shop. */ diff --git a/typings/interfaces/ItemData.d.ts b/typings/interfaces/ItemData.d.ts index 04a8fa7a..1c89526b 100644 --- a/typings/interfaces/ItemData.d.ts +++ b/typings/interfaces/ItemData.d.ts @@ -36,7 +36,7 @@ declare interface ItemData { maxAmount: number /** - * Role ID from your Discord server. + * Role **ID** from your Discord server. */ role: string diff --git a/typings/interfaces/ItemProperties.d.ts b/typings/interfaces/ItemProperties.d.ts index e7eab326..aa182c7b 100644 --- a/typings/interfaces/ItemProperties.d.ts +++ b/typings/interfaces/ItemProperties.d.ts @@ -1,3 +1,5 @@ +import CustomItemData from '../interfaces/CustomItemData' + export interface ItemProperties { id: number name: string @@ -7,7 +9,7 @@ export interface ItemProperties { maxAmount: number role: string date: string - custom: T + custom: CustomItemData } export type ItemPropertyType = T extends 'custom' ? object : ItemProperties[T] \ No newline at end of file diff --git a/typings/interfaces/StackedInventoryItemObject.d.ts b/typings/interfaces/StackedInventoryItemObject.d.ts new file mode 100644 index 00000000..2b39b60f --- /dev/null +++ b/typings/interfaces/StackedInventoryItemObject.d.ts @@ -0,0 +1,9 @@ +import InventoryItem from '../classes/InventoryItem' + +interface StackedInventoryItemObject { + quantity: number + totalPrice: number + item: InventoryItem +} + +export = StackedInventoryItemObject \ No newline at end of file diff --git a/typings/managers/BalanceManager.d.ts b/typings/managers/BalanceManager.d.ts index a562ae90..c15c93d7 100644 --- a/typings/managers/BalanceManager.d.ts +++ b/typings/managers/BalanceManager.d.ts @@ -14,10 +14,37 @@ import TransferingResult from '../interfaces/TransferingResult' declare class BalanceManager extends Emitter { public constructor(options: EconomyConfiguration) + /** + * Returns a factory with `get`, `set`, `add` and `subtract` methods to work with custom currencies. + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @returns {CurrencyFactory} Factory object. + */ + public currency(currencyID: string, memberID: string, guildID: string): CurrencyFactory + + /** + * Returns a factory with `get`, `set`, `add` and `subtract` methods to work with custom currencies. + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @returns {CurrencyFactory} Factory object. + */ + public currency(currencyID: number, memberID: string, guildID: string): CurrencyFactory + + /** + * Returns a factory with `get`, `set`, `add` and `subtract` methods to work with custom currencies. + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @returns {CurrencyFactory} Factory object. + */ + public currency(currencyID: string | number, memberID: string, guildID: string): CurrencyFactory + /** * Fetches the user's balance. - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @returns User's balance */ public fetch(memberID: string, guildID: string): number @@ -26,8 +53,8 @@ declare class BalanceManager extends Emitter { * Gets the user's balance. * * This method is an alias for the `BalanceManager.fetch()` method. - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @returns User's balance */ public get(memberID: string, guildID: string): number @@ -35,8 +62,8 @@ declare class BalanceManager extends Emitter { /** * Sets the money amount on user's balance. * @param {number} amount Amount of money that you want to set - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @param {string} [reason] The reason why you set the money * @returns Money amount */ @@ -45,8 +72,8 @@ declare class BalanceManager extends Emitter { /** * Adds the money amount on user's balance. * @param {number} amount Amount of money that you want to add - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @param {string} [reason] The reason why you add the money * @returns Money amount */ @@ -55,8 +82,8 @@ declare class BalanceManager extends Emitter { /** * Subtracts the money amount from user's balance. * @param {number} amount Amount of money that you want to subtract - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @param {string} [reason] The reason why you subtract the money * @returns Money amount */ @@ -74,7 +101,7 @@ declare class BalanceManager extends Emitter { /** * Gets a balance leaderboard for specified server - * @param {string} guildID Guild ID + * @param {string} guildID Guild ID. * @returns Sorted leaderboard array */ public leaderboard(guildID: string): LeaderboardData[] diff --git a/typings/managers/BankManager.d.ts b/typings/managers/BankManager.d.ts index 915109aa..423497a2 100644 --- a/typings/managers/BankManager.d.ts +++ b/typings/managers/BankManager.d.ts @@ -12,8 +12,8 @@ declare class BankManager extends Emitter { /** * Fetches the user's bank balance. - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @returns User's bank balance */ public fetch(memberID: string, guildID: string): number @@ -22,8 +22,8 @@ declare class BankManager extends Emitter { * Gets the user's bank balance. * * This method is an alias for the `BankManager.fetch()` method. - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @returns User's bank balance */ public get(memberID: string, guildID: string): number @@ -31,8 +31,8 @@ declare class BankManager extends Emitter { /** * Sets the money amount on user's bank balance. * @param {number} amount Amount of money that you want to set - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @param {string} [reason] The reason why you set the money * @returns Money amount */ @@ -41,8 +41,8 @@ declare class BankManager extends Emitter { /** * Adds the money amount on user's bank balance. * @param {number} amount Amount of money that you want to add - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @param {string} [reason] The reason why you add the money * @returns Money amount */ @@ -51,8 +51,8 @@ declare class BankManager extends Emitter { /** * Subtracts the money amount from user's bank balance. * @param {number} amount Amount of money that you want to subtract - * @param {string} memberID Member ID - * @param {string} guildID Guild ID + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. * @param {string} [reason] The reason why you subtract the money * @returns Money amount */ @@ -70,7 +70,7 @@ declare class BankManager extends Emitter { /** * Gets a bank balance leaderboard for your server - * @param {string} guildID Guild ID + * @param {string} guildID Guild ID. * @returns Sorted leaderboard array */ public leaderboard(guildID: string): LeaderboardData[] diff --git a/typings/managers/CurrencyManager.d.ts b/typings/managers/CurrencyManager.d.ts new file mode 100644 index 00000000..2f13cc9f --- /dev/null +++ b/typings/managers/CurrencyManager.d.ts @@ -0,0 +1,299 @@ +import Emitter from '../classes/util/Emitter' + +import { CurrencyObject, CurrencyPropertyType } from '../interfaces/CurrencyObject' +import CustomItemData from '../interfaces/CustomItemData' + +import EconomyConfiguration from '../interfaces/EconomyConfiguration' + +/** +* Currency manager methods class. +* @extends {Emitter} +*/ +declare class CurrencyManager extends Emitter { + + /** + * Currency Manager. + * @param {EconomyConfiguration} options Economy configuration. + */ + public constructor(options: EconomyConfiguration) + + /** + * Finds the info for the specified currency. + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Currency object. + */ + public find(currencyID: string, guildID: string): CurrencyObject + + /** + * Finds the info for the specified currency. + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Currency object. + */ + public find(currencyID: number, guildID: string): CurrencyObject + + /** + * Finds the info for the specified currency. + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Currency object. + */ + public find(currencyID: string | number, guildID: string): CurrencyObject + + /** + * Finds the info for the specified currency. + * + * This method is an alias for `CurrencyManager.find()` method. + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Currency object. + */ + public get(currencyID: string, guildID: string): CurrencyObject + + /** + * Finds the info for the specified currency. + * + * This method is an alias for `CurrencyManager.find()` method. + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Currency object. + */ + public get(currencyID: number, guildID: string): CurrencyObject + + /** + * Finds the info for the specified currency. + * + * This method is an alias for `CurrencyManager.find()` method. + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Currency object. + */ + public get(currencyID: string | number, guildID: string): CurrencyObject + + /** + * Edits the currency object. + * + * Type parameters: + * + * - T: Currency property string. + * - K: Type for specified property in T. + * + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {T} property Currency property to edit. + * @param {K} value Any value to set. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Edited currency object. + */ + public edit< + T extends keyof Omit, + K extends CurrencyPropertyType + >( + currencyID: string, + property: T, + value: T extends 'custom' ? CustomItemData : K, + guildID: string + ): CurrencyObject + + /** + * Edits the currency object. + * + * Type parameters: + * + * - T: Currency property string. + * - K: Type for specified property in T. + * + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {T} property Currency property to edit. + * @param {K} value Any value to set. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Edited currency object. + */ + public edit< + T extends keyof Omit, + K extends CurrencyPropertyType + >( + currencyID: number, + property: T, + value: T extends 'custom' ? CustomItemData : K, + guildID: string + ): CurrencyObject + + /** + * Edits the currency object. + * + * Type parameters: + * + * - T: Item property string. + * - K: Type for specified property in T. + * + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @param {T} property Currency property to edit. + * @param {K} value Any value to set. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Edited currency object. + */ + public edit< + T extends keyof Omit, + K extends CurrencyPropertyType + >( + currencyID: string | number, + property: T, + value: T extends 'custom' ? CustomItemData : K, + guildID: string + ): CurrencyObject + + /** + * Edits the currency's custom data object. + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @param {object} customObject Custom data object to set. + * @returns {CurrencyObject} Currency object with its updated custom property. + */ + public setCustom(currencyID: string, guildID: string, customObject: T): CurrencyObject + + /** + * Edits the currency's custom data object. + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @param {object} customObject Custom data object to set. + * @returns {CurrencyObject} Currency object with its updated custom property. + */ + public setCustom(currencyID: number, guildID: string, customObject: T): CurrencyObject + + /** + * Edits the currency's custom data object. + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @param {object} customObject Custom data object to set. + * @returns {CurrencyObject} Currency object with its updated custom property. + */ + public setCustom(currencyID: string | number, guildID: string, customObject: T): CurrencyObject + + /** + * Gets the specified currency balance for specified member. + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {string} memberID Guild ID. + * @param {string} guildID Guild ID. + * @returns {number} Currency balance for specified member. + */ + public getBalance(currencyID: string, memberID: string, guildID: string): number + + /** + * Gets the specified currency balance for specified member. + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {string} memberID Guild ID. + * @param {string} guildID Guild ID. + * @returns {number} Currency balance for specified member. + */ + public getBalance(currencyID: number, memberID: string, guildID: string): number + + /** + * Gets the specified currency balance for specified member. + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @param {string} memberID Guild ID. + * @param {string} guildID Guild ID. + * @returns {number} Currency balance for specified member. + */ + public getBalance(currencyID: string | number, memberID: string, guildID: string): number + + /** + * Sets the currecy balance for speciied member. + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {number} amount Amount of money to set. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {string} [reason] The reason why the money was set. + * @param {boolean} [emitSet=false] If true, `customCurrencySet` event will be emitted on set. Default: false. + * @returns {number} Amount of money that was set. + */ + public setBalance(currencyID: string, amount: number, memberID: string, guildID: string, reason?: string, emitSet?: boolean): number + + /** + * Sets the currecy balance for speciied member. + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {number} amount Amount of money to set. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {string} [reason] The reason why the money was set. + * @param {boolean} [emitSet=false] If true, `customCurrencySet` event will be emitted on set. Default: false. + * @returns {number} Amount of money that was set. + */ + public setBalance(currencyID: number, amount: number, memberID: string, guildID: string, reason?: string, emitSet?: boolean): number + + /** + * Sets the currecy balance for speciied member. + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @param {number} amount Amount of money to set. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {string} [reason] The reason why the money was set. + * @param {boolean} [emitSet=false] If true, `customCurrencySet` event will be emitted on set. Default: false. + * @returns {number} Amount of money that was set. + */ + public setBalance(currencyID: string | number, amount: number, memberID: string, guildID: string, reason?: string, emitSet?: boolean): number + + /** + * Adds the currecy balance for speciied member. + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {number} amount Amount of money to add. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {string} [reason] The reason why the money was added. + * @returns {number} Amount of money that was add. + */ + public addBalance(currencyID: string, amount: number, memberID: string, guildID: string, reason?: string): number + + /** + * Subtracts the currecy balance for speciied member. + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {number} amount Amount of money to subtract. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {string} [reason] The reason why the money was subtracted. + * @returns {number} Amount of money that was subtract. + */ + public subtractBalance(currencyID: number, amount: number, memberID: string, guildID: string, reason?: string): number + + /** + * Deletes the currency object and all its balances in a specified guild. + * @param {string} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {boolean} If deleted: true, else - false. + */ + public delete(currencyID: string, guildID: string): boolean + + /** + * Deletes the currency object and all its balances in a specified guild. + * @param {number} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {boolean} If deleted: true, else - false. + */ + public delete(currencyID: number, guildID: string): boolean + + /** + * Deletes the currency object and all its balances in a specified guild. + * @param {string | number} currencyID Currency ID, its name or its symbol. + * @param {string} guildID Guild ID. + * @returns {boolean} If deleted: true, else - false. + */ + public delete(currencyID: string | number, guildID: string): boolean + + /** + * Creates a currency object in database. + * @param {string} name Currency name to set. + * @param {string} symbol Currency symbol to set. + * @param {string} guildID Guild ID. + * @returns {CurrencyObject} Currency object. + */ + public create(name: string, symbol: string, guildID: string): CurrencyObject + + /** + * Clears the currencies array for specified guild. + * @param {string} guildID Guild ID. + * @returns {boolean} If cleared: true, else: false. + */ + public clear(guildID: string): boolean +} + +export = CurrencyManager diff --git a/typings/managers/InventoryManager.d.ts b/typings/managers/InventoryManager.d.ts index 4e8c3f69..9633b63c 100644 --- a/typings/managers/InventoryManager.d.ts +++ b/typings/managers/InventoryManager.d.ts @@ -1,11 +1,14 @@ import DatabaseManager from './DatabaseManager' +import CacheManager from './CacheManager' import Emitter from '../classes/util/Emitter' +import InventoryItem from '../classes/InventoryItem' import EconomyConfiguration from '../interfaces/EconomyConfiguration' -import InventoryItem from '../classes/InventoryItem' import ShopOperationInfo from '../interfaces/ShopOperationInfo' +import SellingOperationInfo from '../interfaces/SellingOperationInfo' +import StackedInventoryItemObject from '../interfaces/StackedInventoryItemObject' /** @@ -13,7 +16,7 @@ import ShopOperationInfo from '../interfaces/ShopOperationInfo' * @extends {Emitter} */ declare class InventoryManager extends Emitter { - public constructor(options: EconomyConfiguration, database: DatabaseManager) + public constructor(options: EconomyConfiguration, database: DatabaseManager, cache: CacheManager) /** * Uses the item from the user's inventory. @@ -21,38 +24,38 @@ declare class InventoryManager extends Emitter { * @param {string} memberID Member ID * @param {string} guildID Guild ID * @param {any} client The Discord Client [Optional] - * @returns {string} Item message + * @returns {Promise} Item message */ - public useItem(itemID: string | number, memberID: string, guildID: string, client?: any): string + public useItem(itemID: string | number, memberID: string, guildID: string, client?: any): Promise /** * Uses the item from user's inventory. * * This method is an alias for the `InventoryManager.useItem()` method. - * @param {number | string} itemID Item ID or name. + * @param {string | number} itemID Item ID or name. * @param {string} memberID Member ID. * @param {string} guildID Guild ID. * @param {Client} [client] The Discord Client. [Optional] - * @returns {string} Item message or null if item not found. + * @returns {Promise} Item message or null if item not found. */ - public use(itemID: string | number, memberID: string, guildID: string, client?: any): string + public use(itemID: string | number, memberID: string, guildID: string, client?: any): Promise /** * Clears the user's inventory. * @param {string} memberID Member ID * @param {string} guildID Guild ID - * @returns {string} If cleared: true, else: false + * @returns {Promise} If cleared: true, else: false */ - public clear(memberID: string, guildID: string): string + public clear(memberID: string, guildID: string): Promise /** * Gets the item in the inventory. * @param {string} itemID Item ID or name. * @param {string} memberID Member ID. * @param {string} guildID Guild ID. - * @returns {InventoryItem} If item not found: null; else: item info object. + * @returns {Promise} If item not found: null; else: item info object. */ - public getItem(itemID: string | number, memberID: string, guildID: string): InventoryItem + public getItem(itemID: string | number, memberID: string, guildID: string): Promise> /** * Gets the item in the inventory. @@ -61,9 +64,9 @@ declare class InventoryManager extends Emitter { * @param {string} itemID Item ID or name. * @param {string} memberID Member ID. * @param {string} guildID Guild ID. - * @returns {InventoryItem} If item not found: null; else: item info object. + * @returns {Promise} If item not found: null; else: item info object. */ - public findItem(itemID: string | number, memberID: string, guildID: string): InventoryItem + public findItem(itemID: string | number, memberID: string, guildID: string): Promise> /** * Adds the item from the shop to user's inventory. @@ -71,7 +74,7 @@ declare class InventoryManager extends Emitter { * @param {string} memberID Member ID. * @param {string} guildID Guild ID. * @param {number} [quantity=1] Quantity of items to add. Default: 1. - * @returns {ShopOperationInfo} Operation info object. + * @returns {Promise} Operation info object. */ public addItem< T extends object = any @@ -80,7 +83,18 @@ declare class InventoryManager extends Emitter { memberID: string, guildID: string, quantity?: number - ): ShopOperationInfo + ): Promise> + + /** + * Returns the stacked item in user inventory: it shows the quantity and total price of the item. + * @param {string | number} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID.s + * @returns {Promise>} Stacked item object. + */ + public stack< + T extends object = any + >(itemID: string | number, memberID: string, guildID: string): Promise> /** * Shows all items in user's inventory. @@ -88,7 +102,7 @@ declare class InventoryManager extends Emitter { * @param {string} guildID Guild ID * @returns The user's inventory array. */ - public fetch(memberID: string, guildID: string): InventoryItem[] + public fetch(memberID: string, guildID: string): Promise[]> /** * Shows all items in user's inventory. @@ -98,7 +112,7 @@ declare class InventoryManager extends Emitter { * @param {string} guildID Guild ID * @returns The user's inventory array. */ - public get(memberID: string, guildID: string): InventoryItem[] + public get(memberID: string, guildID: string): Promise[]> /** * Removes the item from user's inventory @@ -108,9 +122,17 @@ declare class InventoryManager extends Emitter { * @param {string} memberID Member ID. * @param {string} guildID Guild ID. * @param {number} [quantity=1] Quantity of items to sell. - * @returns {number} The price the item(s) was/were sold for. + * @returns {Promise} Selling operation info. */ - public sellItem(itemID: string | number, memberID: string, guildID: string, quantity?: number, reason?: string): number + public sellItem< + T extends object = any + >( + itemID: string | number, + memberID: string, + guildID: string, + quantity?: number, + reason?: string + ): Promise> /** * Removes the item from user's inventory @@ -123,9 +145,17 @@ declare class InventoryManager extends Emitter { * @param {string} guildID Guild ID. * @param {number} [quantity=1] Quantity of items to sell. * @param {string} [reason='sold the item from the inventory'] The reason why the item was sold. - * @returns {number} The price the item(s) was/were sold for. + * @returns {Promise} Selling operation info. */ - public sell(itemID: string | number, memberID: string, guildID: string, quantity?: number, reason?: string): number + public sell< + T extends object = any + >( + itemID: string | number, + memberID: string, + guildID: string, + quantity?: number, + reason?: string + ): Promise> /** * Removes the item from user's inventory. @@ -133,9 +163,9 @@ declare class InventoryManager extends Emitter { * @param {string} memberID Member ID. * @param {string} guildID Guild ID. * @param {number} [quantity=1] Quantity of items to sell. - * @returns {string} If removed successfully: true, else: false. + * @returns {Promise} If removed successfully: true, else: false. */ - public removeItem(itemID: string | number, memberID: string, guildID: string, quantity?: number): string + public removeItem(itemID: string | number, memberID: string, guildID: string, quantity?: number): Promise } export = InventoryManager \ No newline at end of file diff --git a/typings/managers/ShopManager.d.ts b/typings/managers/ShopManager.d.ts index 923e8fcf..d7dd8946 100644 --- a/typings/managers/ShopManager.d.ts +++ b/typings/managers/ShopManager.d.ts @@ -1,15 +1,17 @@ +import DatabaseManager from './DatabaseManager' +import CacheManager from './CacheManager' + import Emitter from '../classes/util/Emitter' import ShopItem from '../classes/ShopItem' import AddItemOptions from '../interfaces/AddItemOptions' import ShopOperationInfo from '../interfaces/ShopOperationInfo' + import { ItemProperties, ItemPropertyType } from '../interfaces/ItemProperties' import CustomItemData from '../interfaces/CustomItemData' import EconomyConfiguration from '../interfaces/EconomyConfiguration' -import InventoryData from '../interfaces/InventoryData' -import HistoryData from '../interfaces/HistoryData' /** @@ -17,7 +19,7 @@ import HistoryData from '../interfaces/HistoryData' * @extends {Emitter} */ declare class ShopManager extends Emitter { - public constructor(options: EconomyConfiguration) + public constructor(options: EconomyConfiguration, database: DatabaseManager, cache: CacheManager) /** * Creates an item in shop. @@ -27,7 +29,7 @@ declare class ShopManager extends Emitter { * - T: Set an object for 'custom' item property. * @param {AddItemOptions} options Configuration with item info. * @param {string} guildID Guild ID. - * @returns Item info. + * @returns {ShopItem} Item info. */ public addItem(guildID: string, options: AddItemOptions): ShopItem @@ -52,22 +54,25 @@ declare class ShopManager extends Emitter { * * - T: Item property string. * - K: Type for specified property in T. + * * @param {string} itemID Item ID or name. * @param {string} guildID Guild ID. * - * @param {"description" | "price" | "name" | "message" | "maxAmount" | "role" | 'custom'} itemProperty + * @param {T} itemProperty * This argument means what thing in item you want to edit (item property). * Available item properties are 'description', 'price', 'name', 'message', 'amount', 'role', 'custom'. * - * @param {T} value Any value to set. + * @param {K} value Any value to set. * @returns {boolean} If edited successfully: true, else: false. */ public edit< T extends keyof Omit, K extends ItemPropertyType >( - itemID: string | number, guildID: string, - itemProperty: T, value: T extends 'custom' ? CustomItemData : K + itemID: string | number, + guildID: string, + itemProperty: T, + value: T extends 'custom' ? CustomItemData : K ): boolean /** @@ -83,11 +88,11 @@ declare class ShopManager extends Emitter { * @param {string} itemID Item ID or name. * @param {string} guildID Guild ID. * - * @param {"description" | "price" | "name" | "message" | "maxAmount" | "role" | 'custom'} itemProperty + * @param {T} itemProperty * This argument means what thing in item you want to edit (item property). * Available item properties are 'description', 'price', 'name', 'message', 'amount', 'role', 'custom'. * - * @param {T} value Any value to set. + * @param {K} value Any value to set. * @returns {boolean} If edited successfully: true, else: false. */ public editItem< @@ -106,7 +111,7 @@ declare class ShopManager extends Emitter { * @returns {boolean} If set successfully: true, else: false. */ public setCustom< - T extends object = never + T extends object = any >(itemID: string | number, guildID: string, custom: CustomItemData): boolean /** @@ -127,36 +132,78 @@ declare class ShopManager extends Emitter { * This method is an alias for the `ShopManager.getItem()` method. * @param {string} itemID Item ID or name. * @param {string} guildID Guild ID - * @returns If item not found: null; else: item data array + * @returns {ShopItem} If item not found: null; else: item data array */ public findItem(itemID: string | number, guildID: string): ShopItem /** - * Uses the item from the user's inventory. + * Buys the item from the shop. + * @param {string | number} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. * - * [!!!] This method is deprecated. - * If you want to get all the bugfixes and - * use the newest inventory features, please - * switch to the usage of the new InventoryManager. + * @param {string | number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. * - * [!!!] No help will be provided for inventory - * related methods in ShopManager. - * @param {string} itemID Item ID or name - * @param {string} memberID Member ID - * @param {string} guildID Guild ID - * @param {any} client The Discord Client [Optional] - * @returns {string} Item message - * @deprecated + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + itemID: string | number, + memberID: string, + guildID: string, + quantity?: number, + currency?: string | number, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * @param {string} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. */ - public useItem(itemID: string | number, memberID: string, guildID: string, client?: any): string + public buy< + T extends object = any + >( + itemID: string, + memberID: string, + guildID: string, + quantity?: number, + currency?: string, + reason?: string + ): ShopOperationInfo /** * Buys the item from the shop. - * @param {number | string} itemID Item ID or name. + * @param {number} itemID Item ID or name. * @param {string} memberID Member ID. * @param {string} guildID Guild ID. * @param {number} [quantity=1] Quantity of items to buy. Default: 1. * + * @param {number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * * @param {string} [reason='received the item from the shop'] * The reason why the money was subtracted. Default: 'received the item from the shop'. * @@ -165,10 +212,67 @@ declare class ShopManager extends Emitter { public buy< T extends object = any >( - itemID: string | number, + itemID: number, memberID: string, guildID: string, quantity?: number, + currency?: number, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * @param {string} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + itemID: string, + memberID: string, + guildID: string, + quantity?: number, + currency?: number, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * @param {number} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buy< + T extends object = any + >( + itemID: number, + memberID: string, + guildID: string, + quantity?: number, + currency?: string, reason?: string ): ShopOperationInfo @@ -176,7 +280,7 @@ declare class ShopManager extends Emitter { * Buys the item from the shop. * * This method is an alias for the `ShopManager.buy()` method. - * @param {number | string} itemID Item ID or name. + * @param {string | number} itemID Item ID or name. * @param {string} memberID Member ID. * @param {string} guildID Guild ID. * @param {number} [quantity=1] Quantity of items to buy. Default: 1. @@ -197,45 +301,131 @@ declare class ShopManager extends Emitter { ): ShopOperationInfo /** - * Clears the shop. - * @param {string} guildID Guild ID - * @returns {boolean} If cleared: true, else: false + * Buys the item from the shop. + * + * This method is an alias for the `ShopManager.buy()` method. + * @param {string} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. */ - public clear(guildID: string): boolean + public buyItem< + T extends object = any + >( + itemID: string, + memberID: string, + guildID: string, + quantity?: number, + currency?: string, + reason?: string + ): ShopOperationInfo /** - * Clears the user's inventory. + * Buys the item from the shop. * - * [!!!] This method is deprecated. - * If you want to get all the bugfixes and - * use the newest inventory features, please - * switch to the usage of the new InventoryManager. + * This method is an alias for the `ShopManager.buy()` method. + * @param {number} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. * - * [!!!] No help will be provided for inventory - * related methods in ShopManager. - * @param {string} memberID Member ID - * @param {string} guildID Guild ID - * @returns {boolean} If cleared: true, else: false. - * @deprecated + * @param {number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. */ - public clearInventory(memberID: string, guildID: string): boolean + public buyItem< + T extends object = any + >( + itemID: number, + memberID: string, + guildID: string, + quantity?: number, + currency?: number, + reason?: string + ): ShopOperationInfo /** - * Clears the user's purchases history. - * - * [!!!] This method is deprecated. - * If you want to get all the bugfixes and - * use the newest history features, please - * switch to the usage of the new HistoryManager. - * - * [!!!] No help will be provided for history - * related methods in ShopManager. - * @param {string} memberID Member ID. - * @param {string} guildID Guild ID. - * @returns {boolean} If cleared: true, else: false. - * @deprecated - */ - public clearHistory(memberID: string, guildID: string): boolean + * Buys the item from the shop. + * + * This method is an alias for the `ShopManager.buy()` method. + * @param {string} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {number} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buyItem< + T extends object = any + >( + itemID: string, + memberID: string, + guildID: string, + quantity?: number, + currency?: number, + reason?: string + ): ShopOperationInfo + + /** + * Buys the item from the shop. + * + * This method is an alias for the `ShopManager.buy()` method. + * @param {number} itemID Item ID or name. + * @param {string} memberID Member ID. + * @param {string} guildID Guild ID. + * @param {number} [quantity=1] Quantity of items to buy. Default: 1. + * + * @param {string} [currency=null] + * The currency to subtract the money from. + * Can be omitted by specifying 'null' or ignoring this parameter. + * Requires the `subtractOnBuy` option to be enabled. Default: null. + * + * @param {string} [reason='received the item from the shop'] + * The reason why the money was subtracted. Default: 'received the item from the shop'. + * + * @returns {ShopOperationInfo} Operation information object. + */ + public buyItem< + T extends object = any + >( + itemID: number, + memberID: string, + guildID: string, + quantity?: number, + currency?: string, + reason?: string + ): ShopOperationInfo + + /** + * Clears the shop. + * @param {string} guildID Guild ID + * @returns {boolean} If cleared: true, else: false + */ + public clear(guildID: string): boolean /** * Shows all items in the shop. @@ -244,7 +434,7 @@ declare class ShopManager extends Emitter { * * - T: Set an object for 'custom' item property. * @param {string} guildID Guild ID - * @returns The shop array. + * @returns {ShopItem[]} The shop array. */ public fetch(guildID: string): ShopItem[] @@ -268,63 +458,11 @@ declare class ShopManager extends Emitter { /** * Gets the item in the shop. - * @param {number | string} itemID Item ID or name. - * @param {string} guildID Guild ID. - * @returns {ShopItem} If item not found: null; else: item info object. - */ - public getItem(itemID: string | number, guildID: string): ShopItem - - /** - * Gets the item in the inventory. - * - * [!!!] This method is deprecated. - * If you want to get all the bugfixes and - * use the newest inventory features, please - * switch to the usage of the new InventoryManager. - * - * [!!!] No help will be provided for inventory - * related methods in ShopManager. * @param {string} itemID Item ID or name. - * @param {string} memberID Member ID. - * @param {string} guildID Guild ID. - * @returns {InventoryData} If item not found: null; else: item info object. - * @deprecated - */ - public searchInventoryItem(itemID: string | number, memberID: string, guildID: string): InventoryData - - /** - * Shows all items in user's inventory - * - * [!!!] This method is deprecated. - * If you want to get all the bugfixes and - * use the newest inventory features, please - * switch to the usage of the new InventoryManager. - * - * [!!!] No help will be provided for inventory - * related methods in ShopManager. - * @param {string} memberID Member ID * @param {string} guildID Guild ID - * @returns The user's inventory array. - * @deprecated + * @returns {ShopItem} If item not found: null; else: item info object */ - public inventory(memberID: string, guildID: string): InventoryData[] - - /** - * Shows the user's purchase history. - * - * [!!!] This method is deprecated. - * If you want to get all the bugfixes and - * use the newest history features, please - * switch to the usage of the new HistoryManager. - * - * [!!!] No help will be provided for history - * related methods in ShopManager. - * @param {string} memberID Member ID - * @param {string} guildID Guild ID - * @returns {HistoryData[]} User's purchase history. - * @deprecated - */ - public history(memberID: string, guildID: string): HistoryData[] + public getItem(itemID: string | number, guildID: string): ShopItem } export = ShopManager \ No newline at end of file