@@ -11,16 +11,16 @@ internal static class Command
1111 /// 获取市场商品信息
1212 /// </summary>
1313 /// <param name="bot"></param>
14- /// <param name="query "></param>
14+ /// <param name="marketUrl "></param>
1515 /// <returns></returns>
16- internal static async Task < string ? > ResponseGetMarketInfo ( Bot bot , string query )
16+ internal static async Task < string ? > ResponseGetMarketInfo ( Bot bot , string marketUrl )
1717 {
1818 if ( ! bot . IsConnectedAndLoggedOn )
1919 {
2020 return bot . FormatBotResponse ( Strings . BotNotConnected ) ;
2121 }
2222
23- var match = RegexUtils . MatchMarketUrl ( ) . Match ( query ) ;
23+ var match = RegexUtils . MatchMarketUrl ( ) . Match ( marketUrl ) ;
2424 if ( ! match . Success )
2525 {
2626 return bot . FormatBotResponse ( "市场链接似乎无效" ) ;
@@ -36,7 +36,7 @@ internal static class Command
3636 return bot . FormatBotResponse ( Langs . NetworkError ) ;
3737 }
3838
39- var detail = await WebRequest . GetMarketDetail ( bot , baseInfo . ItemId , bot . GetUserCountryCode ( ) , bot . WalletCurrency ) . ConfigureAwait ( false ) ;
39+ var detail = await WebRequest . GetMarketPriceInfo ( bot , baseInfo . ItemId , bot . GetUserCountryCode ( ) , bot . WalletCurrency ) . ConfigureAwait ( false ) ;
4040
4141 var sb = new StringBuilder ( ) ;
4242
@@ -63,10 +63,10 @@ internal static class Command
6363 /// 获取市场商品信息 (多个Bot)
6464 /// </summary>
6565 /// <param name="botNames"></param>
66- /// <param name="query "></param>
66+ /// <param name="marketUrl "></param>
6767 /// <returns></returns>
6868 /// <exception cref="ArgumentNullException"></exception>
69- internal static async Task < string ? > ResponseGetMarketInfo ( string botNames , string query )
69+ internal static async Task < string ? > ResponseGetMarketInfo ( string botNames , string marketUrl )
7070 {
7171 if ( string . IsNullOrEmpty ( botNames ) )
7272 {
@@ -80,7 +80,7 @@ internal static class Command
8080 return FormatStaticResponse ( Strings . BotNotFound , botNames ) ;
8181 }
8282
83- var results = await Utilities . InParallel ( bots . Select ( x => ResponseGetMarketInfo ( x , query ) ) ) . ConfigureAwait ( false ) ;
83+ var results = await Utilities . InParallel ( bots . Select ( x => ResponseGetMarketInfo ( x , marketUrl ) ) ) . ConfigureAwait ( false ) ;
8484 var responses = new List < string ? > ( results . Where ( result => ! string . IsNullOrEmpty ( result ) ) ) ;
8585
8686 return responses . Count > 0 ? string . Join ( Environment . NewLine , responses ) : null ;
@@ -90,21 +90,33 @@ internal static class Command
9090 /// 创建市场求购订单
9191 /// </summary>
9292 /// <param name="bot"></param>
93- /// <param name="query"></param>
93+ /// <param name="marketUrl"></param>
94+ /// <param name="strPrice"></param>
95+ /// <param name="strAmount"></param>
9496 /// <returns></returns>
95- internal static async Task < string ? > ResponseBuyMarketItem ( Bot bot , string query )
97+ internal static async Task < string ? > ResponseBuyMarketItem ( Bot bot , string marketUrl , string strPrice , string strAmount )
9698 {
9799 if ( ! bot . IsConnectedAndLoggedOn )
98100 {
99101 return bot . FormatBotResponse ( Strings . BotNotConnected ) ;
100102 }
101103
102- var match = RegexUtils . MatchMarketUrl ( ) . Match ( query ) ;
104+ var match = RegexUtils . MatchMarketUrl ( ) . Match ( marketUrl ) ;
103105 if ( ! match . Success )
104106 {
105107 return bot . FormatBotResponse ( "市场链接似乎无效" ) ;
106108 }
107109
110+ if ( ! decimal . TryParse ( strPrice , out var price ) || price <= 0 )
111+ {
112+ return bot . FormatBotResponse ( "求购价格无效" ) ;
113+ }
114+
115+ if ( ! int . TryParse ( strAmount , out var amount ) || amount <= 0 )
116+ {
117+ return bot . FormatBotResponse ( "求购数量无效" ) ;
118+ }
119+
108120 var appId = match . Groups [ 1 ] . Value ;
109121 var marketHash = match . Groups [ 2 ] . Value ;
110122
@@ -115,36 +127,98 @@ internal static class Command
115127 return bot . FormatBotResponse ( Langs . NetworkError ) ;
116128 }
117129
118- var detail = await WebRequest . GetMarketDetail ( bot , baseInfo . ItemId , bot . GetUserCountryCode ( ) , bot . WalletCurrency ) . ConfigureAwait ( false ) ;
130+ var buyResponse = await WebRequest . CreateBuyOrder ( bot , appId , marketHash , price , amount , bot . WalletCurrency , null ) . ConfigureAwait ( false ) ;
131+
132+ if ( buyResponse == null )
133+ {
134+ return bot . FormatBotResponse ( Langs . NetworkError ) ;
135+ }
136+
137+ if ( buyResponse . Success == SteamKit2 . EResult . Pending )
138+ {
139+ return bot . FormatBotResponse ( "创建求购订单需要验证令牌。请在移动设备上确认订单, 或者使用 2FAOK" ) ;
140+ }
119141
120142 var sb = new StringBuilder ( ) ;
121143
122144 sb . AppendLine ( Langs . MultipleLineResult ) ;
123145 sb . AppendLineFormat ( "物品名称: {0}" , baseInfo . Name ) ;
124- sb . AppendLineFormat ( "物品Id : {0} - {1} " , baseInfo . AppId , baseInfo . ItemId ) ;
146+ sb . AppendLineFormat ( "求购Id : {0}" , buyResponse . BuyOrderId ) ;
125147
126- if ( detail ? . SellInfoList != null )
148+ return bot . FormatBotResponse ( sb . ToString ( ) ) ;
149+ }
150+
151+ /// <summary>
152+ /// 创建市场求购订单 (多个Bot)
153+ /// </summary>
154+ /// <param name="botNames"></param>
155+ /// <param name="marketUrl"></param>
156+ /// <param name="strPrice"></param>
157+ /// <param name="strAmount"></param>
158+ /// <returns></returns>
159+ /// <exception cref="ArgumentNullException"></exception>
160+ internal static async Task < string ? > ResponseBuyMarketItem ( string botNames , string marketUrl , string strPrice , string strAmount )
161+ {
162+ if ( string . IsNullOrEmpty ( botNames ) )
127163 {
128- var price = detail . SellInfoList . FirstOrDefault ( ) ;
129- sb . AppendLineFormat ( "最低出售价: {1}{0}{2}" , price ? . Price , detail . PricePrefix , detail . PriceSuffix ) ;
164+ throw new ArgumentNullException ( nameof ( botNames ) ) ;
130165 }
131- if ( detail ? . BuyInfoList != null )
166+
167+ var bots = Bot . GetBots ( botNames ) ;
168+
169+ if ( bots == null || bots . Count == 0 )
132170 {
133- var price = detail . BuyInfoList . FirstOrDefault ( ) ;
134- sb . AppendLineFormat ( "最高求购价: {1}{0}{2}" , price ? . Price , detail . PricePrefix , detail . PriceSuffix ) ;
171+ return FormatStaticResponse ( Strings . BotNotFound , botNames ) ;
172+ }
173+
174+ var results = await Utilities . InParallel ( bots . Select ( x => ResponseBuyMarketItem ( x , marketUrl , strPrice , strAmount ) ) ) . ConfigureAwait ( false ) ;
175+ var responses = new List < string ? > ( results . Where ( result => ! string . IsNullOrEmpty ( result ) ) ) ;
176+
177+ return responses . Count > 0 ? string . Join ( Environment . NewLine , responses ) : null ;
178+ }
179+
180+ /// <summary>
181+ /// 获取求购订单列表
182+ /// </summary>
183+ /// <param name="bot"></param>
184+ /// <returns></returns>
185+ internal static async Task < string ? > ResponseGetMarketOrders ( Bot bot )
186+ {
187+ if ( ! bot . IsConnectedAndLoggedOn )
188+ {
189+ return bot . FormatBotResponse ( Strings . BotNotConnected ) ;
190+ }
191+
192+ var results = await WebRequest . GetOrderList ( bot ) . ConfigureAwait ( false ) ;
193+
194+ if ( results == null )
195+ {
196+ return bot . FormatBotResponse ( Langs . NetworkError ) ;
197+ }
198+
199+ if ( results . Count == 0 )
200+ {
201+ return bot . FormatBotResponse ( "市场求购列表为空" ) ;
202+ }
203+
204+ var sb = new StringBuilder ( ) ;
205+ sb . AppendLine ( Langs . MultipleLineResult ) ;
206+ sb . AppendLine ( "求购订单列表:" ) ;
207+ foreach ( var item in results )
208+ {
209+ sb . AppendLineFormat ( "{0} : {1} {2} * {3}" , item . OrderId , item . Name , item . Price , item . Amount ) ;
135210 }
136211
137212 return bot . FormatBotResponse ( sb . ToString ( ) ) ;
138213 }
139214
140215 /// <summary>
141- /// 创建市场求购订单 (多个Bot)
216+ /// 获取求购订单列表 (多个Bot)
142217 /// </summary>
143218 /// <param name="botNames"></param>
144- /// <param name="query"></param>
145219 /// <returns></returns>
146220 /// <exception cref="ArgumentNullException"></exception>
147- internal static async Task < string ? > ResponseBuyMarketItem ( string botNames , string query )
221+ internal static async Task < string ? > ResponseGetMarketOrders ( string botNames )
148222 {
149223 if ( string . IsNullOrEmpty ( botNames ) )
150224 {
@@ -158,13 +232,84 @@ internal static class Command
158232 return FormatStaticResponse ( Strings . BotNotFound , botNames ) ;
159233 }
160234
161- var results = await Utilities . InParallel ( bots . Select ( x => ResponseBuyMarketItem ( x , query ) ) ) . ConfigureAwait ( false ) ;
235+ var results = await Utilities . InParallel ( bots . Select ( ResponseGetMarketOrders ) ) . ConfigureAwait ( false ) ;
162236 var responses = new List < string ? > ( results . Where ( result => ! string . IsNullOrEmpty ( result ) ) ) ;
163237
164238 return responses . Count > 0 ? string . Join ( Environment . NewLine , responses ) : null ;
165239 }
166240
241+ /// <summary>
242+ /// 取消市场求购订单
243+ /// </summary>
244+ /// <param name="bot"></param>
245+ /// <param name="query"></param>
246+ /// <returns></returns>
247+ internal static async Task < string ? > ResponseCancelOrder ( Bot bot , string query )
248+ {
249+ if ( ! bot . IsConnectedAndLoggedOn )
250+ {
251+ return bot . FormatBotResponse ( Strings . BotNotConnected ) ;
252+ }
253+
254+ var entities = query . Split ( SeparatorDot , StringSplitOptions . RemoveEmptyEntries ) ;
255+
256+ var sb = new StringBuilder ( ) ;
257+
258+ if ( entities . Length > 1 )
259+ {
260+ sb . AppendLine ( Langs . MultipleLineResult ) ;
261+ }
262+
263+ foreach ( var entity in entities )
264+ {
265+ if ( ! long . TryParse ( entity , out var orderId ) || ( orderId == 0 ) )
266+ {
267+ var response = await WebRequest . CancelBuyOrder ( bot , orderId ) . ConfigureAwait ( false ) ;
268+
269+ if ( response ? . Success == SteamKit2 . EResult . OK )
270+ {
271+ sb . AppendLineFormat ( Langs . CookieItem , entity , "求购取消成功" ) ;
272+ }
273+ else
274+ {
275+ sb . AppendLineFormat ( Langs . CookieItem , entity , "求购取消失败" ) ;
276+ }
277+
278+ continue ;
279+ }
280+ else
281+ {
282+ sb . AppendLineFormat ( Langs . CookieItem , entity , "输入无效" ) ;
283+ }
284+ }
285+
286+ return bot . FormatBotResponse ( sb . ToString ( ) ) ;
287+ }
288+
289+ /// <summary>
290+ /// 取消市场求购订单 (多个Bot)
291+ /// </summary>
292+ /// <param name="botNames"></param>
293+ /// <param name="query"></param>
294+ /// <returns></returns>
295+ /// <exception cref="ArgumentNullException"></exception>
296+ internal static async Task < string ? > ResponseCancelOrder ( string botNames , string query )
297+ {
298+ if ( string . IsNullOrEmpty ( botNames ) )
299+ {
300+ throw new ArgumentNullException ( nameof ( botNames ) ) ;
301+ }
302+
303+ var bots = Bot . GetBots ( botNames ) ;
167304
305+ if ( bots == null || bots . Count == 0 )
306+ {
307+ return FormatStaticResponse ( Strings . BotNotFound , botNames ) ;
308+ }
168309
310+ var results = await Utilities . InParallel ( bots . Select ( x => ResponseCancelOrder ( x , query ) ) ) . ConfigureAwait ( false ) ;
311+ var responses = new List < string ? > ( results . Where ( result => ! string . IsNullOrEmpty ( result ) ) ) ;
169312
313+ return responses . Count > 0 ? string . Join ( Environment . NewLine , responses ) : null ;
314+ }
170315}
0 commit comments