|
7 | 7 |
|
8 | 8 | var |
9 | 9 | shouldLog = false |
| 10 | + linecounter = 0 |
10 | 11 | # check if a string contains some text that can be found in a set |
11 | 12 | # there's probably a cleaner/smarter way to do this, will update at some point |
12 | 13 | proc hasTextInSet(str: string, s: seq): bool = |
@@ -48,6 +49,10 @@ proc addTwitchBadges(s: string, e: IrcEvent): string = |
48 | 49 | proc logToFile(f: File, s: string) = |
49 | 50 | if shouldLog: |
50 | 51 | f.writeLine(s) |
| 52 | + linecounter += 1 |
| 53 | + if linecounter >= 10: |
| 54 | + f.flushFile() |
| 55 | + linecounter = 0 |
51 | 56 |
|
52 | 57 | var chans = newSeq[string](0) |
53 | 58 | var highlights = newSeq[string](0) |
@@ -90,7 +95,7 @@ if shouldLog: |
90 | 95 | else: |
91 | 96 | discard f.open(filename, fmReadWrite) |
92 | 97 |
|
93 | | -system.addQuitProc(resetAttributes) |
| 98 | +addQuitProc(resetAttributes) |
94 | 99 |
|
95 | 100 | while true: |
96 | 101 | var event: IrcEvent |
@@ -133,25 +138,11 @@ while true: |
133 | 138 | f.logToFile(chatline) |
134 | 139 |
|
135 | 140 | 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) |
143 | 141 | chatline = "$1 $2 - [JOIN] $3" % [curtime, event.origin, event.nick] |
144 | 142 | styledWriteLine(stdout, fgGreen, chatline) |
145 | 143 | f.logToFile(chatline) |
146 | 144 |
|
147 | 145 | 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) |
155 | 146 | chatline = "$1 $2 - [PART] $3" % [curtime, event.origin, event.nick] |
156 | 147 | styledWriteLine(stdout, fgRed, chatline) |
157 | 148 | f.logToFile(chatline) |
|
0 commit comments