Skip to content

Commit 4a2902e

Browse files
committed
remove silly hack, flush file every 10 lines
add config later to allow changing this
1 parent dc1f534 commit 4a2902e

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

tinytwitch.nim

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const
77

88
var
99
shouldLog = false
10+
linecounter = 0
1011
# check if a string contains some text that can be found in a set
1112
# there's probably a cleaner/smarter way to do this, will update at some point
1213
proc hasTextInSet(str: string, s: seq): bool =
@@ -48,6 +49,10 @@ proc addTwitchBadges(s: string, e: IrcEvent): string =
4849
proc logToFile(f: File, s: string) =
4950
if shouldLog:
5051
f.writeLine(s)
52+
linecounter += 1
53+
if linecounter >= 10:
54+
f.flushFile()
55+
linecounter = 0
5156

5257
var chans = newSeq[string](0)
5358
var highlights = newSeq[string](0)
@@ -90,7 +95,7 @@ if shouldLog:
9095
else:
9196
discard f.open(filename, fmReadWrite)
9297

93-
system.addQuitProc(resetAttributes)
98+
addQuitProc(resetAttributes)
9499

95100
while true:
96101
var event: IrcEvent
@@ -133,25 +138,11 @@ while true:
133138
f.logToFile(chatline)
134139

135140
of MJoin:
136-
# silly hack, saves text roughly every 30s
137-
if shouldLog:
138-
f.close()
139-
if f.open(filename):
140-
discard f.open(filename, fmAppend)
141-
else:
142-
discard f.open(filename, fmReadWrite)
143141
chatline = "$1 $2 - [JOIN] $3" % [curtime, event.origin, event.nick]
144142
styledWriteLine(stdout, fgGreen, chatline)
145143
f.logToFile(chatline)
146144

147145
of MPart:
148-
# silly hack, saves text roughly every 30s
149-
if shouldLog:
150-
f.close()
151-
if f.open(filename):
152-
discard f.open(filename, fmAppend)
153-
else:
154-
discard f.open(filename, fmReadWrite)
155146
chatline = "$1 $2 - [PART] $3" % [curtime, event.origin, event.nick]
156147
styledWriteLine(stdout, fgRed, chatline)
157148
f.logToFile(chatline)

0 commit comments

Comments
 (0)