@@ -18,21 +18,9 @@ export function getItemAndAmount(
18
18
prefix : string ,
19
19
from ?: 'buy' | 'sell' | 'buycart' | 'sellcart'
20
20
) : { match : Entry ; priceKey : string ; amount : number } | null {
21
- let name = removeLinkProtocol ( message ) ;
22
- let amount = 1 ;
23
- const args = name . split ( ' ' ) ;
24
- if ( / ^ [ - ] ? \d + $ / . test ( args [ 0 ] ) && args . length > 2 ) {
25
- // Check if the first part of the name is a number, if so, then that is the amount the user wants to trade
26
- amount = parseInt ( args [ 0 ] ) ;
27
- name = name . replace ( amount . toString ( ) , '' ) . trim ( ) ;
28
- } else if ( Pricelist . isAssetId ( args [ 0 ] ) && args . length === 1 ) {
29
- // Check if the only parameter is an assetid
30
- name = args [ 0 ] ;
31
- }
32
-
33
- if ( 1 > amount ) {
34
- amount = 1 ;
35
- }
21
+ const parsedMessage = parseItemAndAmountFromMessage ( message ) ;
22
+ const name = parsedMessage . name ;
23
+ let amount = parsedMessage . amount ;
36
24
37
25
if ( [ '!price' , '!sellcart' , '!buycart' , '!sell' , '!buy' , '!pc' , '!s' , '!b' ] . includes ( name ) ) {
38
26
bot . sendMessage (
@@ -210,6 +198,26 @@ export function getItemAndAmount(
210
198
} ;
211
199
}
212
200
201
+ export function parseItemAndAmountFromMessage ( message : string ) : { name : string ; amount : number } {
202
+ let name = removeLinkProtocol ( message ) ;
203
+ let amount = 1 ;
204
+ const args = name . split ( ' ' ) ;
205
+ if ( / ^ [ - ] ? \d + $ / . test ( args [ 0 ] ) && args . length > 1 ) {
206
+ // Check if the first part of the name is a number, if so, then that is the amount the user wants to trade
207
+ amount = parseInt ( args [ 0 ] ) ;
208
+ name = name . replace ( amount . toString ( ) , '' ) . trim ( ) ;
209
+ } else if ( Pricelist . isAssetId ( args [ 0 ] ) && args . length === 1 ) {
210
+ // Check if the only parameter is an assetid
211
+ name = args [ 0 ] ;
212
+ }
213
+
214
+ if ( 1 > amount ) {
215
+ amount = 1 ;
216
+ }
217
+
218
+ return { name : name , amount : amount } ;
219
+ }
220
+
213
221
export function getItemFromParams (
214
222
steamID : SteamID | string ,
215
223
params : UnknownDictionaryKnownValues ,
0 commit comments