@@ -422,22 +422,31 @@ func ExtractLevel(text string) int {
422422
423423// ExtractEnhanceResultLevel 강화 결과에서 변경 후 레벨 추출
424424// "+0 → +1" 패턴에서 1을 추출, 또는 "획득 검: [+1]" 패턴에서 1을 추출
425+ // 여러 매칭이 있으면 마지막(가장 최신) 사용
425426func ExtractEnhanceResultLevel (text string ) int {
426- // 1순위: "+0 → +1" 패턴에서 결과 레벨 추출
427- if matches := enhanceLevelPattern .FindStringSubmatch (text ); len (matches ) > 2 {
428- if level , err := strconv .Atoi (matches [2 ]); err == nil {
429- if level >= MinLevel && level <= MaxLevel {
430- return level
427+ // 1순위: "+0 → +1" 패턴에서 결과 레벨 추출 (마지막 매칭)
428+ allMatches := enhanceLevelPattern .FindAllStringSubmatch (text , - 1 )
429+ if len (allMatches ) > 0 {
430+ matches := allMatches [len (allMatches )- 1 ] // 마지막 매칭 사용
431+ if len (matches ) > 2 {
432+ if level , err := strconv .Atoi (matches [2 ]); err == nil {
433+ if level >= MinLevel && level <= MaxLevel {
434+ return level
435+ }
431436 }
432437 }
433438 }
434439
435- // 2순위: "획득 검: [+N]" 패턴에서 레벨 추출
440+ // 2순위: "획득 검: [+N]" 패턴에서 레벨 추출 (마지막 매칭)
436441 swordPattern := regexp .MustCompile (`획득\s*검:\s*\[\+?(\d+)\]` )
437- if matches := swordPattern .FindStringSubmatch (text ); len (matches ) > 1 {
438- if level , err := strconv .Atoi (matches [1 ]); err == nil {
439- if level >= MinLevel && level <= MaxLevel {
440- return level
442+ allSwordMatches := swordPattern .FindAllStringSubmatch (text , - 1 )
443+ if len (allSwordMatches ) > 0 {
444+ matches := allSwordMatches [len (allSwordMatches )- 1 ]
445+ if len (matches ) > 1 {
446+ if level , err := strconv .Atoi (matches [1 ]); err == nil {
447+ if level >= MinLevel && level <= MaxLevel {
448+ return level
449+ }
441450 }
442451 }
443452 }
@@ -595,39 +604,49 @@ func ParseProfile(text string) *Profile {
595604 }
596605 }
597606
598- // 골드 추출 (음수 불가)
599- if matches := profileGoldPattern .FindStringSubmatch (text ); len (matches ) > 1 {
600- goldStr := strings .ReplaceAll (matches [1 ], "," , "" )
601- if gold , err := strconv .Atoi (goldStr ); err == nil {
602- // 골드는 절대 음수가 될 수 없음
603- if gold >= 0 {
604- profile .Gold = gold
607+ // 골드 추출 (음수 불가) - 마지막 매칭 사용
608+ allGoldMatches := profileGoldPattern .FindAllStringSubmatch (text , - 1 )
609+ if len (allGoldMatches ) > 0 {
610+ matches := allGoldMatches [len (allGoldMatches )- 1 ]
611+ if len (matches ) > 1 {
612+ goldStr := strings .ReplaceAll (matches [1 ], "," , "" )
613+ if gold , err := strconv .Atoi (goldStr ); err == nil {
614+ // 골드는 절대 음수가 될 수 없음
615+ if gold >= 0 {
616+ profile .Gold = gold
617+ }
605618 }
606619 }
607620 }
608621
609- // 보유 검 추출 (레벨 + 이름)
610- if matches := profileSwordPattern .FindStringSubmatch (text ); len (matches ) > 2 {
611- levelStr := strings .TrimPrefix (matches [1 ], "+" )
612- if level , err := strconv .Atoi (levelStr ); err == nil {
613- profile .Level = level
622+ // 보유 검 추출 (레벨 + 이름) - 마지막 매칭 사용 (채팅에 여러 프로필 있을 수 있음)
623+ allSwordMatches := profileSwordPattern .FindAllStringSubmatch (text , - 1 )
624+ if len (allSwordMatches ) > 0 {
625+ // 마지막 매칭 사용 (가장 최신 프로필)
626+ matches := allSwordMatches [len (allSwordMatches )- 1 ]
627+ if len (matches ) > 2 {
628+ levelStr := strings .TrimPrefix (matches [1 ], "+" )
629+ if level , err := strconv .Atoi (levelStr ); err == nil {
630+ profile .Level = level
631+ }
632+ profile .SwordName = strings .TrimSpace (matches [2 ])
614633 }
615- profile .SwordName = strings .TrimSpace (matches [2 ])
616634 }
617635
618- // 최고 기록 추출
619- if matches := profileBestPattern .FindStringSubmatch (text ); len (matches ) > 2 {
620- levelStr := strings .TrimPrefix (matches [1 ], "+" )
621- if level , err := strconv .Atoi (levelStr ); err == nil {
622- profile .BestLevel = level
636+ // 최고 기록 추출 - 마지막 매칭 사용
637+ allBestMatches := profileBestPattern .FindAllStringSubmatch (text , - 1 )
638+ if len (allBestMatches ) > 0 {
639+ matches := allBestMatches [len (allBestMatches )- 1 ]
640+ if len (matches ) > 2 {
641+ levelStr := strings .TrimPrefix (matches [1 ], "+" )
642+ if level , err := strconv .Atoi (levelStr ); err == nil {
643+ profile .BestLevel = level
644+ }
645+ profile .BestSword = strings .TrimSpace (matches [2 ])
623646 }
624- profile .BestSword = strings .TrimSpace (matches [2 ])
625647 }
626648
627- // 레벨이 없으면 일반 패턴으로 시도
628- if profile .Level == - 1 {
629- profile .Level = ExtractLevel (text )
630- }
649+ // 참고: ExtractLevel fallback 제거 (이전 채팅의 레벨이 잡히는 버그 방지)
631650
632651 return profile
633652}
0 commit comments