Skip to content

Commit

Permalink
Discord Economy Super v1.7.1
Browse files Browse the repository at this point in the history
**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! 🔥**
- 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.
  • Loading branch information
shadowplay1 authored Dec 31, 2022
1 parent ef120b3 commit 6600f4e
Show file tree
Hide file tree
Showing 24 changed files with 1,247 additions and 206 deletions.
17 changes: 12 additions & 5 deletions typings/Economy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import UserManager from './managers/UserManager'
import GuildManager from './managers/GuildManager'

import SettingsManager from './managers/SettingsManager'
import CurrencyManager from './managers/CurrencyManager'


/**
Expand Down Expand Up @@ -97,20 +98,26 @@ declare class Economy<Ready extends boolean = boolean> extends Emitter {
*/
public readonly inventory: If<Ready, InventoryManager>

/**
* Currency manager.
* @type {?CurrencyManager}
*/
public readonly currencies: If<Ready, CurrencyManager>

/**
* History manager.
* @type {?HistoryManager}
*/
public readonly history: If<Ready, HistoryManager>

/**
* Balance.
* Balance manager.
* @type {?BalanceManager}
*/
public readonly balance: If<Ready, BalanceManager>

/**
* Bank balance.
* Bank balance manager.
* @type {?BankManager}
*/
public readonly bank: If<Ready, BankManager>
Expand All @@ -128,13 +135,13 @@ declare class Economy<Ready extends boolean = boolean> extends Emitter {
public readonly shop: If<Ready, ShopManager>

/**
* Balance.
* Rewards manager.
* @type {?RewardManager}
*/
public readonly rewards: If<Ready, RewardManager>

/**
* Cooldown.
* Cooldown manager.
* @type {?CooldownManager}
*/
public readonly cooldowns: If<Ready, CooldownManager>
Expand All @@ -152,7 +159,7 @@ declare class Economy<Ready extends boolean = boolean> extends Emitter {
public readonly guilds: If<Ready, GuildManager>

/**
* Settings.
* Settings manager.
* @type {?SettingsManager}
*/
public readonly settings: If<Ready, SettingsManager>
Expand Down
152 changes: 152 additions & 0 deletions typings/classes/Currency.d.ts
Original file line number Diff line number Diff line change
@@ -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<T extends object = any> {

/**
* @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<T>,
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<T>

/**
* Currency Manager.
* @type {CurrencyManager}
* @private
*/
private _currencies: CurrencyManager

/**
* Creates a currency object in guild database.
* @returns {Currency<T>} Currency object.
*/
public create(): Currency<T>

/**
* Deletes the currency object from guild database.
* @returns {Currency<T>} Currency object.
*/
public delete(): Currency<T>

/**
* Edits the currency object.
* @param {T} property Currency property to edit.
* @param {K} value Any value to set.
* @returns {Currency<T>} Edited currency object.
*/
public edit<
T extends keyof Omit<CurrencyObject, 'id' | 'balances'>,
K extends CurrencyPropertyType<T>
>(
property: T,
value: T extends 'custom' ? CustomItemData<K> : K,
): Currency<K>

/**
* Edits the currency's custom data object.
* @param {object} customObject Custom data object to set.
* @returns {Currency<T>} Currency object with its updated custom property.
*/
public setCustom(customObject: CurrencyObject<T>): Currency<T>

/**
* 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
6 changes: 6 additions & 0 deletions typings/classes/EconomyGuild.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions typings/classes/EconomyUser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion typings/classes/EmptyEconomyUser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 17 additions & 5 deletions typings/classes/HistoryItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ declare class HistoryItem<T extends object = any> {
/**
* 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<T>,
database: DatabaseManager
database: DatabaseManager
)


Expand Down Expand Up @@ -81,7 +81,7 @@ declare class HistoryItem<T extends object = any> {
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
Expand All @@ -104,6 +104,18 @@ declare class HistoryItem<T extends object = any> {
* @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
30 changes: 25 additions & 5 deletions typings/classes/InventoryItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -15,17 +17,17 @@ declare class InventoryItem<T extends object = any> {
/**
* 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<T>,
database: DatabaseManager
database: DatabaseManager
)


Expand Down Expand Up @@ -66,7 +68,7 @@ declare class InventoryItem<T extends object = any> {
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
Expand Down Expand Up @@ -112,6 +114,12 @@ declare class InventoryItem<T extends object = any> {
*/
public use(client?: any): string

/**
* Returns the stacked item in user inventory: it shows the quantity and total price of the item.
* @returns {StackedInventoryItemObject<T>} Stacked item object.
*/
public stack(): StackedInventoryItemObject<T>

/**
* Removes the item from user's inventory
* and adds its price to the user's balance.
Expand All @@ -121,6 +129,18 @@ declare class InventoryItem<T extends object = any> {
* @returns {SellingOperationInfo} The price the item(s) was/were sold for.
*/
public sell<T extends object = any>(quantity?: number): SellingOperationInfo<T>

/**
* 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
Loading

0 comments on commit 6600f4e

Please sign in to comment.