diff --git a/examples/json/example.js b/examples/json/example.js index f69dfdc7..e9784377 100644 --- a/examples/json/example.js +++ b/examples/json/example.js @@ -274,7 +274,7 @@ client.on('messageCreate', async message => { if (command == prefix + 'daily') { const dailyResult = user.rewards.getDaily() - if (dailyResult.cooldown) { + if (!dailyResult.claimed) { const cooldownTime = dailyResult.cooldown.time const cooldownTimeString = @@ -303,7 +303,7 @@ client.on('messageCreate', async message => { if (command == prefix + 'work') { const workResult = user.rewards.getWork() - if (workResult.cooldown) { + if (!workResult.claimed) { const cooldownTime = workResult.cooldown.time const cooldownTimeString = @@ -332,7 +332,7 @@ client.on('messageCreate', async message => { if (command == prefix + 'weekly') { const weeklyResult = user.rewards.getWeekly() - if (weeklyResult.cooldown) { + if (!weeklyResult.claimed) { const cooldownTime = weeklyResult.cooldown.time const cooldownTimeString = diff --git a/examples/json/example.ts b/examples/json/example.ts index c55246e7..a8c045d5 100644 --- a/examples/json/example.ts +++ b/examples/json/example.ts @@ -275,7 +275,7 @@ client.on('messageCreate', async msg => { if (command == prefix + 'daily') { const dailyResult = user.rewards.getDaily() - if (dailyResult.cooldown) { + if (!dailyResult.claimed) { const cooldownTime = dailyResult.cooldown.time const cooldownTimeString = @@ -304,7 +304,7 @@ client.on('messageCreate', async msg => { if (command == prefix + 'work') { const workResult = user.rewards.getWork() - if (workResult.cooldown) { + if (!workResult.claimed) { const cooldownTime = workResult.cooldown.time const cooldownTimeString = @@ -333,7 +333,7 @@ client.on('messageCreate', async msg => { if (command == prefix + 'weekly') { const weeklyResult = user.rewards.getWeekly() - if (weeklyResult.cooldown) { + if (!weeklyResult.claimed) { const cooldownTime = weeklyResult.cooldown.time const cooldownTimeString = diff --git a/examples/mongodb/example.js b/examples/mongodb/example.js index 282d42e6..19b549dc 100644 --- a/examples/mongodb/example.js +++ b/examples/mongodb/example.js @@ -317,7 +317,7 @@ client.on('messageCreate', async message => { if (command == prefix + 'daily') { const dailyResult = await user.rewards.getDaily() - if (dailyResult.cooldown) { + if (!dailyResult.claimed) { const cooldownTime = dailyResult.cooldown.time const cooldownTimeString = @@ -346,7 +346,7 @@ client.on('messageCreate', async message => { if (command == prefix + 'work') { const workResult = await user.rewards.getWork() - if (workResult.cooldown) { + if (!workResult.claimed) { const cooldownTime = workResult.cooldown.time const cooldownTimeString = @@ -375,7 +375,7 @@ client.on('messageCreate', async message => { if (command == prefix + 'weekly') { const weeklyResult = await user.rewards.getWeekly() - if (weeklyResult.cooldown) { + if (!weeklyResult.claimed) { const cooldownTime = weeklyResult.cooldown.time const cooldownTimeString = diff --git a/examples/mongodb/example.ts b/examples/mongodb/example.ts index 82bed53a..51396d10 100644 --- a/examples/mongodb/example.ts +++ b/examples/mongodb/example.ts @@ -318,7 +318,7 @@ client.on('messageCreate', async msg => { if (command == prefix + 'daily') { const dailyResult = await user.rewards.getDaily() - if (dailyResult.cooldown) { + if (!dailyResult.claimed) { const cooldownTime = dailyResult.cooldown.time const cooldownTimeString = @@ -347,7 +347,7 @@ client.on('messageCreate', async msg => { if (command == prefix + 'work') { const workResult = await user.rewards.getWork() - if (workResult.cooldown) { + if (!workResult.claimed) { const cooldownTime = workResult.cooldown.time const cooldownTimeString = @@ -376,7 +376,7 @@ client.on('messageCreate', async msg => { if (command == prefix + 'weekly') { const weeklyResult = await user.rewards.getWeekly() - if (weeklyResult.cooldown) { + if (!weeklyResult.claimed) { const cooldownTime = weeklyResult.cooldown.time const cooldownTimeString = diff --git a/mongodb/package.json b/mongodb/package.json index 3b9f0eb8..603b2548 100644 --- a/mongodb/package.json +++ b/mongodb/package.json @@ -10,6 +10,7 @@ "precommit": "bash ./.husky/scripts/commit-to-public.sh", "docs:deploy": "bash ./.husky/scripts/deploy-docs.sh", "deploy": "bash ./.husky/scripts/commit-and-deploy.sh", + "upload": "bash ./publish.sh && bash ./.husky/scripts/deploy-docs.sh", "lint": "eslint ./", "lint:fix": "eslint ./ --fix" }, diff --git a/mongodb/src/classes/HistoryItem.js b/mongodb/src/classes/HistoryItem.js index 7968b602..47217c9a 100644 --- a/mongodb/src/classes/HistoryItem.js +++ b/mongodb/src/classes/HistoryItem.js @@ -1,7 +1,3 @@ -const EconomyError = require('../classes/util/EconomyError') -const errors = require('../structures/errors') - - /** * History item class. */ @@ -113,19 +109,6 @@ class HistoryItem { */ async remove() { const id = this.id - - if (typeof id !== 'number' && typeof id !== 'string') { - throw new EconomyError(errors.invalidTypes.id + typeof id, 'INVALID_TYPE') - } - - if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') - } - - if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') - } - const history = (await this._database.fetch(`${this.guildID}.${this.memberID}.history`)) || [] const historyItem = history.find( diff --git a/mongodb/src/classes/ShopItem.js b/mongodb/src/classes/ShopItem.js index 9b39adeb..0d08a5ad 100644 --- a/mongodb/src/classes/ShopItem.js +++ b/mongodb/src/classes/ShopItem.js @@ -259,7 +259,7 @@ class ShopItem extends Emitter { */ async buy(memberID, quantity = 1, currency = null, reason = 'received the item from the shop') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } const balance = this.cache.balance.get({ diff --git a/mongodb/src/classes/user/History.js b/mongodb/src/classes/user/History.js index 62b7f352..0f5e30bf 100644 --- a/mongodb/src/classes/user/History.js +++ b/mongodb/src/classes/user/History.js @@ -84,7 +84,7 @@ class History extends BaseManager { if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return false @@ -115,7 +115,7 @@ class History extends BaseManager { */ async remove(id) { if (typeof id !== 'number' && typeof id !== 'string') { - throw new EconomyError(errors.invalidTypes.id + typeof id, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('id', 'string or number', id), 'INVALID_TYPE') } const history = (await this.fetch(this.memberID, this.guildID)) || [] diff --git a/mongodb/src/classes/user/Inventory.js b/mongodb/src/classes/user/Inventory.js index 0817aa87..6fd36461 100644 --- a/mongodb/src/classes/user/Inventory.js +++ b/mongodb/src/classes/user/Inventory.js @@ -90,7 +90,7 @@ class Inventory extends BaseManager { const item = inventory[itemIndex] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return null @@ -183,7 +183,7 @@ class Inventory extends BaseManager { const inventoryItems = inventory.filter(invItem => invItem.name == item.name) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return false @@ -222,7 +222,7 @@ class Inventory extends BaseManager { const itemIndex = inventory.findIndex(invItem => invItem.id == item?.id) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return false diff --git a/mongodb/src/classes/user/Rewards.js b/mongodb/src/classes/user/Rewards.js index 7148a307..28816bdf 100644 --- a/mongodb/src/classes/user/Rewards.js +++ b/mongodb/src/classes/user/Rewards.js @@ -62,14 +62,6 @@ class Rewards { async receive(reward, reason) { const rewardTypes = ['daily', 'work', 'weekly', 'monthly', 'hourly'] - if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') - } - - if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') - } - if (isNaN(reward) || !rewardTypes[reward]) { throw new EconomyError( errors.invalidType('reward', 'key of RewardType enum', typeof reward), diff --git a/mongodb/src/managers/BalanceManager.js b/mongodb/src/managers/BalanceManager.js index 5a643d0f..2166bb06 100644 --- a/mongodb/src/managers/BalanceManager.js +++ b/mongodb/src/managers/BalanceManager.js @@ -100,11 +100,11 @@ class BalanceManager extends Emitter { */ async fetch(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const result = await this.database.fetch(`${guildID}.${memberID}.money`) @@ -135,15 +135,15 @@ class BalanceManager extends Emitter { const balance = await this.fetch(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.set(`${guildID}.${memberID}.money`, amount) @@ -177,15 +177,15 @@ class BalanceManager extends Emitter { const balance = await this.fetch(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.add(`${guildID}.${memberID}.money`, amount) @@ -219,15 +219,15 @@ class BalanceManager extends Emitter { const balance = await this.fetch(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.subtract(`${guildID}.${memberID}.money`, amount) @@ -262,7 +262,7 @@ class BalanceManager extends Emitter { const bank = await this.database.get(`${guildID}.${memberID}.bank`) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (amount < 0) { @@ -270,11 +270,11 @@ class BalanceManager extends Emitter { } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.subtract(`${guildID}.${memberID}.money`, amount) @@ -316,7 +316,7 @@ class BalanceManager extends Emitter { const data = await this.database.all() if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] @@ -349,19 +349,19 @@ class BalanceManager extends Emitter { } = options || {} if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof senderMemberID !== 'string') { - throw new EconomyError(errors.invalidTypes.senderMemberID + typeof senderMemberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('senderMemberID', 'string', senderMemberID), 'INVALID_TYPE') } if (typeof receiverMemberID !== 'string') { - throw new EconomyError(errors.invalidTypes.receiverMemberID + typeof receiverMemberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('receiverMemberID', 'string', receiverMemberID), 'INVALID_TYPE') } await this.add(amount, receiverMemberID, guildID, receivingReason || 'receiving money from user') diff --git a/mongodb/src/managers/BankManager.js b/mongodb/src/managers/BankManager.js index 4311d2bb..8515ed00 100644 --- a/mongodb/src/managers/BankManager.js +++ b/mongodb/src/managers/BankManager.js @@ -48,11 +48,11 @@ class BankManager extends Emitter { */ async fetch(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const result = await this.database.fetch(`${guildID}.${memberID}.bank`) @@ -83,15 +83,15 @@ class BankManager extends Emitter { const bank = await this.fetch(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.set(`${guildID}.${memberID}.bank`, Number(amount)) @@ -125,15 +125,15 @@ class BankManager extends Emitter { const bank = this.fetch(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.add(`${guildID}.${memberID}.bank`, Number(amount)) @@ -167,15 +167,15 @@ class BankManager extends Emitter { const bank = await this.fetch(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.subtract(`${guildID}.${memberID}.bank`, Number(amount)) @@ -210,7 +210,7 @@ class BankManager extends Emitter { const bank = await this.database.get(`${guildID}.${memberID}.bank`) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (amount < 0) { @@ -218,11 +218,11 @@ class BankManager extends Emitter { } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.add(`${guildID}.${memberID}.money`, amount) @@ -265,7 +265,7 @@ class BankManager extends Emitter { const data = await this.database.all() if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] diff --git a/mongodb/src/managers/CooldownManager.js b/mongodb/src/managers/CooldownManager.js index 8228ffee..e81bcd6a 100644 --- a/mongodb/src/managers/CooldownManager.js +++ b/mongodb/src/managers/CooldownManager.js @@ -49,11 +49,11 @@ class CooldownManager { */ async getDaily(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = await this.database.fetch(`${guildID}.${memberID}.dailyCooldown`) @@ -68,11 +68,11 @@ class CooldownManager { */ async getWork(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = await this.database.fetch(`${guildID}.${memberID}.workCooldown`) @@ -87,11 +87,11 @@ class CooldownManager { */ async getWeekly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = await this.database.fetch(`${guildID}.${memberID}.weeklyCooldown`) @@ -106,11 +106,11 @@ class CooldownManager { */ async getMonthly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = await this.database.fetch(`${guildID}.${memberID}.monthlyCooldown`) @@ -125,11 +125,11 @@ class CooldownManager { */ async getHourly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = await this.database.fetch(`${guildID}.${memberID}.hourlyCooldown`) @@ -144,11 +144,11 @@ class CooldownManager { */ async getAll(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const rawUserObject = await this.database.fetch(`${guildID}.${memberID}`) @@ -196,11 +196,11 @@ class CooldownManager { */ async clearAll(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const results = [ @@ -226,11 +226,11 @@ class CooldownManager { */ async clearDaily(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const result = await this.database.delete(`${guildID}.${memberID}.dailyCooldown`) @@ -251,11 +251,11 @@ class CooldownManager { */ async clearWork(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const result = await this.database.delete(`${guildID}.${memberID}.workCooldown`) @@ -276,11 +276,11 @@ class CooldownManager { */ async clearWeekly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const result = await this.database.delete(`${guildID}.${memberID}.weeklyCooldown`) @@ -301,11 +301,11 @@ class CooldownManager { */ async clearMonthly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const result = await this.database.delete(`${guildID}.${memberID}.monthlyCooldown`) @@ -326,11 +326,11 @@ class CooldownManager { */ async clearHourly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const result = await this.database.delete(`${guildID}.${memberID}.hourlyCooldown`) diff --git a/mongodb/src/managers/CurrencyManager.js b/mongodb/src/managers/CurrencyManager.js index 47d82062..8c21a803 100644 --- a/mongodb/src/managers/CurrencyManager.js +++ b/mongodb/src/managers/CurrencyManager.js @@ -63,7 +63,7 @@ class CurrencyManager extends Emitter { } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const currenciesArray = await this.all(guildID) diff --git a/mongodb/src/managers/GuildManager.js b/mongodb/src/managers/GuildManager.js index 4d8257d1..cbf6116a 100644 --- a/mongodb/src/managers/GuildManager.js +++ b/mongodb/src/managers/GuildManager.js @@ -94,7 +94,7 @@ class GuildManager extends BaseManager { settings: [] } - if (!guildID) throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + if (!guildID) throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') await this.database.set(guildID, emptyGuildObject) diff --git a/mongodb/src/managers/HistoryManager.js b/mongodb/src/managers/HistoryManager.js index 98c343bd..28a716ae 100644 --- a/mongodb/src/managers/HistoryManager.js +++ b/mongodb/src/managers/HistoryManager.js @@ -52,11 +52,11 @@ class HistoryManager { } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return history.map( @@ -87,11 +87,11 @@ class HistoryManager { const history = (await this.fetch(memberID, guildID)) || [] if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!history) return false @@ -130,15 +130,15 @@ class HistoryManager { } if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return false @@ -174,15 +174,15 @@ class HistoryManager { */ async remove(id, memberID, guildID) { if (typeof id !== 'number' && typeof id !== 'string') { - throw new EconomyError(errors.invalidTypes.id + typeof id, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('id', 'string or number', id), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const history = (await this.fetch(memberID, guildID)) || [] @@ -220,15 +220,15 @@ class HistoryManager { const history = (await this.fetch(memberID, guildID)) || [] if (typeof id !== 'number' && typeof id !== 'string') { - throw new EconomyError(errors.invalidTypes.id + typeof id, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('id', 'string or number', id), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } diff --git a/mongodb/src/managers/InventoryManager.js b/mongodb/src/managers/InventoryManager.js index 37f85391..95c89025 100644 --- a/mongodb/src/managers/InventoryManager.js +++ b/mongodb/src/managers/InventoryManager.js @@ -61,11 +61,11 @@ class InventoryManager extends Emitter { const inventory = (await this.fetch(memberID, guildID)) || [] if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!inventory) return false @@ -137,15 +137,15 @@ class InventoryManager extends Emitter { const item = inventory.find(item => item.id == itemID || item.name == itemID) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return null @@ -175,11 +175,11 @@ class InventoryManager extends Emitter { const inventory = (await this.database.get(`${guildID}.${memberID}.inventory`)) || [] if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return inventory.map(item => { @@ -220,15 +220,15 @@ class InventoryManager extends Emitter { const item = inventory[itemIndex] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return null @@ -347,15 +347,15 @@ class InventoryManager extends Emitter { } if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return false @@ -406,15 +406,15 @@ class InventoryManager extends Emitter { const inventoryItems = inventory.filter(invItem => invItem.name == item.name) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return { @@ -499,14 +499,14 @@ class InventoryManager extends Emitter { } if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return { diff --git a/mongodb/src/managers/RewardManager.js b/mongodb/src/managers/RewardManager.js index dbeb4d9b..cee4ce95 100644 --- a/mongodb/src/managers/RewardManager.js +++ b/mongodb/src/managers/RewardManager.js @@ -85,11 +85,11 @@ class RewardManager { const rewardTypes = ['daily', 'work', 'weekly', 'monthly', 'hourly'] if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (isNaN(reward) || !rewardTypes[reward]) { @@ -132,11 +132,11 @@ class RewardManager { */ async getDaily(memberID, guildID, reason = 'claimed the daily reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const settings = await this.database.get(`${guildID}.settings`) @@ -204,11 +204,11 @@ class RewardManager { */ async getWork(memberID, guildID, reason = 'claimed the work reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const settings = await this.database.get(`${guildID}.settings`) @@ -274,11 +274,11 @@ class RewardManager { */ async getWeekly(memberID, guildID, reason = 'claimed the weekly reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const settings = await this.database.get(`${guildID}.settings`) @@ -344,11 +344,11 @@ class RewardManager { */ async getMonthly(memberID, guildID, reason = 'claimed the monthly reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const settings = await this.database.get(`${guildID}.settings`) @@ -414,11 +414,11 @@ class RewardManager { */ async getHourly(memberID, guildID, reason = 'claimed the hourly reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const settings = await this.database.get(`${guildID}.settings`) diff --git a/mongodb/src/managers/SettingsManager.js b/mongodb/src/managers/SettingsManager.js index e964861a..890e0b5b 100644 --- a/mongodb/src/managers/SettingsManager.js +++ b/mongodb/src/managers/SettingsManager.js @@ -154,7 +154,7 @@ class SettingsManager { */ async get(key, guildID) { if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!settingsArray.includes(key)) { @@ -189,7 +189,7 @@ class SettingsManager { } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!settingsArray.includes(key)) { @@ -220,7 +220,7 @@ class SettingsManager { } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!settingsArray.includes(key)) { @@ -257,7 +257,7 @@ class SettingsManager { */ async all(guildID) { if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const settings = await this.database.fetch(`${guildID}.settings`) @@ -294,7 +294,7 @@ class SettingsManager { */ async reset(guildID) { if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const defaultSettings = { diff --git a/mongodb/src/managers/ShopManager.js b/mongodb/src/managers/ShopManager.js index 063ecb3d..1f46a580 100644 --- a/mongodb/src/managers/ShopManager.js +++ b/mongodb/src/managers/ShopManager.js @@ -84,7 +84,7 @@ class ShopManager extends Emitter { } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (typeof name !== 'string') { @@ -167,11 +167,11 @@ class ShopManager extends Emitter { const itemProperties = ['description', 'price', 'name', 'message', 'maxAmount', 'role', 'custom'] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!itemProperties.includes(itemProperty)) { @@ -296,11 +296,11 @@ class ShopManager extends Emitter { const item = shop[itemIndex] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } await this.database.pop(`${guildID}.shop`, itemIndex) @@ -333,7 +333,7 @@ class ShopManager extends Emitter { const shop = await this.fetch(guildID) if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!shop && !shop?.length) { @@ -358,7 +358,7 @@ class ShopManager extends Emitter { */ async fetch(guildID) { if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } /** @@ -405,11 +405,11 @@ class ShopManager extends Emitter { const item = shop.find(item => item.id == itemID || item.name == itemID) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return null @@ -500,15 +500,15 @@ class ShopManager extends Emitter { } if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return { diff --git a/src/classes/HistoryItem.js b/src/classes/HistoryItem.js index 9ddbb9f0..848cb6f2 100644 --- a/src/classes/HistoryItem.js +++ b/src/classes/HistoryItem.js @@ -112,15 +112,7 @@ class HistoryItem { const id = this.id if (typeof id !== 'number' && typeof id !== 'string') { - throw new EconomyError(errors.invalidTypes.id + typeof id, 'INVALID_TYPE') - } - - if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') - } - - if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('id', 'string or number', id), 'INVALID_TYPE') } const history = this.database diff --git a/src/classes/ShopItem.js b/src/classes/ShopItem.js index f09912c1..a6070761 100644 --- a/src/classes/ShopItem.js +++ b/src/classes/ShopItem.js @@ -236,7 +236,7 @@ class ShopItem extends Emitter { */ buy(memberID, quantity = 1, currency = null, reason = 'received the item from the shop') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } const balance = this.database.fetch(`${this.guildID}.${memberID}.money`) || 0 diff --git a/src/classes/guild/Shop.js b/src/classes/guild/Shop.js index cf13865b..15d6228c 100644 --- a/src/classes/guild/Shop.js +++ b/src/classes/guild/Shop.js @@ -38,7 +38,7 @@ class Shop extends BaseManager { const item = shop.find(item => item.id == itemID || item.name == itemID) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return null @@ -175,7 +175,7 @@ class Shop extends BaseManager { const itemProperties = ['description', 'price', 'name', 'message', 'maxAmount', 'role', 'custom'] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof this.guildID !== 'string') { diff --git a/src/classes/user/History.js b/src/classes/user/History.js index 21ebd807..8663dda7 100644 --- a/src/classes/user/History.js +++ b/src/classes/user/History.js @@ -83,7 +83,7 @@ class History extends BaseManager { if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return false @@ -107,7 +107,7 @@ class History extends BaseManager { */ remove(id) { if (typeof id !== 'number' && typeof id !== 'string') { - throw new EconomyError(errors.invalidTypes.id + typeof id, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('id', 'string or number', id), 'INVALID_TYPE') } const history = this.fetch(this.memberID, this.guildID) diff --git a/src/classes/user/Inventory.js b/src/classes/user/Inventory.js index 48ca63d8..e89f800f 100644 --- a/src/classes/user/Inventory.js +++ b/src/classes/user/Inventory.js @@ -82,7 +82,7 @@ class Inventory extends BaseManager { const item = inventory[itemIndex] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return null @@ -174,7 +174,7 @@ class Inventory extends BaseManager { const inventoryItems = inventory.filter(invItem => invItem.name == item.name) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return false @@ -206,7 +206,7 @@ class Inventory extends BaseManager { const itemIndex = inventory.findIndex(invItem => invItem.id == item?.id) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (!item) return false diff --git a/src/classes/user/Rewards.js b/src/classes/user/Rewards.js index 0e5e5524..57730de0 100644 --- a/src/classes/user/Rewards.js +++ b/src/classes/user/Rewards.js @@ -67,14 +67,6 @@ class Rewards { receive(reward, reason) { const rewardTypes = ['daily', 'work', 'weekly', 'monthly', 'hourly'] - if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') - } - - if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') - } - if (isNaN(reward) || !rewardTypes[reward]) { throw new EconomyError( errors.invalidType('reward', 'key of RewardType enum', typeof reward), diff --git a/src/managers/BalanceManager.js b/src/managers/BalanceManager.js index fa7954f3..a772f0ba 100644 --- a/src/managers/BalanceManager.js +++ b/src/managers/BalanceManager.js @@ -103,11 +103,11 @@ class BalanceManager extends Emitter { */ fetch(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return this.fetcher.fetchBalance(memberID, guildID) @@ -137,15 +137,15 @@ class BalanceManager extends Emitter { const balance = this.fetcher.fetchBalance(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.set(`${guildID}.${memberID}.money`, amount) @@ -174,15 +174,15 @@ class BalanceManager extends Emitter { const balance = this.fetcher.fetchBalance(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.add(`${guildID}.${memberID}.money`, amount) @@ -211,15 +211,15 @@ class BalanceManager extends Emitter { const balance = this.fetcher.fetchBalance(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.subtract(`${guildID}.${memberID}.money`, amount) @@ -249,7 +249,7 @@ class BalanceManager extends Emitter { const bank = this.fetcher.fetchBank(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (amount < 0) { @@ -257,11 +257,11 @@ class BalanceManager extends Emitter { } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.subtract(`${guildID}.${memberID}.money`, amount) @@ -298,7 +298,7 @@ class BalanceManager extends Emitter { const data = this.fetcher.fetchAll() if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] @@ -331,19 +331,19 @@ class BalanceManager extends Emitter { } = options || {} if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof senderMemberID !== 'string') { - throw new EconomyError(errors.invalidTypes.senderMemberID + typeof senderMemberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('senderMemberID', 'string', senderMemberID), 'INVALID_TYPE') } if (typeof receiverMemberID !== 'string') { - throw new EconomyError(errors.invalidTypes.receiverMemberID + typeof receiverMemberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('receiverMemberID', 'string', receiverMemberID), 'INVALID_TYPE') } this.add(amount, receiverMemberID, guildID, receivingReason || 'receiving money from user') diff --git a/src/managers/BankManager.js b/src/managers/BankManager.js index 1ce0eac0..a64e35e5 100644 --- a/src/managers/BankManager.js +++ b/src/managers/BankManager.js @@ -53,11 +53,11 @@ class BankManager extends Emitter { */ fetch(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return this.fetcher.fetchBank(memberID, guildID) @@ -87,15 +87,15 @@ class BankManager extends Emitter { const bank = this.fetcher.fetchBank(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.set(`${guildID}.${memberID}.bank`, Number(amount)) @@ -124,15 +124,15 @@ class BankManager extends Emitter { const bank = this.fetcher.fetchBank(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.add(`${guildID}.${memberID}.bank`, Number(amount)) @@ -161,15 +161,15 @@ class BankManager extends Emitter { const bank = this.fetcher.fetchBank(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.subtract(`${guildID}.${memberID}.bank`, Number(amount)) @@ -199,7 +199,7 @@ class BankManager extends Emitter { const bank = this.fetcher.fetchBank(memberID, guildID) if (isNaN(amount)) { - throw new EconomyError(errors.invalidTypes.amount + typeof amount, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('amount', 'number', amount), 'INVALID_TYPE') } if (amount < 0) { @@ -207,11 +207,11 @@ class BankManager extends Emitter { } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.subtract(`${guildID}.${memberID}.money`, amount) @@ -248,7 +248,7 @@ class BankManager extends Emitter { const data = this.fetcher.fetchAll() if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] diff --git a/src/managers/CooldownManager.js b/src/managers/CooldownManager.js index 54031fdf..5f8259a5 100644 --- a/src/managers/CooldownManager.js +++ b/src/managers/CooldownManager.js @@ -49,11 +49,11 @@ class CooldownManager { */ getDaily(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.fetch(`${guildID}.${memberID}.dailyCooldown`) @@ -68,11 +68,11 @@ class CooldownManager { */ getWork(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.fetch(`${guildID}.${memberID}.workCooldown`) @@ -87,11 +87,11 @@ class CooldownManager { */ getWeekly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.fetch(`${guildID}.${memberID}.weeklyCooldown`) @@ -106,11 +106,11 @@ class CooldownManager { */ getMonthly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.fetch(`${guildID}.${memberID}.monthlyCooldown`) @@ -125,11 +125,11 @@ class CooldownManager { */ getHourly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.fetch(`${guildID}.${memberID}.hourlyCooldown`) @@ -145,11 +145,11 @@ class CooldownManager { */ getAll(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const rawUserObject = this.database.fetch(`${guildID}.${memberID}`) @@ -197,11 +197,11 @@ class CooldownManager { */ clearAll(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const results = [ @@ -227,11 +227,11 @@ class CooldownManager { */ clearDaily(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return this.database.delete(`${guildID}.${memberID}.dailyCooldown`) @@ -245,11 +245,11 @@ class CooldownManager { */ clearWork(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return this.database.delete(`${guildID}.${memberID}.workCooldown`) @@ -263,11 +263,11 @@ class CooldownManager { */ clearWeekly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return this.database.delete(`${guildID}.${memberID}.weeklyCooldown`) @@ -281,11 +281,11 @@ class CooldownManager { */ clearMonthly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return this.database.delete(`${guildID}.${memberID}.monthlyCooldown`) @@ -299,11 +299,11 @@ class CooldownManager { */ clearHourly(memberID, guildID) { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return this.database.delete(`${guildID}.${memberID}.hourlyCooldown`) diff --git a/src/managers/CurrencyManager.js b/src/managers/CurrencyManager.js index 8a52f7c7..b398889d 100644 --- a/src/managers/CurrencyManager.js +++ b/src/managers/CurrencyManager.js @@ -55,7 +55,7 @@ class CurrencyManager extends Emitter { } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const currenciesArray = this.all(guildID) diff --git a/src/managers/FetchManager.js b/src/managers/FetchManager.js index e7f517dd..19e04b53 100644 --- a/src/managers/FetchManager.js +++ b/src/managers/FetchManager.js @@ -67,11 +67,11 @@ class FetchManager { const data = this.fetchAll() if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] @@ -91,11 +91,11 @@ class FetchManager { const data = this.fetchAll() if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] @@ -115,11 +115,11 @@ class FetchManager { const data = this.fetchAll() if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] @@ -139,11 +139,11 @@ class FetchManager { const data = this.fetchAll() if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] @@ -163,11 +163,11 @@ class FetchManager { const data = this.fetchAll() if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] @@ -197,7 +197,7 @@ class FetchManager { const data = this.fetchAll() if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const guildData = data[guildID] diff --git a/src/managers/GuildManager.js b/src/managers/GuildManager.js index f7fea5d8..26e1a3c8 100644 --- a/src/managers/GuildManager.js +++ b/src/managers/GuildManager.js @@ -86,7 +86,7 @@ class GuildManager extends BaseManager { settings: [] } - if (!guildID) throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + if (!guildID) throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') this.database.set(guildID, emptyGuildObject) return new EconomyGuild(guildID, this.options, emptyGuildObject, this.database) diff --git a/src/managers/HistoryManager.js b/src/managers/HistoryManager.js index 630fa036..75f4f985 100644 --- a/src/managers/HistoryManager.js +++ b/src/managers/HistoryManager.js @@ -54,11 +54,11 @@ class HistoryManager { } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return history.map( @@ -89,11 +89,11 @@ class HistoryManager { const history = this.fetch(memberID, guildID) if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!history) return false @@ -124,15 +124,15 @@ class HistoryManager { } if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return false @@ -163,15 +163,15 @@ class HistoryManager { */ remove(id, memberID, guildID) { if (typeof id !== 'number' && typeof id !== 'string') { - throw new EconomyError(errors.invalidTypes.id + typeof id, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('id', 'string or number', id), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const history = this.fetch(memberID, guildID) @@ -202,15 +202,15 @@ class HistoryManager { const history = this.fetch(memberID, guildID) if (typeof id !== 'number' && typeof id !== 'string') { - throw new EconomyError(errors.invalidTypes.id + typeof id, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('id', 'string or number', id), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } diff --git a/src/managers/InventoryManager.js b/src/managers/InventoryManager.js index 8ba37f36..f4e830f5 100644 --- a/src/managers/InventoryManager.js +++ b/src/managers/InventoryManager.js @@ -65,11 +65,11 @@ class InventoryManager extends Emitter { const inventory = this.fetch(memberID, guildID) if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!inventory) return false @@ -93,15 +93,15 @@ class InventoryManager extends Emitter { const item = inventory.find(item => item.id == itemID || item.name == itemID) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return null @@ -131,11 +131,11 @@ class InventoryManager extends Emitter { const inventory = this.fetcher.fetchInventory(memberID, guildID) if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return inventory.map(item => { @@ -172,15 +172,15 @@ class InventoryManager extends Emitter { const item = inventory[itemIndex] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return null @@ -335,15 +335,15 @@ class InventoryManager extends Emitter { } if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return false @@ -392,15 +392,15 @@ class InventoryManager extends Emitter { const inventoryItems = inventory.filter(invItem => invItem.name == item.name) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return { @@ -480,14 +480,14 @@ class InventoryManager extends Emitter { } if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return { diff --git a/src/managers/RewardManager.js b/src/managers/RewardManager.js index eb7d2678..3f935bde 100644 --- a/src/managers/RewardManager.js +++ b/src/managers/RewardManager.js @@ -78,11 +78,11 @@ class RewardManager { const rewardTypes = ['daily', 'work', 'weekly', 'monthly', 'hourly'] if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (isNaN(reward) || !rewardTypes[reward]) { @@ -129,11 +129,11 @@ class RewardManager { */ getDaily(memberID, guildID, reason = 'claimed the daily reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.get(`${guildID}.settings.dailyCooldown`) @@ -197,11 +197,11 @@ class RewardManager { */ getWork(memberID, guildID, reason = 'claimed the work reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.get(`${guildID}.settings.workCooldown`) @@ -264,11 +264,11 @@ class RewardManager { */ getWeekly(memberID, guildID, reason = 'claimed the weekly reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.get(`${guildID}.settings.weeklyCooldown`) @@ -331,11 +331,11 @@ class RewardManager { */ getMonthly(memberID, guildID, reason = 'claimed the monthly reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.get(`${guildID}.settings.monthlyCooldown`) @@ -398,11 +398,11 @@ class RewardManager { */ getHourly(memberID, guildID, reason = 'claimed the hourly reward') { if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const cooldown = this.database.get(`${guildID}.settings.hourlyCooldown`) diff --git a/src/managers/SettingsManager.js b/src/managers/SettingsManager.js index 373231bf..6d1286b8 100644 --- a/src/managers/SettingsManager.js +++ b/src/managers/SettingsManager.js @@ -155,7 +155,7 @@ class SettingsManager { */ get(key, guildID) { if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!settingsArray.includes(key)) { @@ -190,7 +190,7 @@ class SettingsManager { } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!settingsArray.includes(key)) { @@ -220,7 +220,7 @@ class SettingsManager { } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!settingsArray.includes(key)) { @@ -255,7 +255,7 @@ class SettingsManager { */ all(guildID) { if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const settings = this.database.fetch(`${guildID}.settings`) @@ -291,7 +291,7 @@ class SettingsManager { */ reset(guildID) { if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const defaultSettings = { diff --git a/src/managers/ShopManager.js b/src/managers/ShopManager.js index c67e8aea..5ccc3135 100644 --- a/src/managers/ShopManager.js +++ b/src/managers/ShopManager.js @@ -85,7 +85,7 @@ class ShopManager extends Emitter { } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (typeof name !== 'string') { @@ -164,11 +164,11 @@ class ShopManager extends Emitter { const itemProperties = ['description', 'price', 'name', 'message', 'maxAmount', 'role', 'custom'] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!itemProperties.includes(itemProperty)) { @@ -275,11 +275,11 @@ class ShopManager extends Emitter { const item = shop[itemIndex] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } this.database.pop(`${guildID}.shop`, itemIndex) @@ -308,7 +308,7 @@ class ShopManager extends Emitter { const shop = this.fetch(guildID) if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!shop && !shop?.length) { @@ -353,11 +353,11 @@ class ShopManager extends Emitter { const inventory = this.database.fetch(`${guildID}.${memberID}.inventory`) || [] if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!inventory) return false @@ -372,7 +372,7 @@ class ShopManager extends Emitter { */ fetch(guildID) { if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } const shop = this.database.fetch(`${guildID}.shop`) || [] @@ -416,11 +416,11 @@ class ShopManager extends Emitter { const item = shop.find(item => item.id == itemID || item.name == itemID) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return null @@ -474,15 +474,15 @@ class ShopManager extends Emitter { const item = inventory.find(item => item.id == itemID || item.name == itemID) if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return null @@ -551,15 +551,15 @@ class ShopManager extends Emitter { } if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return { @@ -698,11 +698,11 @@ class ShopManager extends Emitter { const inventory = this.database.fetch(`${guildID}.${memberID}.inventory`) || [] if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return inventory @@ -747,15 +747,15 @@ class ShopManager extends Emitter { const item = inventory[itemIndex] if (typeof itemID !== 'number' && typeof itemID !== 'string') { - throw new EconomyError(errors.invalidTypes.editItemArgs.itemID + typeof itemID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('itemID', 'string or number', itemID), 'INVALID_TYPE') } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!item) return null @@ -861,11 +861,11 @@ class ShopManager extends Emitter { } if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } return history @@ -901,11 +901,11 @@ class ShopManager extends Emitter { const history = this.database.fetch(`${guildID}.${memberID}.history`) || [] if (typeof memberID !== 'string') { - throw new EconomyError(errors.invalidTypes.memberID + typeof memberID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('memberID', 'string', memberID), 'INVALID_TYPE') } if (typeof guildID !== 'string') { - throw new EconomyError(errors.invalidTypes.guildID + typeof guildID, 'INVALID_TYPE') + throw new EconomyError(errors.invalidType('guildID', 'string', guildID), 'INVALID_TYPE') } if (!history) return false