@@ -5,6 +5,7 @@ use colored::*;
55use fishpi_rust:: { GestureType , RedPacketMessage , RedPacketType } ;
66use std:: collections:: HashMap ;
77use std:: sync:: { Arc , Mutex } ;
8+ use crate :: utils:: random_gesture;
89
910pub struct RedpacketCommand {
1011 context : CommandContext ,
@@ -66,8 +67,8 @@ impl RedpacketCommand {
6667
6768 // 只提供了红包ID,则随机生成一个手势
6869 let gesture = if args. len ( ) == 1 {
69- let rand_num = rand :: random_range ( 0 ..= 2 ) ;
70- match rand_num {
70+ // let rand_num = random_gesture( );
71+ match random_gesture ( ) {
7172 0 => GestureType :: Rock ,
7273 1 => GestureType :: Scissors ,
7374 _ => GestureType :: Paper ,
@@ -383,7 +384,7 @@ impl RedpacketCommand {
383384 match args. len ( ) {
384385 0 => {
385386 // 不给参数, 积分32 手势随机
386- let gesture = match rand :: random_range ( 0 ..= 2 ) {
387+ let gesture = match random_gesture ( ) {
387388 0 => GestureType :: Rock ,
388389 1 => GestureType :: Scissors ,
389390 _ => GestureType :: Paper ,
@@ -408,7 +409,7 @@ impl RedpacketCommand {
408409 1 => {
409410 // 只给了一个参数,手势随机
410411 let money: i32 = args[ 0 ] . parse ( ) . unwrap_or ( default_money) ;
411- let gesture = match rand :: random_range ( 0 ..= 2 ) {
412+ let gesture = match random_gesture ( ) {
412413 0 => GestureType :: Rock ,
413414 1 => GestureType :: Scissors ,
414415 _ => GestureType :: Paper ,
@@ -433,7 +434,7 @@ impl RedpacketCommand {
433434 2 => {
434435 // 两个参数,手势随机,第二个参数msg
435436 let money: i32 = args[ 0 ] . parse ( ) . unwrap_or ( default_money) ;
436- let gesture = match rand :: random_range ( 0 ..= 2 ) {
437+ let gesture = match random_gesture ( ) {
437438 0 => GestureType :: Rock ,
438439 1 => GestureType :: Scissors ,
439440 2 => GestureType :: Paper ,
@@ -508,13 +509,13 @@ impl RedpacketCommand {
508509 async fn handle_list_command ( & self ) -> Result < ( ) > {
509510 let cache = self . redpacket_cache . lock ( ) . unwrap ( ) ;
510511 if cache. is_empty ( ) {
511- println ! ( "{}" , "当前没有可领取的红包" . yellow( ) ) ;
512+ println ! ( "\r {}" , "当前没有可领取的红包" . yellow( ) ) ;
512513 } else {
513- println ! ( "{}" , "当前可领取的红包:" . bold( ) ) ;
514+ println ! ( "\r {}" , "当前可领取的红包:" . bold( ) ) ;
514515 for ( id, info) in cache. iter ( ) . enumerate ( ) {
515516 let type_name = RedPacketType :: to_name ( & info. 1 . type_ ) ;
516517 println ! (
517- " {}. {} [{}] {} 个, 共 {} 积分, 已领取 {}/{}" ,
518+ "\r {}. {} [{}] {} 个, 共 {} 积分, 已领取 {}/{}" ,
518519 id + 1 ,
519520 info. 0 . bright_black( ) ,
520521 type_name. red( ) ,
@@ -531,7 +532,7 @@ impl RedpacketCommand {
531532 /// 自动打开红包
532533 async fn handle_auto_open_command ( & self ) -> Result < ( ) > {
533534 if self . redpacket_cache . lock ( ) . unwrap ( ) . is_empty ( ) {
534- println ! ( "{}" , "当前没有可领取的红包" . yellow( ) ) ;
535+ println ! ( "\r {}" , "当前没有可领取的红包" . yellow( ) ) ;
535536 return Ok ( ( ) ) ;
536537 }
537538 let oids: Vec < ( String , RedPacketMessage ) > = {
@@ -544,7 +545,7 @@ impl RedpacketCommand {
544545 for ( id, msg) in oids {
545546 if msg. type_ == RedPacketType :: ROCK_PAPER_SCISSORS {
546547 // 随机生成一个手势
547- let gesture = match rand :: random_range ( 0 ..= 2 ) {
548+ let gesture = match random_gesture ( ) {
548549 0 => GestureType :: Rock ,
549550 1 => GestureType :: Scissors ,
550551 _ => GestureType :: Paper ,
@@ -576,13 +577,13 @@ impl RedpacketCommand {
576577 let user_name = self . context . auth . get_user_name ( ) . await ?;
577578 if let Some ( got) = info. who . iter ( ) . find ( |got| got. user_name == user_name) {
578579 println ! (
579- "你领取了 {} 积分 {} / {}" ,
580+ "\r 你领取了 {} 积分 {} / {}" ,
580581 got. money. to_string( ) . yellow( ) . bold( ) ,
581582 info. info. got. to_string( ) . cyan( ) ,
582583 info. info. count. to_string( ) . cyan( )
583584 ) ;
584585 } else {
585- println ! ( "{}" , "红包已领完" . yellow( ) ) ;
586+ println ! ( "\r {}" , "红包已领完" . yellow( ) ) ;
586587 }
587588 }
588589 }
0 commit comments