Fix parse error during game update
This commit is contained in:
		
							parent
							
								
									0a877f9f27
								
							
						
					
					
						commit
						ca2ccc569d
					
				
							
								
								
									
										14
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								main.go
									
									
									
									
									
								
							@ -263,11 +263,12 @@ func parseGameStart(input string) (string, error) {
 | 
			
		||||
	for _, line := range strings.Split(input, "\n") {
 | 
			
		||||
		line = strings.Trim(line, " ")
 | 
			
		||||
 | 
			
		||||
		if !strings.HasPrefix(line, "@chess") {
 | 
			
		||||
		var found bool
 | 
			
		||||
		if line, found = strings.CutPrefix(line, "@chess"); !found {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return strings.Trim(strings.ReplaceAll(line, "@chess", ""), " "), nil
 | 
			
		||||
		return strings.Trim(line, " "), nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return "", errors.New("failed to parse game start")
 | 
			
		||||
@ -278,15 +279,18 @@ func parseGameProgress(input string) (string, error) {
 | 
			
		||||
	words := strings.Split(input, " ")
 | 
			
		||||
 | 
			
		||||
	if len(lines) == 1 && len(words) == 1 {
 | 
			
		||||
		return strings.Trim(input, " "), nil
 | 
			
		||||
		return strings.Trim(strings.ReplaceAll(input, "@chess", ""), " "), nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, line := range strings.Split(input, "\n") {
 | 
			
		||||
		if !strings.Contains(line, "@chess") {
 | 
			
		||||
		line = strings.Trim(line, " ")
 | 
			
		||||
 | 
			
		||||
		var found bool
 | 
			
		||||
		if line, found = strings.CutPrefix(line, "@chess"); !found {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return strings.Trim(strings.ReplaceAll(line, "@chess", ""), " "), nil
 | 
			
		||||
		return strings.Trim(line, " "), nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return "", errors.New("failed to parse game update")
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user