fix markov overflow

This commit is contained in:
skeletable 2022-10-02 00:09:36 +02:00
parent ef1fddfad6
commit bea8b57a99
1 changed files with 2 additions and 25 deletions

27
main.go
View File

@ -6,7 +6,6 @@ import (
"database/sql"
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"math/rand"
@ -1169,30 +1168,8 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
return
}
if fi.Size() > 1000000 {
fout, err := os.Create("markov-copy.txt")
if err != nil {
print(err.Error())
return
}
defer fout.Close()
_, err = f.Seek(int64(len(m.Content)), io.SeekStart)
if err != nil {
print("DEBUG: Seeking error: " + err.Error() + "\n")
}
bytes_copied, err := io.Copy(fout, f)
if err != nil {
print("DEBUG: Byte copying error: " + err.Error() + "\n")
return
}
print("DEBUG: bytes copied: %d", bytes_copied)
if err := os.Remove("markov.txt"); err != nil {
print("DEBUG: error removing markov.txt: " + err.Error() + "\n")
return
}
if err := os.Rename("markov-copy.txt", "markov.txt"); err != nil {
print(err.Error())
return
if err := os.Truncate("markov.txt", 0); err != nil {
fmt.Println("Failed to truncate: " + err.Error())
}
}
_, err = f.WriteString(m.Content + "\n")