fix: bufio.Scanner message too long

This commit is contained in:
Eugen Eisler 2024-11-05 11:25:32 +01:00
parent 96c8117135
commit 0bb4f58222
3 changed files with 13 additions and 12 deletions

View File

@ -23,8 +23,6 @@ func Cli(version string) (err error) {
return
}
println("Message: " + currentFlags.Message)
if currentFlags.Version {
fmt.Println(version)
return

View File

@ -95,18 +95,20 @@ func Init() (ret *Flags, err error) {
// readStdin reads from stdin and returns the input as a string or an error
func readStdin() (ret string, err error) {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
ret += scanner.Text() + "\n"
}
if err = scanner.Err(); err != nil {
if errors.Is(err, io.EOF) {
err = nil
} else {
err = fmt.Errorf("error reading piped message from stdin: %w", err)
reader := bufio.NewReader(os.Stdin)
var sb strings.Builder
for {
line, err := reader.ReadString('\n')
if err != nil {
if errors.Is(err, io.EOF) {
sb.WriteString(line)
break
}
return "", fmt.Errorf("error reading piped message from stdin: %w", err)
}
sb.WriteString(line)
}
return
return sb.String(), nil
}
func (o *Flags) BuildChatOptions() (ret *common.ChatOptions) {

View File

@ -59,6 +59,7 @@ func (o *YouTube) GetVideoOrPlaylistId(url string) (videoId string, playlistId s
}
// Video ID pattern
//https:((youtu.be/7qZl_5xHoBw
videoPattern := `(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})`
videoRe := regexp.MustCompile(videoPattern)
videoMatch := videoRe.FindStringSubmatch(url)