Chore: linter

This commit is contained in:
Grail Finder
2025-05-19 10:42:10 +03:00
parent a7e7da6f99
commit 94df5b830c
6 changed files with 53 additions and 44 deletions

View File

@@ -1,32 +1,44 @@
version: "2"
run:
timeout: 1m
concurrency: 2
tests: false
linters:
enable-all: false
disable-all: true
default: none
enable:
- bodyclose
- errcheck
- gosimple
- fatcontext
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- noctx
- perfsprint
- prealloc
presets:
- performance
linters-settings:
- staticcheck
- unused
settings:
funlen:
lines: 80
statements: 50
lll:
line-length: 80
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
issues:
exclude:
# Display all issues
max-issues-per-linter: 0
max-same-issues: 0
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

6
bot.go
View File

@@ -43,6 +43,7 @@ var (
interruptResp = false
ragger *rag.RAG
chunkParser ChunkParser
//nolint:unused // TTS_ENABLED conditionally uses this
orator extra.Orator
asr extra.STT
defaultLCPProps = map[string]float32{
@@ -272,6 +273,7 @@ func roleToIcon(role string) string {
return "<" + role + ">: "
}
// FIXME: it should not be here; move to extra
func checkGame(role string, tv *tview.TextView) {
// Handle Cluedo game flow
// should go before form msg, since formmsg takes chatBody and makes ioreader out of it
@@ -283,8 +285,7 @@ func checkGame(role string, tv *tview.TextView) {
playerOrder = []string{cfg.UserRole, cfg.AssistantRole, cfg.CluedoRole2}
cluedoState = extra.CluedoPrepCards(playerOrder)
}
notifyUser("got in cluedo", "yay")
// notifyUser("got in cluedo", "yay")
currentPlayer := playerOrder[0]
playerOrder = append(playerOrder[1:], currentPlayer) // Rotate turns
if role == cfg.UserRole {
@@ -296,7 +297,6 @@ func checkGame(role string, tv *tview.TextView) {
})
}
}
return
}
func chatRound(userMsg, role string, tv *tview.TextView, regen, resume bool) {

View File

@@ -46,18 +46,13 @@ type KokoroOrator struct {
}
func stoproutine(orator Orator) {
select {
case <-TTSDoneChan:
<-TTSDoneChan
orator.GetLogger().Info("orator got done signal")
orator.Stop()
// close(TTSTextChan)
// TTSTextChan = make(chan string, 10000)
// drain the channel
for len(TTSTextChan) > 0 {
<-TTSTextChan
}
return
}
}
func readroutine(orator Orator) {

View File

@@ -32,7 +32,6 @@ type WhisperSTT struct {
ServerURL string
SampleRate int
AudioBuffer *bytes.Buffer
streamer StreamCloser
recording bool
}
@@ -90,7 +89,7 @@ func (stt *WhisperSTT) StopRecording() (string, error) {
return "", err
}
// Send request
resp, err := http.Post("http://localhost:8081/inference", writer.FormDataContentType(), body)
resp, err := http.Post(stt.ServerURL, writer.FormDataContentType(), body)
if err != nil {
stt.logger.Error("fn: StopRecording", "error", err)
return "", err
@@ -122,7 +121,9 @@ func (stt *WhisperSTT) writeWavHeader(w io.Writer, dataSize int) {
binary.LittleEndian.PutUint16(header[34:36], 16)
copy(header[36:40], "data")
binary.LittleEndian.PutUint32(header[40:44], uint32(dataSize))
w.Write(header)
if _, err := w.Write(header); err != nil {
stt.logger.Error("writeWavHeader", "error", err)
}
}
func (stt *WhisperSTT) IsRecording() bool {
@@ -136,7 +137,9 @@ func (stt *WhisperSTT) microphoneStream(sampleRate int) error {
in := make([]int16, 64)
stream, err := portaudio.OpenDefaultStream(1, 0, float64(sampleRate), len(in), in)
if err != nil {
portaudio.Terminate()
if paErr := portaudio.Terminate(); paErr != nil {
return fmt.Errorf("failed to open microphone: %w; terminate error: %w", err, paErr)
}
return fmt.Errorf("failed to open microphone: %w", err)
}
go func(stream *portaudio.Stream) {

View File

@@ -22,7 +22,6 @@ const (
writeHeader = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
)
type PngEmbed struct {
Key string
Value string
@@ -96,7 +95,7 @@ func ReadCard(fname, uname string) (*models.CharCard, error) {
return nil, err
}
if charSpec.Name == "" {
return nil, fmt.Errorf("failed to find role; fname %s\n", fname)
return nil, fmt.Errorf("failed to find role; fname %s", fname)
}
return charSpec.Simplify(uname, fname), nil
}

View File

@@ -235,7 +235,7 @@ func (r *RAG) LineToVector(line string) ([]float32, error) {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err = fmt.Errorf("non 200 resp; code: %v\n", resp.StatusCode)
err = fmt.Errorf("non 200 resp; code: %v", resp.StatusCode)
r.logger.Error(err.Error())
return nil, err
}