Sub GrabAll(guild1 As Object) As ResumableSub
'saving at string only the channels
Dim output As String = ""
' 1. Get Guild object !
Dim guildObj As Guild = guild1
' 2. list all channels of guild
Dim channelsList As List = guildObj.GuildChannels
For Each gc As Object In channelsList
Dim joGC As JavaObject = gc
Dim chanType As JavaObject= joGC.RunMethod("getType", Null)
Dim chantype2 As String = chanType.RunMethod("name", Null)
Dim chanName As String = joGC.RunMethod("getName", Null)
Dim chanId As String = joGC.RunMethod("getId", Null)
output = output & $"Channel: ${chanName} [${chanId}] Type: ${chantype2}"$ & CRLF
'trigger them all!
' 4. Archived public threads (if it is supported)
Try
Dim pubThreadss As JavaObject= joGC.RunMethod("retrieveArchivedPublicThreadChannels", Null)
Dim pubThreads As List=pubThreadss.RunMethod("complete", Null)
For Each t As Object In pubThreads
Dim joT As JavaObject = t
Dim tName As String = joT.RunMethod("getName", Null)
Dim tId As String = joT.RunMethod("getId", Null)
output = output & $" Archived Public Thread: ${tName} [${tId}]"$ & CRLF
Next
Catch
' skip if unsupported or no permission
End Try
' 5. Archived private threads
Try
Dim privThreadss As JavaObject = joGC.RunMethod("retrieveArchivedPrivateThreadChannels", Null)
Dim privThreads As List = privThreadss.RunMethod("complete", Null)
For Each t As Object In privThreads
Dim joT As JavaObject = t
Dim tName As String = joT.RunMethod("getName", Null)
Dim tId As String = joT.RunMethod("getId", Null)
output = output & $" Archived Private Thread: ${tName} [${tId}]"$ & CRLF
Next
Catch
End Try
' 6. Archived private-joined threads
Try
Dim joinedThreadss As JavaObject = joGC.RunMethod("retrieveArchivedPrivateJoinedThreadChannels", Null)
Dim joinedThreads As List = joinedThreadss.RunMethod("complete", Null)
For Each t As Object In joinedThreads
Dim joT As JavaObject = t
Dim tName As String = joT.RunMethod("getName", Null)
Dim tId As String = joT.RunMethod("getId", Null)
output = output & $" Archived Private-Joined Thread: ${tName} [${tId}]"$ & CRLF
Next
Catch
End Try
' 3. Active threads (don't change the order)
Dim activeThreads As List = guildObj.ThreadChannels 'guildObj.RunMethod("getThreadChannels", Null)
For Each at As Object In activeThreads
Dim joAT As JavaObject = at
Dim parentId As JavaObject= joAT.RunMethod("getParentChannel", Null)
Dim parentId2 As String = parentId.RunMethod("getId", Null)
Dim aName As String = joAT.RunMethod("getName", Null)
Dim aId As String = joAT.RunMethod("getId", Null)
output = output & $" Active Thread (in ${parentId2}): ${aName} [${aId}]"$ & CRLF
'Save that if you want: $"-- Messages in Thread [${aId}] --"$
' Get history object
Dim historyJo As JavaObject = joThread.RunMethod("getHistory", Null)
Dim batch As List
Dim retrievedJos As JavaObject
' First batch (newest 100)
retrievedJos = historyJo.RunMethod("retrievePast", Array(100))
Dim retrievedjo As JavaObject=retrievedJos.RunMethod("complete", Null)
batch = retrievedjo
Do While batch.IsInitialized And batch.Size > 0
For Each m As Object In batch
Dim joM As JavaObject = m
Dim msgId As String = joM.RunMethod("getId", Null) ' message id
Dim authorJo As JavaObject = joM.RunMethod("getAuthor", Null)
Dim author As String = authorJo.RunMethod("getName", Null)
Dim timeJo As JavaObject = joM.RunMethod("getTimeCreated", Null)
Dim timeStr As String = timeJo.RunMethod("toString", Null)
Dim content As String = joM.RunMethod("getContentDisplay", Null)
'Dim line As String = $" Message [${timeStr}] ${author}: ${content}"$
Dim dt As Long
Dim aa() As String=Regex.Split("T",timeStr.Replace("Z","")) 'split the date from time
dt=DateTime.DateTimeParse(aa(0),aa(1)) 'turn it to long (datetime) - useful for searching
'save the strings if you want.... perhaps line...
Next
If batch.Size < 100 Then Exit
' Page older using the last message object
Dim oldestJo As JavaObject = batch.Get(batch.Size - 1)
retrievedJos = historyJo.RunMethod("retrievePast", Array(100))
retrievedjo= retrievedJos.RunMethod("complete", Null)
batch = retrievedjo
Loop
Next
Next
Return output
End Sub