Sub ListAllChannelsAndThreadsAsString(guild1 As Object) As ResumableSub
Dim output As String = ""
Dim joJDA As JavaObject = jda
File.OpenOutput(File.DirApp,"allmsg.txt",False)
' 1. Πάρε το Guild αντικείμενο
Dim guildObj As Guild = guild1'joJDA.RunMethod("getGuildById", Array(guildId))
'If guildObj = Null Then Return $"Guild with ID ${guildId} not found."$
Log("X1")
' 2. Λίστα όλων των καναλιών του guild
Dim channelsList As List = guildObj.GuildChannels
Log("X2")
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!
Log("X4")
' 4. Archived public threads (εφόσον υποστηρίζεται)
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
Log("X5")
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
Log("X6")
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
Log("X3")
' 3. Active threads
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
Dim joThread As JavaObject = guildObj.getThreadChannelById(aId)
' Write header once
AppendLineToFile("allmsg.txt", $"-- 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 ' complete() returns List<Message>
Do While batch.IsInitialized And batch.Size > 0
For Each m As Object In batch
Dim joM As JavaObject = m
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}"$
AppendLineToFile("allmsg.txt", 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, oldestJo))
retrievedjo= retrievedJos.RunMethod("complete", Null)
batch = retrievedjo
Loop
Next
Next
Return output
End Sub