@@ -11,7 +11,7 @@ class BuyItem extends Command {
11
11
name : 'buy-item' ,
12
12
category : 'Items' ,
13
13
description : 'Buy an item from the store.' ,
14
- usage : 'buy-item <item>' ,
14
+ usage : 'buy-item [quantity] <item>' ,
15
15
examples : [ 'buy pizza' ] ,
16
16
aliases : [ 'buy' ] ,
17
17
requiredArgs : 1 ,
@@ -20,7 +20,20 @@ class BuyItem extends Command {
20
20
}
21
21
22
22
async run ( msg , args ) {
23
- const itemName = args . join ( ' ' ) . toLowerCase ( ) ;
23
+ let quantity = 1 ;
24
+ let itemName = args . join ( ' ' ) . toLowerCase ( ) ;
25
+ if ( ! isNaN ( args [ 0 ] ) ) {
26
+ quantity = parseInt ( args [ 0 ] ) ;
27
+ if ( quantity <= 0 ) {
28
+ return msg . reply ( 'Invalid `[quantity]` argument given. Cannot be less than 1' ) ;
29
+ }
30
+ args . shift ( ) ;
31
+ itemName = args . join ( ' ' ) . toLowerCase ( ) ;
32
+ if ( ! itemName ) {
33
+ return msg . reply ( 'Invalid `<item name>` argument given' ) ;
34
+ }
35
+ }
36
+
24
37
if ( ! itemName ) return msg . reply ( 'Please specify an item to buy.' ) ;
25
38
26
39
const store = ( await db . get ( `servers.${ msg . guild . id } .economy.store` ) ) || { } ;
@@ -57,7 +70,7 @@ class BuyItem extends Command {
57
70
}
58
71
59
72
// Deduct the cost from the user's cash
60
- userCash = userCash - itemCost ;
73
+ userCash = userCash - itemCost * BigInt ( quantity ) ;
61
74
await db . set ( `servers.${ msg . guild . id } .users.${ msg . member . id } .economy.cash` , userCash . toString ( ) ) ;
62
75
63
76
if ( ! item . inventory ) {
@@ -124,26 +137,29 @@ class BuyItem extends Command {
124
137
const itemIndex = userInventory . findIndex ( ( inventoryItem ) => inventoryItem ?. name ?. toLowerCase ( ) === itemName ) ;
125
138
if ( itemIndex !== - 1 ) {
126
139
// If the item is found, increment the quantity
127
- userInventory [ itemIndex ] . quantity += 1 ;
140
+ userInventory [ itemIndex ] . quantity += quantity ;
128
141
await db . set ( `servers.${ msg . guild . id } .users.${ msg . member . id } .economy.inventory` , userInventory ) ;
129
142
} else {
130
143
// Add the item to the user's inventory
131
- item . quantity = 1 ;
144
+ item . quantity = quantity ;
132
145
userInventory . push ( { name : itemKey , ...item } ) ;
133
146
134
147
await db . set ( `servers.${ msg . guild . id } .users.${ msg . member . id } .economy.inventory` , userInventory ) ;
135
148
}
136
149
137
150
const currencySymbol = ( await db . get ( `servers.${ msg . guild . id } .economy.symbol` ) ) || '$' ;
151
+ const itemCostQuantity = ( itemCost * BigInt ( quantity ) ) . toLocaleString ( ) ;
138
152
const csCost =
139
- itemCost . toLocaleString ( ) . length > 700
140
- ? currencySymbol + itemCost . toLocaleString ( ) . slice ( 0 , 700 ) + '...'
141
- : currencySymbol + itemCost . toLocaleString ( ) ;
153
+ itemCostQuantity . length > 700
154
+ ? currencySymbol + itemCostQuantity . slice ( 0 , 700 ) + '...'
155
+ : currencySymbol + itemCostQuantity ;
142
156
143
157
const embed = new EmbedBuilder ( )
144
158
. setTitle ( 'Purchase Successful' )
145
159
. setDescription (
146
- `You have bought ${ itemKey } for ${ csCost } ! This is now in your inventory. \nUse this item with the \`use-item\` command.` ,
160
+ `You have bought ${ quantity } ${ itemKey } ${
161
+ quantity > 1 ? 's' : ''
162
+ } for ${ csCost } ! This is now in your inventory. \nUse this item with the \`use-item\` command.`,
147
163
)
148
164
. setColor ( msg . settings . embedColor )
149
165
. setTimestamp ( ) ;
0 commit comments