@@ -18,21 +18,9 @@ export function getItemAndAmount(
1818 prefix : string ,
1919 from ?: 'buy' | 'sell' | 'buycart' | 'sellcart'
2020) : { 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 ;
3624
3725 if ( [ '!price' , '!sellcart' , '!buycart' , '!sell' , '!buy' , '!pc' , '!s' , '!b' ] . includes ( name ) ) {
3826 bot . sendMessage (
@@ -210,6 +198,26 @@ export function getItemAndAmount(
210198 } ;
211199}
212200
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+
213221export function getItemFromParams (
214222 steamID : SteamID | string ,
215223 params : UnknownDictionaryKnownValues ,
0 commit comments