Skip to content

Commit

Permalink
fix blockedusers
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeine01 committed May 30, 2022
1 parent 552fb18 commit 42faaff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/main/kotlin/org/caffeine/chaos/api/client/ClientBlockedUser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.caffeine.chaos.api.client

@kotlinx.serialization.Serializable
data class ClientBlockedUser (
override val username: String,
override val discriminator: String,
override val avatar: String?,
override val id: String,
) : DiscordUser() {
override val discriminatedName = "$username#$avatar"
fun unblock() {
return
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ import org.caffeine.chaos.api.json

@kotlinx.serialization.Serializable
class ClientBlockedUsers(val client: Client) {
suspend fun getList(): List<DiscordUser> {
val blocked = mutableListOf<DiscordUser>()
suspend fun getList(): List<ClientBlockedUser> {
val blocked = mutableListOf<ClientBlockedUser>()
val response = discordHTTPClient.request("$BASE_URL/users/@me/relationships") {
method = HttpMethod.Get
headers {
append(HttpHeaders.Authorization, client.config.token)
}
}
val final = json.decodeFromString<List<ClientRelationship>>(response.bodyAsText())
for (blockedUser in final) {
if (blockedUser.type == 2) {
val user = blockedUser.user
for (i in final) {
if (i.type == 2) {
val user = ClientBlockedUser(
i.user.username,
i.user.discriminator,
i.user.avatar,
i.user.id
)
blocked.add(user)
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/main/kotlin/org/caffeine/chaos/commands/Backup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.serialization.encodeToString
import org.caffeine.chaos.Command
import org.caffeine.chaos.api.client.Client
import org.caffeine.chaos.api.client.ClientFriend
import org.caffeine.chaos.api.client.ClientGuild
import org.caffeine.chaos.api.client.DiscordUser
import org.caffeine.chaos.api.client.*
import org.caffeine.chaos.api.client.message.MessageBuilder
import org.caffeine.chaos.api.client.message.MessageCreateEvent
import org.caffeine.chaos.api.jsonp
Expand All @@ -22,7 +19,7 @@ class Backup : Command(arrayOf("backup")) {

@kotlinx.serialization.Serializable
data class BackupStructure(
val blockList: List<DiscordUser>,
val blockList: List<ClientBlockedUser>,
val friends: List<ClientFriend>,
val guilds: List<ClientGuild>,
)
Expand Down

0 comments on commit 42faaff

Please sign in to comment.