@@ -40,7 +40,6 @@ func (conf ConfigType) FetchMain() {
4040 conf .checkToken ()
4141
4242 ParsedMessages := map [string ]JSONMetaData {}
43- NumLeft := conf .Filter .NumMax
4443
4544 maxTime := conf .Filter .MaxTime
4645 minTime := conf .Filter .MinTime
@@ -150,21 +149,27 @@ func (conf ConfigType) FetchMain() {
150149 }
151150 }
152151
153- if maxTime > maxMsg .Timestamp && maxMsg .Timestamp != 0 {
152+ if ( maxTime > maxMsg .Timestamp && maxMsg .Timestamp != 0 ) || ( maxTime == 0 && maxMsg . Timestamp != 0 ) {
154153 maxTime = maxMsg .Timestamp
155154 }
156155
157- if minTime < minMsg .Timestamp {
156+ if ( minTime < minMsg .Timestamp && maxMsg . Timestamp != 0 ) || ( minTime == 0 && minMsg . Timestamp != 0 ) {
158157 minTime = minMsg .Timestamp
159158 }
160159
160+ if maxTime == 0 {
161+ maxTime = 9999999999999999
162+ }
163+
161164 for _ , channel := range conf .Ids {
162- NumLeft = conf .Filter .NumMax
165+ NumLeft : = conf .Filter .NumMax
163166
164167 outputDir := tools .ParseTemplate (conf .ExportLocation , map [string ]string {
165168 "CHANNEL_ID" : channel ,
166169 })
167170
171+ os .RemoveAll (outputDir )
172+
168173 os .Mkdir (outputDir , 0755 )
169174
170175 mediaDir := ""
@@ -255,26 +260,24 @@ func (conf ConfigType) FetchMain() {
255260 } // TODO: Add other channel types
256261 }
257262
263+ lastID := fmt .Sprint (discord .TimestampToID (minTime ))
264+
265+ if len (lastID ) == 0 {
266+ lastID = "0"
267+ }
268+
258269 prevMsg := discord.Message {}
259270
260271 for {
261272 fin := false
262-
263- msgQSuffix := "&after=" + prevMsg .ID
264- if len (prevMsg .ID ) == 0 {
265- if minTime != 0 {
266- msgQSuffix += discord .TimestampToID (maxTime )
267- } else {
268- msgQSuffix = ""
269- }
270- }
271-
272273 resp := []byte {}
273- err := conf .discordFetch (fmt .Sprintf ("/channels/%v/messages?limit=%v%v" , channel , limit , msgQSuffix ), & resp )
274+ msgUrl := fmt .Sprintf ("/channels/%v/messages?limit=%v&after=%v" , channel , limit , lastID )
275+ fmt .Println (msgUrl )
276+ err := conf .discordFetch (msgUrl , & resp )
274277 tools .PanicIfErr (err )
275278 allMsgs := []discord.Message {}
276279 json .Unmarshal (resp , & allMsgs )
277-
280+
278281 if len (allMsgs ) != limit {
279282 fin = true // don't break because you still need proccessing
280283 }
@@ -284,11 +287,20 @@ func (conf ConfigType) FetchMain() {
284287 allMsgs [i ], allMsgs [j ] = allMsgs [j ], allMsgs [i ]
285288 }
286289
290+ lastID = allMsgs [len (allMsgs )- 1 ].ID
291+
287292 for _ , msg := range allMsgs {
288293 if NumLeft == 0 {
294+ fin = true
289295 break
290296 }
291297
298+ if msg .Timestamp > maxTime {
299+ break
300+ }
301+
302+ // fmt.Println(msg.Content)
303+
292304 for _ , embed := range msg .Embeds {
293305 if embed .Type == discord .EMBED_IMAGE {
294306 msg .Attachments = append (msg .Attachments , discord.Attachment {
@@ -342,16 +354,10 @@ func (conf ConfigType) FetchMain() {
342354 case config .EXPORT_TYPE_HTML :
343355 msgTimestamp := discord .TimestampToTime (msg .Timestamp )
344356 sameDate := tools .SameDate (msgTimestamp , discord .TimestampToTime (prevMsg .Timestamp ))
345-
346357 if ! sameDate {
347358 file .WriteString (theme .DateSeperator (msgTimestamp ))
348359 }
349-
350360 file .WriteString (theme .MessageComponent (msg , prevMsg , prevMsg .Author .ID != msg .Author .ID || ! sameDate || msg .IsReply ))
351-
352- prevMsg = msg
353- fin = true
354-
355361 case config .EXPORT_TYPE_JSON :
356362 newChanInfo := ParsedMessages [channel ]
357363
@@ -364,15 +370,16 @@ func (conf ConfigType) FetchMain() {
364370 Attachment : attachRaw ,
365371 AuthorID : msg .Author .ID ,
366372 }
367-
373+
368374 newChanInfo .AttachList = append (newChanInfo .AttachList , attachment )
369375 newChanInfo .AttachIDToIndex [attachment .ID ] = len (newChanInfo .AttachIDToIndex ) - 1
370376 newChanInfo .AttachByAuthor [msg .Author .ID ] = append (newChanInfo .AttachByAuthor [msg .Author .ID ], attachment .ID )
371377 }
372-
378+
373379 ParsedMessages [channel ] = newChanInfo
374380 }
375381
382+ prevMsg = msg
376383 NumLeft --
377384 }
378385
0 commit comments